1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N1215\CakeCandle\Http; |
4
|
|
|
|
5
|
|
|
use Cake\Controller\Controller; |
6
|
|
|
use Cake\Controller\Exception\MissingActionException; |
7
|
|
|
use Cake\Http\ServerRequest; |
8
|
|
|
use LogicException; |
9
|
|
|
use N1215\CakeCandle\ContainerBagLocator; |
10
|
|
|
|
11
|
|
|
trait AssistedAction |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param string |
15
|
|
|
* @return bool |
16
|
|
|
* @throws \ReflectionException |
17
|
|
|
*/ |
18
|
|
|
abstract public function isAction($action); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Dispatches the controller action. Checks that the action |
22
|
|
|
* exists and isn't private. |
23
|
|
|
* |
24
|
|
|
* @return mixed The resulting response. |
25
|
|
|
* @throws \ReflectionException |
26
|
|
|
* @see Controller::invokeAction() |
27
|
|
|
*/ |
28
|
3 |
|
public function invokeAction() |
29
|
|
|
{ |
30
|
|
|
/** @var ServerRequest|null $request */ |
31
|
3 |
|
$request = $this->request; |
32
|
3 |
|
if (!$request) { |
33
|
1 |
|
throw new LogicException('No Request object configured. Cannot invoke action'); |
34
|
|
|
} |
35
|
2 |
|
if (!$this->isAction($request->getParam('action'))) { |
36
|
1 |
|
throw new MissingActionException([ |
37
|
1 |
|
'controller' => $this->name . 'Controller', |
38
|
1 |
|
'action' => $request->getParam('action'), |
39
|
1 |
|
'prefix' => $request->getParam('prefix') ?: '', |
40
|
1 |
|
'plugin' => $request->getParam('plugin'), |
41
|
1 |
|
]); |
42
|
|
|
} |
43
|
|
|
/* @var callable $callable */ |
44
|
1 |
|
$callable = [$this, $request->getParam('action')]; |
45
|
|
|
|
46
|
1 |
|
return ContainerBagLocator::get()->call( |
47
|
1 |
|
$callable, |
48
|
1 |
|
$request->getParam('pass') |
49
|
1 |
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|