/** * Before execute handler * * @throws \Magelight\Exception */ public function beforeExecute() { \Magelight\Event\Manager::getInstance()->dispatchEvent('access_scaffolding', ['controller' => $this, 'user_id' => $this->session()->get('user_id')]); $this->entity = $this->request()->getGet('entity'); parent::beforeExecute(); $this->breadcrumbsBlock->addBreadcrumb(__('Scaffolding'), 'admin/scaffold'); if (!empty($this->entity)) { $this->breadcrumbsBlock->addBreadcrumb($this->entity, 'admin/scaffold/{entity}/', ['entity' => $this->entity]); } return $this; }
/** * Run app * * @throws \Exception|\Magelight\Exception */ public function run() { try { \Magelight\Event\Manager::getInstance()->dispatchEvent('app_start', []); $request = \Magelight\Http\Request::getInstance(); $action = \Magelight\Components\Router::getInstance($this)->getAction((string) $request->getRequestRoute()); $request->appendGet($action['arguments']); $this->dispatchAction($action); } catch (\Exception $e) { \Magelight\Log::getInstance()->add($e->getMessage()); if ($this->developerMode) { throw $e; } } }
/** * Run app * * @throws \Exception|Exception */ public function run() { try { \Magelight\Event\Manager::getInstance()->dispatchEvent('app_start', []); $request = \Magelight\Http\Request::getInstance(); $resource = $request->getGet('resource'); $staticDir = realpath($this->getAppDir() . DS . \Magelight\Config::getInstance()->getConfigString('global/view/published_static_dir', 'pub/static')); foreach (array_reverse($this->getModuleDirectories()) as $modulesPath) { $resource = str_replace('\\/', DS, $resource); $filename = $modulesPath . DS . $resource; $targetFilename = $staticDir . DS . $resource; if (file_exists($filename)) { if (!is_dir(dirname($targetFilename))) { mkdir(dirname($targetFilename), 0777, true); } if (\Magelight\Config::getInstance()->getConfigBool('global/app/developer_mode', false)) { $pathinfo = pathinfo($filename, PATHINFO_EXTENSION); if (isset($this->mimeTypes[$pathinfo])) { $mimeType = $this->mimeTypes[$pathinfo]; header('Content-type: ' . $mimeType); } echo file_get_contents($filename); break; } copy($filename, $targetFilename); header('Location: ' . \Magelight\Helpers\UrlHelper::getInstance()->getUrl($resource)); break; } } } catch (\Exception $e) { \Magelight\Log::getInstance()->add($e->getMessage()); if ($this->developerMode) { throw $e; } } }
/** * Dispatch action * * @param array $action * * @return App * @throws \Magelight\Exception */ public function dispatchAction(array $action) { $this->currentAction = $action; $eventManager = \Magelight\Event\Manager::getInstance(); $request = \Magelight\Http\Request::getInstance(); $eventManager->dispatchEvent('app_dispatch_action', ['action' => $action, 'request' => $request]); $controllerName = str_replace('/', '\\', $action['module'] . '\\Controllers\\' . ucfirst($action['controller'])); $controllerMethod = $action['action'] . 'Action'; $controller = call_user_func([$controllerName, 'forge']); /* @var $controller \Magelight\Controller */ $eventManager->dispatchEvent('app_controller_init', ['controller' => $controller, 'action' => $action, 'request' => $request]); $controller->init($action); $eventManager->dispatchEvent('app_controller_initialized', ['controller' => $controller, 'action' => $action, 'request' => $request]); $controller->beforeExecute(); $controller->{$controllerMethod}(); $controller->afterExecute(); $eventManager->dispatchEvent('app_controller_executed', ['controller' => $controller, 'action' => $action, 'request' => $request]); return $this; }