1: <?php
2:
3: namespace PHPixie\Processors\Processor;
4:
5: abstract class Actions implements Selective
6: {
7: public function process($value)
8: {
9: $method = $this->getMethodNameFor($value);
10:
11: if($method === null) {
12: throw new \PHPixie\Processors\Exception("No action method found for value");
13: }
14:
15: return $this->$method($value);
16: }
17:
18: public function isProcessable($value)
19: {
20: $method = $this->getMethodNameFor($value);
21: return $method !== null;
22: }
23:
24: protected function getMethodNameFor($value)
25: {
26: $actionName = $this->getActionNameFor($value);
27: if($actionName === null) {
28: return null;
29: }
30:
31: $methodName = $this->actionMethodName($actionName);
32:
33: if(!method_exists($this, $methodName)) {
34: return null;
35: }
36:
37: return $methodName;
38: }
39:
40: protected function actionMethodName($actionName)
41: {
42: return $actionName.'Action';
43: }
44:
45: abstract protected function getActionNameFor($value);
46: }