|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DoctrineModule\Mvc\Router\Console; |
|
6
|
|
|
|
|
7
|
|
|
use BadMethodCallException; |
|
8
|
|
|
use Laminas\Console\Request as ConsoleRequest; |
|
9
|
|
|
use Laminas\Mvc\Console\Router\RouteInterface; |
|
10
|
|
|
use Laminas\Router\RouteMatch; |
|
11
|
|
|
use Laminas\Stdlib\RequestInterface as Request; |
|
12
|
|
|
use Symfony\Component\Console\Application; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Route matching commands in Symfony CLI |
|
16
|
|
|
*/ |
|
17
|
|
|
class SymfonyCli implements RouteInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var Application */ |
|
20
|
|
|
protected $cliApplication; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Default values. |
|
24
|
|
|
* |
|
25
|
|
|
* @var mixed[] |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $defaults; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor |
|
31
|
|
|
* |
|
32
|
|
|
* @param mixed[] $defaults |
|
33
|
|
|
*/ |
|
34
|
3 |
|
public function __construct(Application $cliApplication, array $defaults = []) |
|
35
|
|
|
{ |
|
36
|
3 |
|
$this->cliApplication = $cliApplication; |
|
37
|
3 |
|
$this->defaults = $defaults; |
|
38
|
3 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritDoc} |
|
42
|
|
|
*/ |
|
43
|
3 |
|
public function match(Request $request) |
|
44
|
|
|
{ |
|
45
|
3 |
|
if (! $request instanceof ConsoleRequest) { |
|
46
|
|
|
return null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
$params = $request->getParams()->toArray(); |
|
50
|
|
|
|
|
51
|
3 |
|
if (! isset($params[0]) || ! $this->cliApplication->has($params[0])) { |
|
52
|
1 |
|
return null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
return new RouteMatch($this->defaults); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Disabled. |
|
60
|
|
|
* |
|
61
|
|
|
* {@inheritDoc} |
|
62
|
|
|
* |
|
63
|
|
|
* @throws BadMethodCallException this method is disabled. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function assemble(array $params = [], array $options = []) |
|
66
|
|
|
{ |
|
67
|
|
|
throw new BadMethodCallException('Unsupported'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritDoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getAssembledParams() |
|
74
|
|
|
{ |
|
75
|
|
|
return []; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Disabled. |
|
80
|
|
|
* |
|
81
|
|
|
* {@inheritDoc} |
|
82
|
|
|
* |
|
83
|
|
|
* @throws BadMethodCallException this method is disabled. |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function factory($options = []) |
|
86
|
|
|
{ |
|
87
|
|
|
throw new BadMethodCallException('Unsupported'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|