1
|
|
|
<?php |
2
|
|
|
namespace rtens\domin\delivery\web\adapters\curir\root; |
3
|
|
|
|
4
|
|
|
use rtens\domin\delivery\web\adapters\curir\CurirBreadCrumbsTrail; |
5
|
|
|
use rtens\domin\delivery\web\adapters\curir\CurirParameterReader; |
6
|
|
|
use rtens\domin\delivery\web\resources\ExecutionResource; |
7
|
|
|
use rtens\domin\delivery\web\WebApplication; |
8
|
|
|
use watoki\curir\cookie\CookieStore; |
9
|
|
|
use watoki\curir\delivery\WebRequest; |
10
|
|
|
use watoki\curir\Resource; |
11
|
|
|
use watoki\factory\Factory; |
12
|
|
|
|
13
|
|
|
class ExecuteResource extends Resource { |
14
|
|
|
|
15
|
|
|
const ACTION_ARG = '__action'; |
16
|
|
|
|
17
|
|
|
/** @var WebApplication */ |
18
|
|
|
private $app; |
19
|
|
|
|
20
|
|
|
/** @var CookieStore */ |
21
|
|
|
private $cookies; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Factory $factory <- |
25
|
|
|
* @param WebApplication $app <- |
26
|
|
|
* @param CookieStore $cookies <- |
27
|
|
|
*/ |
28
|
|
|
public function __construct(Factory $factory, WebApplication $app, CookieStore $cookies) { |
29
|
|
|
parent::__construct($factory); |
30
|
|
|
$this->app = $app; |
31
|
|
|
$this->cookies = $cookies; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param WebRequest $request <- |
36
|
|
|
* @param string $__action |
37
|
|
|
* @param null|string $__token |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function doGet(WebRequest $request, $__action, $__token = null) { |
41
|
|
|
$execution = $this->getExecutionResource($this->app, $this->cookies, $request); |
42
|
|
|
return $execution->handleGet($__action, $__token); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param WebRequest $request <- |
47
|
|
|
* @param string $__action |
48
|
|
|
* @param null|string $__token |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function doPost(WebRequest $request, $__action, $__token = null) { |
52
|
|
|
$execution = $this->getExecutionResource($this->app, $this->cookies, $request); |
53
|
|
|
return $execution->handlePost($__action, $__token); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function getExecutionResource(WebApplication $app, CookieStore $cookies, WebRequest $request) { |
57
|
|
|
$reader = new CurirParameterReader($request); |
58
|
|
|
return new ExecutionResource($app, $reader, new CurirBreadCrumbsTrail($reader, $cookies)); |
59
|
|
|
} |
60
|
|
|
} |