| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace ModulesGarden\ProxmoxAddon\Core\DependencyInjection;
- use \ModulesGarden\ProxmoxAddon\Core\SL\Data\DataSL;
- class Builder
- {
- /**
- * @var DataSL
- */
- protected $data = null;
- /**
- * @var array
- */
- protected $registers = [];
- public function __construct()
- {
- $this->init();
- $this->loadAliases();
- $this->loadRewrites();
- $this->loadInstances();
- }
- protected function init()
- {
- Container::setInstance(new Container());
- $this->data = new DataSL();
- $this->registers = $this->data->getRegisters();
- }
- protected function loadRewrites()
- {
- foreach ($this->data->getRewrites() as $alias => $className)
- {
- Container::getInstance()->alias($className, $alias);
- }
- }
- protected function loadAliases()
- {
- foreach ($this->data->getAllAlias() as $className => $alias)
- {
- Container::getInstance()->alias($className, $alias);
- }
- }
- protected function loadInstances()
- {
- foreach ($this->data->getConfigurations() as $config)
- {
- $className = $config['name'];
- $method = $config['method'];
- $arguments = $config['args'];
- if (!$method)
- {
- $obj = Container::getInstance()->make($className);
- }
- else
- {
- $obj = call_user_func_array("$className::$method", $arguments);
- }
- if (array_key_exists($className, $this->registers) && $this->registers[$className]['singleton'])
- {
- Container::getInstance()->instance($className, $obj);
- }
- }
- }
- }
|