1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Routing\Matcher\Dumper; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Routing\MethodCollection; |
6
|
|
|
|
7
|
|
|
class PhpMatcherDumper extends MatcherDumper |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
public function dump(array $options = []) |
11
|
|
|
{ |
12
|
|
|
$options = array_replace( |
13
|
|
|
[ |
14
|
|
|
'class' => 'ProjectMethodMatcher', |
15
|
|
|
'base_class' => 'Cmobi\\RabbitmqBundle\\Routing\\Matcher\\MethodMatcher', |
16
|
|
|
], |
17
|
|
|
$options |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
return <<<EOF |
21
|
|
|
<?php |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Routing\Exception\MethodNotAllowedException; |
24
|
|
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
25
|
|
|
use Cmobi\RabbitmqBundle\Routing\Method; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {$options['class']}. |
29
|
|
|
* |
30
|
|
|
* This class has been auto-generated |
31
|
|
|
* by the Symfony Routing Component. |
32
|
|
|
*/ |
33
|
|
|
class {$options['class']} extends {$options['base_class']} |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Constructor. |
37
|
|
|
*/ |
38
|
|
|
public function __construct(Method \$context) |
39
|
|
|
{ |
40
|
|
|
\$this->context = \$context; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
{$this->generateMatchMethod()} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
EOF; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function generateMatchMethod() |
50
|
|
|
{ |
51
|
|
|
$code = rtrim($this->compileRoutes($this->getMethods()), "\n"); |
|
|
|
|
52
|
|
|
|
53
|
|
|
return <<<EOF |
54
|
|
|
public function match(\$name) |
55
|
|
|
{ |
56
|
|
|
\$allow = []; |
57
|
|
|
\$context = \$this->context; |
58
|
|
|
|
59
|
|
|
$code |
60
|
|
|
throw 0 < count(\$allow) ? new MethodNotAllowedException(array_unique(\$allow)) : new ResourceNotFoundException(); |
61
|
|
|
} |
62
|
|
|
EOF; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function compileMethods(MethodCollection $methods) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$code = ''; |
68
|
|
|
|
69
|
|
|
foreach ($methods as $collection) { |
70
|
|
|
if (null !== $name = $collection->getAttribute('name')) { |
71
|
|
|
$code .= sprintf(" if (\$method === \$name) {\n", var_export($name, true)); |
72
|
|
|
$code .= rtrim($this->compileMethod($name)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
$code .= " }\n\n"; |
76
|
|
|
|
77
|
|
|
return $code; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function compileMethod($name) |
81
|
|
|
{ |
82
|
|
|
return sprintf(" return array('_method' => '%s');\n", $name); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.