|
1
|
|
|
<?php |
|
2
|
|
|
namespace rtens\domin\delivery\web\root; |
|
3
|
|
|
|
|
4
|
|
|
use rtens\domin\delivery\web\HeadElements; |
|
5
|
|
|
use rtens\domin\delivery\web\WebApplication; |
|
6
|
|
|
use watoki\curir\Container; |
|
7
|
|
|
use watoki\curir\cookie\Cookie; |
|
8
|
|
|
use watoki\curir\cookie\CookieStore; |
|
9
|
|
|
use watoki\curir\delivery\WebRequest; |
|
10
|
|
|
use watoki\curir\protocol\Url; |
|
11
|
|
|
use watoki\curir\rendering\PhpRenderer; |
|
12
|
|
|
use watoki\deli\Path; |
|
13
|
|
|
use watoki\deli\Request; |
|
14
|
|
|
use watoki\factory\Factory; |
|
15
|
|
|
|
|
16
|
|
|
class IndexResource extends Container { |
|
17
|
|
|
|
|
18
|
|
|
/** @var CookieStore */ |
|
19
|
|
|
private $cookies; |
|
20
|
|
|
|
|
21
|
|
|
/** @var WebApplication */ |
|
22
|
|
|
private $app; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param Factory $factory <- |
|
26
|
|
|
* @param WebApplication $app <- |
|
27
|
|
|
* @param CookieStore $cookies <- |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(Factory $factory, WebApplication $app, CookieStore $cookies) { |
|
30
|
|
|
parent::__construct($factory); |
|
31
|
|
|
$this->cookies = $cookies; |
|
32
|
|
|
$this->app = $app; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param Request|WebRequest $request |
|
37
|
|
|
* @return \watoki\curir\delivery\WebResponse |
|
38
|
|
|
*/ |
|
39
|
|
|
public function respond(Request $request) { |
|
40
|
|
|
$this->app->prepare($request); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
if (!$this->isContainerTarget($request)) { |
|
43
|
|
|
$request = $request |
|
44
|
|
|
->withTarget(Path::fromString('execute')) |
|
45
|
|
|
->withArgument(ExecuteResource::ACTION_ARG, $request->getTarget()->toString()); |
|
46
|
|
|
} |
|
47
|
|
|
return parent::respond($request); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param WebRequest $request <- |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function doGet(WebRequest $request) { |
|
55
|
|
|
$this->resetBreadCrumbs(); |
|
56
|
|
|
return [ |
|
57
|
|
|
'name' => $this->app->name, |
|
58
|
|
|
'menu' => $this->app->menu->render($request), |
|
59
|
|
|
'action' => $this->assembleActions($request->getContext()), |
|
60
|
|
|
'headElements' => [ |
|
61
|
|
|
(string)HeadElements::jquery(), |
|
62
|
|
|
(string)HeadElements::bootstrap(), |
|
63
|
|
|
(string)HeadElements::bootstrapJs(), |
|
64
|
|
|
] |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param Url $base |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
private function assembleActions(Url $base) { |
|
73
|
|
|
$actions = []; |
|
74
|
|
|
foreach ($this->app->actions->getAllActions() as $id => $action) { |
|
75
|
|
|
$actions[] = [ |
|
76
|
|
|
'caption' => $action->caption(), |
|
77
|
|
|
'description' => $this->app->parser->shorten($action->description()), |
|
78
|
|
|
'link' => ['href' => $base->appended($id)->toString()] |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
return $actions; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
private function resetBreadCrumbs() { |
|
85
|
|
|
$this->cookies->create(new Cookie([]), ExecuteResource::BREADCRUMB_COOKIE); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function createDefaultRenderer() { |
|
89
|
|
|
return new PhpRenderer(); |
|
90
|
|
|
} |
|
91
|
|
|
} |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.