1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jaxon\Di\Traits; |
4
|
|
|
|
5
|
|
|
use Jaxon\App\Config\ConfigManager; |
6
|
|
|
use Jaxon\App\I18n\Translator; |
7
|
|
|
use Jaxon\Di\ClassContainer; |
8
|
|
|
use Jaxon\Di\Container; |
9
|
|
|
use Jaxon\Script\Factory\CallFactory; |
10
|
|
|
use Jaxon\Script\Factory\ParameterFactory; |
11
|
|
|
use Jaxon\Plugin\Manager\PluginManager; |
12
|
|
|
use Jaxon\Plugin\Response\DataBag\DataBagPlugin; |
13
|
|
|
use Jaxon\Plugin\Response\Dialog\DialogCommand; |
14
|
|
|
use Jaxon\Request\Handler\CallbackManager; |
15
|
|
|
use Jaxon\Request\Handler\ParameterReader; |
16
|
|
|
use Jaxon\Request\Handler\RequestHandler; |
17
|
|
|
use Jaxon\Request\Upload\UploadHandlerInterface; |
18
|
|
|
use Jaxon\Response\ResponseManager; |
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() |
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(ClassContainer::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 js call factory |
61
|
|
|
* |
62
|
|
|
* @return CallFactory |
63
|
|
|
*/ |
64
|
|
|
public function getCallFactory(): CallFactory |
65
|
|
|
{ |
66
|
|
|
return $this->g(CallFactory::class); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the js call parameter factory |
71
|
|
|
* |
72
|
|
|
* @return ParameterFactory |
73
|
|
|
*/ |
74
|
|
|
public function getParameterFactory(): ParameterFactory |
75
|
|
|
{ |
76
|
|
|
return $this->g(ParameterFactory::class); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the request handler |
81
|
|
|
* |
82
|
|
|
* @return RequestHandler |
83
|
|
|
*/ |
84
|
|
|
public function getRequestHandler(): RequestHandler |
85
|
|
|
{ |
86
|
|
|
return $this->g(RequestHandler::class); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the upload handler |
91
|
|
|
* |
92
|
|
|
* @return UploadHandlerInterface|null |
93
|
|
|
*/ |
94
|
|
|
public function getUploadHandler(): ?UploadHandlerInterface |
95
|
|
|
{ |
96
|
|
|
return $this->g(UploadHandlerInterface::class); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the callback manager |
101
|
|
|
* |
102
|
|
|
* @return CallbackManager |
103
|
|
|
*/ |
104
|
|
|
public function getCallbackManager(): CallbackManager |
105
|
|
|
{ |
106
|
|
|
return $this->g(CallbackManager::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
|
|
|
|