1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace DoctrineModule\Mvc\Router\Console; |
20
|
|
|
|
21
|
|
|
use Symfony\Component\Console\Application; |
22
|
|
|
use Zend\Mvc\Console\Router\RouteInterface; |
23
|
|
|
use Zend\Stdlib\RequestInterface as Request; |
24
|
|
|
use Zend\Router\RouteMatch; |
25
|
|
|
use Zend\Console\Request as ConsoleRequest; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Route matching commands in Symfony CLI |
29
|
|
|
* |
30
|
|
|
* @license MIT |
31
|
|
|
* @author Aleksandr Sandrovskiy <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class SymfonyCli implements RouteInterface |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var \Symfony\Component\Console\Application |
37
|
|
|
*/ |
38
|
|
|
protected $cliApplication; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Default values. |
42
|
|
|
* |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $defaults; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Constructor |
49
|
|
|
* |
50
|
|
|
* @param \Symfony\Component\Console\Application $cliApplication |
51
|
|
|
* @param array $defaults |
52
|
|
|
*/ |
53
|
3 |
|
public function __construct(Application $cliApplication, array $defaults = []) |
54
|
|
|
{ |
55
|
3 |
|
$this->cliApplication = $cliApplication; |
56
|
3 |
|
$this->defaults = $defaults; |
57
|
3 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
3 |
|
public function match(Request $request) |
63
|
|
|
{ |
64
|
3 |
|
if (! $request instanceof ConsoleRequest) { |
65
|
|
|
return null; |
66
|
|
|
} |
67
|
|
|
|
68
|
3 |
|
$params = $request->getParams()->toArray(); |
69
|
|
|
|
70
|
3 |
|
if (! isset($params[0]) || ! $this->cliApplication->has($params[0])) { |
71
|
1 |
|
return null; |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
return new RouteMatch($this->defaults); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Disabled. |
79
|
|
|
* |
80
|
|
|
* {@inheritDoc} |
81
|
|
|
* |
82
|
|
|
* @throws \BadMethodCallException this method is disabled |
83
|
|
|
*/ |
84
|
|
|
public function assemble(array $params = [], array $options = []) |
85
|
|
|
{ |
86
|
|
|
throw new \BadMethodCallException('Unsupported'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritDoc} |
91
|
|
|
*/ |
92
|
|
|
public function getAssembledParams() |
93
|
|
|
{ |
94
|
|
|
return []; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Disabled. |
99
|
|
|
* |
100
|
|
|
* {@inheritDoc} |
101
|
|
|
* |
102
|
|
|
* @throws \BadMethodCallException this method is disabled |
103
|
|
|
*/ |
104
|
|
|
public static function factory($options = []) |
105
|
|
|
{ |
106
|
|
|
throw new \BadMethodCallException('Unsupported'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|