|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jaxon\Di\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\App\Ajax\App; |
|
6
|
|
|
use Jaxon\App\Ajax\AppInterface; |
|
7
|
|
|
use Jaxon\App\Ajax\Bootstrap; |
|
8
|
|
|
use Jaxon\App\Config\ConfigEventManager; |
|
9
|
|
|
use Jaxon\App\Config\ConfigManager; |
|
10
|
|
|
use Jaxon\App\I18n\Translator; |
|
11
|
|
|
use Jaxon\App\View\ViewRenderer; |
|
12
|
|
|
use Jaxon\Di\Container; |
|
13
|
|
|
use Jaxon\Request\Handler\CallbackManager; |
|
14
|
|
|
use Jaxon\Plugin\Manager\PackageManager; |
|
15
|
|
|
use Jaxon\Plugin\Response\Dialog\DialogManager; |
|
16
|
|
|
use Jaxon\Utils\Config\ConfigReader; |
|
17
|
|
|
|
|
18
|
|
|
trait AppTrait |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $sJsLibVersion = 'jaxon_javascript_library_version'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Register the values into the container |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
private function registerApp() |
|
31
|
|
|
{ |
|
32
|
|
|
// Config Manager |
|
33
|
|
|
$this->set(ConfigEventManager::class, function($di) { |
|
|
|
|
|
|
34
|
|
|
return new ConfigEventManager($di->g(Container::class)); |
|
35
|
|
|
}); |
|
36
|
|
|
$this->set(ConfigManager::class, function($di) { |
|
37
|
|
|
$xEventManager = $di->g(ConfigEventManager::class); |
|
38
|
|
|
$xConfigManager = new ConfigManager($di->g(ConfigReader::class), $xEventManager, $di->g(Translator::class)); |
|
39
|
|
|
$xConfigManager->setOptions(require(__DIR__ . '/../../../config/lib.php')); |
|
40
|
|
|
// It's important to call this after the $xConfigManager->setOptions(), |
|
41
|
|
|
// because we don't want to trigger the events since the listeners cannot yet be instantiated. |
|
42
|
|
|
$xEventManager->addListener(Translator::class); |
|
43
|
|
|
$xEventManager->addListener(DialogManager::class); |
|
44
|
|
|
return $xConfigManager; |
|
45
|
|
|
}); |
|
46
|
|
|
|
|
47
|
|
|
// Jaxon App |
|
48
|
|
|
$this->set(AppInterface::class, function() { |
|
49
|
|
|
return new App(); |
|
50
|
|
|
}); |
|
51
|
|
|
// Jaxon App bootstrap |
|
52
|
|
|
$this->set(Bootstrap::class, function($di) { |
|
53
|
|
|
return new Bootstrap($di->g(ConfigManager::class), $di->g(PackageManager::class), |
|
54
|
|
|
$di->g(CallbackManager::class), $di->g(ViewRenderer::class)); |
|
55
|
|
|
}); |
|
56
|
|
|
// The javascript library version |
|
57
|
|
|
$this->set($this->sJsLibVersion, function($di) { |
|
58
|
|
|
$xRequest = $di->getRequest(); |
|
59
|
|
|
$aParams = $xRequest->getMethod() === 'POST' ? |
|
60
|
|
|
$xRequest->getParsedBody() : $xRequest->getQueryParams(); |
|
61
|
|
|
return $aParams['jxnv'] ?? '3.3.0'; |
|
62
|
|
|
}); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the App instance |
|
67
|
|
|
* |
|
68
|
|
|
* @return AppInterface |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getApp(): AppInterface |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->g(AppInterface::class); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the App bootstrap |
|
77
|
|
|
* |
|
78
|
|
|
* @return Bootstrap |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getBootstrap(): Bootstrap |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->g(Bootstrap::class); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get the javascript library version |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getJsLibVersion(): string |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->g($this->sJsLibVersion); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|