|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace Jaxon\Container\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Config\ConfigManager; |
|
6
|
|
|
use Jaxon\Jaxon; |
|
7
|
|
|
use Jaxon\Container\Container; |
|
8
|
|
|
use Jaxon\Request\Handler\RequestHandler; |
|
9
|
|
|
use Jaxon\Request\Plugin\CallableClass\CallableRegistry; |
|
10
|
|
|
use Jaxon\Request\Plugin\CallableClass\CallableRepository; |
|
11
|
|
|
use Jaxon\Request\Plugin\CallableClass\CallableClassPlugin; |
|
12
|
|
|
use Jaxon\Request\Plugin\CallableClass\CallableDirPlugin; |
|
13
|
|
|
use Jaxon\Request\Plugin\CallableFunction\CallableFunctionPlugin; |
|
14
|
|
|
use Jaxon\Request\Validator; |
|
15
|
|
|
use Jaxon\Response\ResponseManager; |
|
16
|
|
|
use Jaxon\Utils\Config\Config; |
|
17
|
|
|
use Jaxon\Utils\Template\Engine as TemplateEngine; |
|
18
|
|
|
use Jaxon\Utils\Translation\Translator; |
|
19
|
|
|
|
|
20
|
|
|
trait CallableTrait |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Register the values into the container |
|
24
|
|
|
* |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
private function registerCallables() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
// Validator |
|
30
|
|
|
$this->set(Validator::class, function($c) { |
|
|
|
|
|
|
31
|
|
|
return new Validator($c->g(Translator::class), $c->g(Config::class)); |
|
32
|
|
|
}); |
|
33
|
|
|
// Callable objects repository |
|
34
|
|
|
$this->set(CallableRepository::class, function($c) { |
|
35
|
|
|
return new CallableRepository($c->g(Container::class)); |
|
36
|
|
|
}); |
|
37
|
|
|
// Callable objects registry |
|
38
|
|
|
$this->set(CallableRegistry::class, function($c) { |
|
39
|
|
|
return new CallableRegistry($c->g(Container::class), |
|
40
|
|
|
$c->g(CallableRepository::class), $c->g(Translator::class)); |
|
41
|
|
|
}); |
|
42
|
|
|
// Callable class plugin |
|
43
|
|
|
$this->set(CallableClassPlugin::class, function($c) { |
|
44
|
|
|
$sPrefix = $c->g(ConfigManager::class)->getOption('core.prefix.class'); |
|
45
|
|
|
return new CallableClassPlugin($sPrefix, $c->g(RequestHandler::class), |
|
46
|
|
|
$c->g(ResponseManager::class), $c->g(CallableRegistry::class), $c->g(CallableRepository::class), |
|
47
|
|
|
$c->g(TemplateEngine::class), $c->g(Translator::class), $c->g(Validator::class)); |
|
48
|
|
|
}); |
|
49
|
|
|
// Callable dir plugin |
|
50
|
|
|
$this->set(CallableDirPlugin::class, function($c) { |
|
51
|
|
|
return new CallableDirPlugin($c->g(CallableRegistry::class), $c->g(Translator::class)); |
|
52
|
|
|
}); |
|
53
|
|
|
// Callable function plugin |
|
54
|
|
|
$this->set(CallableFunctionPlugin::class, function($c) { |
|
55
|
|
|
$sPrefix = $c->g(ConfigManager::class)->getOption('core.prefix.function'); |
|
56
|
|
|
return new CallableFunctionPlugin($sPrefix, $c->g(RequestHandler::class), |
|
57
|
|
|
$c->g(ResponseManager::class), $c->g(TemplateEngine::class), |
|
58
|
|
|
$c->g(Translator::class), $c->g(Validator::class)); |
|
59
|
|
|
}); |
|
60
|
|
|
} |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the callable registry |
|
64
|
|
|
* |
|
65
|
|
|
* @return CallableRegistry |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getClassRegistry(): 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
|
|
|
|