|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace Jaxon\Di\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Jaxon; |
|
6
|
|
|
use Jaxon\Config\ConfigManager; |
|
7
|
|
|
use Jaxon\Di\Container; |
|
8
|
|
|
use Jaxon\Plugin\Code\AssetManager; |
|
9
|
|
|
use Jaxon\Plugin\Code\CodeGenerator; |
|
10
|
|
|
use Jaxon\Plugin\Manager\PluginManager; |
|
11
|
|
|
use Jaxon\Request\Handler\UploadHandler; |
|
12
|
|
|
use Jaxon\Request\Upload\UploadManager; |
|
13
|
|
|
use Jaxon\Request\Validator; |
|
14
|
|
|
use Jaxon\Response\Plugin\DataBag\DataBagPlugin; |
|
15
|
|
|
use Jaxon\Response\Plugin\JQuery\JQueryPlugin; |
|
16
|
|
|
use Jaxon\Response\ResponseManager; |
|
17
|
|
|
use Jaxon\Ui\View\ViewManager; |
|
18
|
|
|
use Jaxon\Utils\File\FileMinifier; |
|
|
|
|
|
|
19
|
|
|
use Jaxon\Utils\Http\UriDetector; |
|
20
|
|
|
use Jaxon\Utils\Template\TemplateEngine; |
|
|
|
|
|
|
21
|
|
|
use Jaxon\Utils\Translation\Translator; |
|
22
|
|
|
|
|
23
|
|
|
trait PluginTrait |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Register the values into the container |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
private function registerPlugins() |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
// Plugin manager |
|
33
|
|
|
$this->set(PluginManager::class, function($c) { |
|
|
|
|
|
|
34
|
|
|
return new PluginManager($c->g(Container::class), $c->g(ConfigManager::class), |
|
35
|
|
|
$c->g(ViewManager::class), $c->g(CodeGenerator::class), $c->g(Translator::class)); |
|
36
|
|
|
}); |
|
37
|
|
|
// Code Generation |
|
38
|
|
|
$this->set(AssetManager::class, function($c) { |
|
39
|
|
|
return new AssetManager($c->g(ConfigManager::class), $c->g(UriDetector::class), $c->g(FileMinifier::class)); |
|
40
|
|
|
}); |
|
41
|
|
|
$this->set(CodeGenerator::class, function($c) { |
|
42
|
|
|
$sVersion = $c->g(Jaxon::class)->getVersion(); |
|
43
|
|
|
return new CodeGenerator($sVersion, $c->g(Container::class), |
|
44
|
|
|
$c->g(TemplateEngine::class), $c->g(AssetManager::class)); |
|
45
|
|
|
}); |
|
46
|
|
|
// File upload manager |
|
47
|
|
|
$this->set(UploadManager::class, function($c) { |
|
48
|
|
|
return new UploadManager($c->g(ConfigManager::class), $c->g(Validator::class), $c->g(Translator::class)); |
|
49
|
|
|
}); |
|
50
|
|
|
// File upload plugin |
|
51
|
|
|
$this->set(UploadHandler::class, function($c) { |
|
52
|
|
|
return !$c->g(ConfigManager::class)->getOption('core.upload.enabled') ? null : |
|
|
|
|
|
|
53
|
|
|
new UploadHandler($c->g(UploadManager::class), $c->g(ResponseManager::class), $c->g(Translator::class)); |
|
54
|
|
|
}); |
|
55
|
|
|
// JQuery response plugin |
|
56
|
|
|
$this->set(JQueryPlugin::class, function($c) { |
|
57
|
|
|
$jQueryNs = $c->g(ConfigManager::class)->getOption('core.jquery.no_conflict', false) ? 'jQuery' : '$'; |
|
58
|
|
|
return new JQueryPlugin($jQueryNs); |
|
59
|
|
|
}); |
|
60
|
|
|
// DataBagPlugin response plugin |
|
61
|
|
|
$this->set(DataBagPlugin::class, function() { |
|
62
|
|
|
return new DataBagPlugin(); |
|
63
|
|
|
}); |
|
64
|
|
|
} |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get the plugin manager |
|
68
|
|
|
* |
|
69
|
|
|
* @return PluginManager |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getPluginManager(): PluginManager |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->g(PluginManager::class); |
|
|
|
|
|
|
74
|
|
|
} |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get the code generator |
|
78
|
|
|
* |
|
79
|
|
|
* @return CodeGenerator |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getCodeGenerator(): CodeGenerator |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->g(CodeGenerator::class); |
|
84
|
|
|
} |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get the upload handler |
|
88
|
|
|
* |
|
89
|
|
|
* @return UploadHandler|null |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getUploadHandler(): ?UploadHandler |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->g(UploadHandler::class); |
|
94
|
|
|
} |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get the jQuery plugin |
|
98
|
|
|
* |
|
99
|
|
|
* @return JQueryPlugin |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getJQueryPlugin(): JQueryPlugin |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
return $this->g(JQueryPlugin::class); |
|
104
|
|
|
} |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|