|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jaxon\Di\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\App\Config\ConfigManager; |
|
6
|
|
|
use Jaxon\App\Dialog\Manager\DialogCommand; |
|
7
|
|
|
use Jaxon\App\I18n\Translator; |
|
8
|
|
|
use Jaxon\Di\ComponentContainer; |
|
9
|
|
|
use Jaxon\Di\Container; |
|
10
|
|
|
use Jaxon\Plugin\Manager\PluginManager; |
|
11
|
|
|
use Jaxon\Plugin\Response\Databag\DatabagPlugin; |
|
12
|
|
|
use Jaxon\Request\Handler\CallbackManager; |
|
13
|
|
|
use Jaxon\Request\Handler\ParameterReader; |
|
14
|
|
|
use Jaxon\Request\Handler\RequestHandler; |
|
15
|
|
|
use Jaxon\Request\Upload\UploadHandlerInterface; |
|
16
|
|
|
use Jaxon\Response\Manager\ResponseManager; |
|
17
|
|
|
use Jaxon\Script\CallFactory; |
|
18
|
|
|
use Jaxon\Script\ParameterFactory; |
|
19
|
|
|
use Jaxon\Utils\Http\UriDetector; |
|
20
|
|
|
|
|
21
|
|
|
trait RequestTrait |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Register the values into the container |
|
25
|
|
|
* |
|
26
|
|
|
* @return void |
|
27
|
|
|
*/ |
|
28
|
|
|
private function registerRequests(): void |
|
29
|
|
|
{ |
|
30
|
|
|
// The parameter reader |
|
31
|
|
|
$this->set(ParameterReader::class, function($di) { |
|
|
|
|
|
|
32
|
|
|
return new ParameterReader($di->g(Container::class), $di->g(Translator::class), |
|
33
|
|
|
$di->g(ConfigManager::class), $di->g(UriDetector::class)); |
|
34
|
|
|
}); |
|
35
|
|
|
// Callback Manager |
|
36
|
|
|
$this->set(CallbackManager::class, function($di) { |
|
37
|
|
|
return new CallbackManager($di->g(ResponseManager::class)); |
|
|
|
|
|
|
38
|
|
|
}); |
|
39
|
|
|
// By default, register a null upload handler |
|
40
|
|
|
$this->set(UploadHandlerInterface::class, function() { |
|
41
|
|
|
return null; |
|
42
|
|
|
}); |
|
43
|
|
|
// Request Handler |
|
44
|
|
|
$this->set(RequestHandler::class, function($di) { |
|
45
|
|
|
return new RequestHandler($di->g(Container::class), $di->g(PluginManager::class), |
|
46
|
|
|
$di->g(ResponseManager::class), $di->g(CallbackManager::class), |
|
47
|
|
|
$di->g(DatabagPlugin::class)); |
|
48
|
|
|
}); |
|
49
|
|
|
// Requests and calls Factory |
|
50
|
|
|
$this->set(CallFactory::class, function($di) { |
|
51
|
|
|
return new CallFactory($di->g(ComponentContainer::class), $di->g(DialogCommand::class)); |
|
52
|
|
|
}); |
|
53
|
|
|
// Factory for function parameters |
|
54
|
|
|
$this->set(ParameterFactory::class, function() { |
|
55
|
|
|
return new ParameterFactory(); |
|
56
|
|
|
}); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the callback manager |
|
61
|
|
|
* |
|
62
|
|
|
* @return CallbackManager |
|
63
|
|
|
*/ |
|
64
|
|
|
public function callback(): CallbackManager |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->g(CallbackManager::class); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the js call factory |
|
71
|
|
|
* |
|
72
|
|
|
* @return CallFactory |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getCallFactory(): CallFactory |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->g(CallFactory::class); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get the js call parameter factory |
|
81
|
|
|
* |
|
82
|
|
|
* @return ParameterFactory |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getParameterFactory(): ParameterFactory |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->g(ParameterFactory::class); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get the request handler |
|
91
|
|
|
* |
|
92
|
|
|
* @return RequestHandler |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getRequestHandler(): RequestHandler |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->g(RequestHandler::class); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Get the upload handler |
|
101
|
|
|
* |
|
102
|
|
|
* @return UploadHandlerInterface|null |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getUploadHandler(): ?UploadHandlerInterface |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->g(UploadHandlerInterface::class); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Get the parameter reader |
|
111
|
|
|
* |
|
112
|
|
|
* @return ParameterReader |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getParameterReader(): ParameterReader |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->g(ParameterReader::class); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|