|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Inflector; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Inflector\Traits\HasCacheTrait; |
|
6
|
|
|
use Nip\Inflector\Traits\HasDictionaryTrait; |
|
7
|
|
|
use Nip\Inflector\Traits\InflectionCamelizeTrait; |
|
8
|
|
|
use Nip\Inflector\Traits\InflectionClassifyTrait; |
|
9
|
|
|
use Nip\Inflector\Traits\InflectionHyphenizeTrait; |
|
10
|
|
|
use Nip\Inflector\Traits\InflectionOrdinalizeTrait; |
|
11
|
|
|
use Nip\Inflector\Traits\InflectionPluralizeTrait; |
|
12
|
|
|
use Nip\Inflector\Traits\InflectionSingularizeTrait; |
|
13
|
|
|
use Nip\Inflector\Traits\InflectionTableizeTrait; |
|
14
|
|
|
use Nip\Inflector\Traits\InflectionUnclasifyTrait; |
|
15
|
|
|
use Nip\Inflector\Traits\InflectionUnderscoreTrait; |
|
16
|
|
|
use Nip\Inflector\Traits\MagicMethodsTrait; |
|
17
|
|
|
use Nip\Inflector\Traits\SingletonTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Inflector |
|
21
|
|
|
* @package Nip\Inflector |
|
22
|
|
|
* @based on https://github.com/cakephp/cakephp/blob/master/src/Utility/Inflector.php |
|
23
|
|
|
*/ |
|
24
|
|
|
class Inflector |
|
25
|
|
|
{ |
|
26
|
|
|
use SingletonTrait; |
|
27
|
|
|
use HasCacheTrait; |
|
28
|
|
|
use HasDictionaryTrait; |
|
29
|
|
|
use MagicMethodsTrait; |
|
30
|
|
|
use InflectionCamelizeTrait; |
|
31
|
|
|
use InflectionClassifyTrait; |
|
32
|
|
|
use InflectionHyphenizeTrait; |
|
33
|
|
|
use InflectionOrdinalizeTrait; |
|
34
|
|
|
use InflectionPluralizeTrait; |
|
35
|
|
|
use InflectionSingularizeTrait; |
|
36
|
|
|
use InflectionTableizeTrait; |
|
37
|
|
|
use InflectionUnclasifyTrait; |
|
38
|
|
|
use InflectionUnderscoreTrait; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param $name |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
19 |
|
public function hasInflection($name) |
|
45
|
|
|
{ |
|
46
|
19 |
|
$method = $this->inflectionMethod($name); |
|
47
|
19 |
|
return method_exists($this, $method); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param $name |
|
52
|
|
|
* @param $word |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
*/ |
|
55
|
19 |
|
public function doInflection($name, $word) |
|
56
|
|
|
{ |
|
57
|
19 |
|
if (!self::hasString($name, $word)) { |
|
58
|
13 |
|
$method = $this->inflectionMethod($name); |
|
59
|
13 |
|
self::setString($name, $word, $this->$method($word)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
19 |
|
return self::getString($name, $word); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param $name |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
19 |
|
protected function inflectionMethod($name) |
|
70
|
|
|
{ |
|
71
|
19 |
|
return "do" . ucfirst($name); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|