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\Container; |
8
|
|
|
use Jaxon\Plugin\Manager\PluginManager; |
9
|
|
|
use Jaxon\Plugin\Response\Dialog\DialogCommand; |
10
|
|
|
use Jaxon\Response\Response; |
11
|
|
|
use Jaxon\Response\ComponentResponse; |
12
|
|
|
use Jaxon\Response\ResponseManager; |
13
|
|
|
use Jaxon\Script\JxnCall; |
14
|
|
|
|
15
|
|
|
use function trim; |
16
|
|
|
|
17
|
|
|
trait ResponseTrait |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Register the values into the container |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
private function registerResponses() |
25
|
|
|
{ |
26
|
|
|
// Global Response |
27
|
|
|
$this->set(Response::class, function($di) { |
|
|
|
|
28
|
|
|
return new Response($di->g(ResponseManager::class), $di->g(PluginManager::class)); |
29
|
|
|
}); |
30
|
|
|
// Response Manager |
31
|
|
|
$this->set(ResponseManager::class, function($di) { |
32
|
|
|
$sEncoding = trim($di->g(ConfigManager::class)->getOption('core.encoding', '')); |
33
|
|
|
return new ResponseManager($di->g(Container::class), $di->g(Translator::class), |
34
|
|
|
$this->g(DialogCommand::class), $sEncoding); |
|
|
|
|
35
|
|
|
}); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get the response manager |
40
|
|
|
* |
41
|
|
|
* @return ResponseManager |
42
|
|
|
*/ |
43
|
|
|
public function getResponseManager(): ResponseManager |
44
|
|
|
{ |
45
|
|
|
return $this->g(ResponseManager::class); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the global Response object |
50
|
|
|
* |
51
|
|
|
* @return Response |
52
|
|
|
*/ |
53
|
|
|
public function getResponse(): Response |
54
|
|
|
{ |
55
|
|
|
return $this->g(Response::class); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create a new Jaxon response |
60
|
|
|
* |
61
|
|
|
* @return Response |
62
|
|
|
*/ |
63
|
|
|
public function newResponse(): Response |
64
|
|
|
{ |
65
|
|
|
return new Response($this->g(ResponseManager::class), $this->g(PluginManager::class)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Create a new reponse for a Jaxon component |
70
|
|
|
* |
71
|
|
|
* @param JxnCall $xJxnCall |
72
|
|
|
* |
73
|
|
|
* @return ComponentResponse |
74
|
|
|
*/ |
75
|
|
|
public function newComponentResponse(JxnCall $xJxnCall): ComponentResponse |
76
|
|
|
{ |
77
|
|
|
return new ComponentResponse($this->g(ResponseManager::class), |
78
|
|
|
$this->g(PluginManager::class), $xJxnCall); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|