1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jaxon\Di\Traits; |
4
|
|
|
|
5
|
|
|
use Jaxon\App\Config\ConfigManager; |
6
|
|
|
use Jaxon\App\I18n\Translator; |
7
|
|
|
use Jaxon\App\Pagination; |
8
|
|
|
use Jaxon\Di\ClassContainer; |
9
|
|
|
use Jaxon\Di\Container; |
10
|
|
|
use Jaxon\Plugin\Request\CallableClass\CallableClassPlugin; |
11
|
|
|
use Jaxon\Plugin\Request\CallableClass\CallableDirPlugin; |
12
|
|
|
use Jaxon\Plugin\Request\CallableClass\CallableRegistry; |
13
|
|
|
use Jaxon\Plugin\Request\CallableFunction\CallableFunctionPlugin; |
14
|
|
|
use Jaxon\Request\Validator; |
15
|
|
|
use Jaxon\Utils\Template\TemplateEngine; |
16
|
|
|
|
17
|
|
|
trait CallableTrait |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Register the values into the container |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
private function registerCallables() |
25
|
|
|
{ |
26
|
|
|
// Validator |
27
|
|
|
$this->set(Validator::class, function($di) { |
|
|
|
|
28
|
|
|
return new Validator($di->g(ConfigManager::class), $di->g(Translator::class)); |
29
|
|
|
}); |
30
|
|
|
// Callable objects registry |
31
|
|
|
$this->set(CallableRegistry::class, function($di) { |
32
|
|
|
$xRegistry = new CallableRegistry($di->g(ClassContainer::class)); |
33
|
|
|
// Register the pagination component, but do not export to js. |
34
|
|
|
$xRegistry->registerClass(Pagination::class, |
35
|
|
|
['excluded' => true, 'namespace' => 'Jaxon\App']); |
36
|
|
|
return $xRegistry; |
37
|
|
|
}); |
38
|
|
|
// Callable class plugin |
39
|
|
|
$this->set(CallableClassPlugin::class, function($di) { |
40
|
|
|
$sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.class'); |
41
|
|
|
$bDebug = $di->g(ConfigManager::class)->getOption('core.debug.on', false); |
42
|
|
|
return new CallableClassPlugin($sPrefix, $bDebug, |
43
|
|
|
$di->g(Container::class), $di->g(ClassContainer::class), |
44
|
|
|
$di->g(CallableRegistry::class), $di->g(TemplateEngine::class), |
45
|
|
|
$di->g(Translator::class), $di->g(Validator::class)); |
46
|
|
|
}); |
47
|
|
|
// Callable dir plugin |
48
|
|
|
$this->set(CallableDirPlugin::class, function($di) { |
49
|
|
|
return new CallableDirPlugin($di->g(ClassContainer::class), |
50
|
|
|
$di->g(CallableRegistry::class), $di->g(Translator::class)); |
51
|
|
|
}); |
52
|
|
|
// Callable function plugin |
53
|
|
|
$this->set(CallableFunctionPlugin::class, function($di) { |
54
|
|
|
$sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.function'); |
55
|
|
|
$bDebug = $di->g(ConfigManager::class)->getOption('core.debug.on', false); |
56
|
|
|
return new CallableFunctionPlugin($sPrefix, $bDebug, |
57
|
|
|
$di->g(Container::class), $di->g(TemplateEngine::class), |
58
|
|
|
$di->g(Translator::class), $di->g(Validator::class)); |
59
|
|
|
}); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the callable registry |
64
|
|
|
* |
65
|
|
|
* @return CallableRegistry |
66
|
|
|
*/ |
67
|
|
|
public function getCallableRegistry(): CallableRegistry |
68
|
|
|
{ |
69
|
|
|
return $this->g(CallableRegistry::class); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the callable function plugin |
74
|
|
|
* |
75
|
|
|
* @return CallableFunctionPlugin |
76
|
|
|
*/ |
77
|
|
|
public function getCallableFunctionPlugin(): CallableFunctionPlugin |
78
|
|
|
{ |
79
|
|
|
return $this->g(CallableFunctionPlugin::class); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get the callable class plugin |
84
|
|
|
* |
85
|
|
|
* @return CallableClassPlugin |
86
|
|
|
*/ |
87
|
|
|
public function getCallableClassPlugin(): CallableClassPlugin |
88
|
|
|
{ |
89
|
|
|
return $this->g(CallableClassPlugin::class); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get the callable dir plugin |
94
|
|
|
* |
95
|
|
|
* @return CallableDirPlugin |
96
|
|
|
*/ |
97
|
|
|
public function getCallableDirPlugin(): CallableDirPlugin |
98
|
|
|
{ |
99
|
|
|
return $this->g(CallableDirPlugin::class); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|