1 | <?php |
||
37 | class Transform |
||
38 | { |
||
39 | /** |
||
40 | * Contains the factory |
||
41 | * |
||
42 | * @var Transform |
||
43 | */ |
||
44 | protected static $transform; |
||
45 | |||
46 | /** |
||
47 | * List of rules to execute on an input |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $currentRules = array(); |
||
52 | |||
53 | /** |
||
54 | * Doesn't allow the class to be instanciated |
||
55 | */ |
||
56 | 1 | protected function __construct() |
|
59 | |||
60 | /** |
||
61 | * Returns the factory to avoid having multiple instances of the same class |
||
62 | * |
||
63 | * @return Transform |
||
64 | */ |
||
65 | 115 | protected static function getFactory() |
|
73 | |||
74 | /** |
||
75 | * Return an Array of rules for an instance |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | 102 | protected function getRules() |
|
83 | |||
84 | /** |
||
85 | * Called on the first time to remove all old rules |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | 115 | protected function cleanRules() |
|
93 | |||
94 | /** |
||
95 | * Add a rule to the rules registry |
||
96 | * |
||
97 | * @param string $ruleName |
||
98 | * @param array $arguments |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | 115 | protected function addRule($ruleName, array $arguments) |
|
118 | |||
119 | /** |
||
120 | * For the first execution, the method is called statically such as T::Replace('a', 'b') |
||
121 | * Then get the factory, clean the previous rules and do a __call() |
||
122 | * |
||
123 | * @param string $ruleName |
||
124 | * @param array $arguments |
||
125 | * |
||
126 | * @return Transform |
||
127 | */ |
||
128 | 115 | public static function __callStatic($ruleName, array $arguments) |
|
135 | |||
136 | /** |
||
137 | * Just add a rule in the registry when called |
||
138 | * |
||
139 | * @param string $ruleName Name of the rule |
||
140 | * @param array $arguments Arguments for the rule |
||
141 | * |
||
142 | * @return Transform |
||
143 | */ |
||
144 | 115 | public function __call($ruleName, array $arguments) |
|
150 | |||
151 | /** |
||
152 | * Transform an input by applying rule |
||
153 | * |
||
154 | * @param string $input Should be a string ! |
||
155 | * |
||
156 | * @return string Transformed string |
||
157 | */ |
||
158 | 112 | public function transform($input) |
|
178 | } |
||
179 |