-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringer.php
More file actions
107 lines (88 loc) · 2.63 KB
/
Stringer.php
File metadata and controls
107 lines (88 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Core;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\Pattern;
use Doctrine\Inflector\Rules\Patterns;
use Doctrine\Inflector\Rules\Ruleset;
use Doctrine\Inflector\Rules\Substitution;
use Doctrine\Inflector\Rules\Substitutions;
use Doctrine\Inflector\Rules\Transformation;
use Doctrine\Inflector\Rules\Transformations;
use Doctrine\Inflector\Rules\Word;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\Inflector\NoopWordInflector;
class Stringer{
protected $inflector;
public function __construct()
{
$inflector = InflectorFactory::create()
->withSingularRules(
new Ruleset(
new Transformations(
new Transformation(new Pattern('/^(bil)er$/i'), '\1'),
new Transformation(new Pattern('/^(inflec|contribu)tors$/i'), '\1ta')
),
new Patterns(new Pattern('singulars')),
new Substitutions(new Substitution(new Word('spins'), new Word('spinor')))
)
)
->withPluralRules(
new Ruleset(
new Transformations(
new Transformation(new Pattern('^(bil)er$'), '\1'),
new Transformation(new Pattern('^(inflec|contribu)tors$'), '\1ta')
),
new Patterns(new Pattern('noflect'), new Pattern('abtuse')),
new Substitutions(
new Substitution(new Word('amaze'), new Word('amazable')),
new Substitution(new Word('phone'), new Word('phonezes'))
)
)
)
->build();
$this->inflector=$inflector;
}
protected function pluralize($str)
{
return $this->inflector->pluralize($str);
}
protected function singularize($str)
{
return $this->inflector->singularize($str);
}
protected function slug($str)
{
return $this->inflector->urlize($str);
}
protected function removeAccent($str)
{
return $this->inflector->unaccent($str);
}
protected function toTableName($str)
{
return $this->inflector->tableize($str);
}
protected function toModelName($str)
{
return $this->inflector->classify($str);
}
protected function camale($str)
{
return $this->inflector->camelize($str);
}
protected function reverse($str)
{
return text_rev($str);
}
public static function __callStatic(string $method,array $params)
{
if(method_exists(new static,$method))
{
return (new static)->$method(...$params);
}
else
{
throw new Exception('The ' . $method . ' method is not supported.');
}
}
}