1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cerbero\Workflow\Inflectors; |
4
|
|
|
|
5
|
|
|
use Cerbero\Workflow\Wrappers\NamespaceDetectorInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Word inflector. |
9
|
|
|
* |
10
|
|
|
* @author Andrea Marco Sartori |
11
|
|
|
*/ |
12
|
|
|
class Inflector implements InflectorInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @author Andrea Marco Sartori |
16
|
|
|
* |
17
|
|
|
* @var string $word Word to inflect. |
18
|
|
|
*/ |
19
|
|
|
protected $word; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Andrea Marco Sartori |
23
|
|
|
* |
24
|
|
|
* @var string $namespace The application namespace. |
25
|
|
|
*/ |
26
|
|
|
protected $namespace; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Set the application namespace. |
30
|
|
|
* |
31
|
|
|
* @author Andrea Marco Sartori |
32
|
|
|
* |
33
|
|
|
* @param Cerbero\Workflow\Wrappers\NamespaceDetectorInterface $detector Application namespace detector. |
34
|
|
|
* |
35
|
|
|
* @return void |
|
|
|
|
36
|
|
|
*/ |
37
|
12 |
|
public function __construct(NamespaceDetectorInterface $detector) |
38
|
|
|
{ |
39
|
12 |
|
$this->namespace = $detector->detect(); |
40
|
12 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Set the word to inflect. |
44
|
|
|
* |
45
|
|
|
* @author Andrea Marco Sartori |
46
|
|
|
* |
47
|
|
|
* @param string $word |
48
|
|
|
* |
49
|
|
|
* @return $this |
50
|
|
|
*/ |
51
|
9 |
|
public function of($word) |
52
|
|
|
{ |
53
|
9 |
|
$this->word = $word; |
54
|
|
|
|
55
|
9 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Retrieve the inflected request. |
60
|
|
|
* |
61
|
|
|
* @author Andrea Marco Sartori |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
3 |
|
public function getRequest() |
66
|
|
|
{ |
67
|
3 |
|
return $this->compose('Request', 'Http\Requests'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Compose the word to inflect. |
72
|
|
|
* |
73
|
|
|
* @author Andrea Marco Sartori |
74
|
|
|
* |
75
|
|
|
* @param string $suffix |
76
|
|
|
* @param string $path |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
6 |
|
protected function compose($suffix, $path) |
81
|
|
|
{ |
82
|
6 |
|
$name = ucfirst($this->word).$suffix; |
83
|
|
|
|
84
|
6 |
|
return $this->namespace."\\{$path}\\{$name}"; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Retrieve the inflected job. |
89
|
|
|
* |
90
|
|
|
* @author Andrea Marco Sartori |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
3 |
|
public function getJob() |
95
|
|
|
{ |
96
|
3 |
|
return $this->compose('Job', 'Jobs'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.