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