function __construct() { parent::__construct(); if (!defined('ROOT_DIR') || !ROOT_DIR) { $rootDir = realpath(__DIR__ . '../../../../../'); define('ROOT_DIR', $rootDir); } $this['sessions'] = function () { return $this->getSession(); }; $this['request'] = function () { return $this->getRequest(); }; $this['response'] = function () { return $this->getResponse(); }; $this['router'] = function () { return $this->getRouter(); }; $this['view'] = function () { return $this->getView(); }; $this["config"] = function () { return $this->getConfig(); }; $this["moduleManager"] = function () { $modulesList = $this->getConfig("modules", [])->toArray(); $mm = new ModuleManager($modulesList); $mm->setLoader($this->getLoader()); return $mm; }; }
public static function init(ModuleManager $moduleManager, Application $application) { $application->extend("DeltaPhp\\Operator", function (Operator $operator, Container $c) use($moduleManager) { $workers = $moduleManager->getListArrayConfigs("workers"); foreach ($workers as $workerName => $data) { $workerParams = []; if (is_callable($data)) { $function = $data; } elseif (is_array($data)) { foreach ($data as $key => $row) { if (is_callable($row)) { $function = $row; } else { switch ($key) { case WorkerInterface::PARAM_TABLEID: $operator->setWorkerTable($row, $workerName); $workerParams[WorkerInterface::PARAM_TABLEID] = $row; break; case WorkerInterface::PARAM_ACTIONS_MAP: foreach ($row as $action => $actionParam) { if (!is_array($actionParam)) { $operator->addAction($action, $workerName, $actionParam); } else { foreach ($actionParam as $class => $order) { $operator->addAction($action, $workerName, $class, $order); } } } break; default: $workerParams[$key] = $row; break; } } } } $operator->addWorker($workerName, $function); $operator->setWorkerParams($workerName, $workerParams); } return $operator; }); }