예제 #1
0
 /**
  * @expectedException \Magelight\Exception
  * @expectedExceptionMessage Observer '\Magelight\Observer' method 'unexistentMethod' does not exist or is not callable!
  */
 public function testDispatchEventException()
 {
     $eventName = 'test_event';
     $observerClass1 = '\\Magelight\\Observer::unexistentMethod';
     $observers = [$observerClass1];
     $this->configMock->expects($this->once())->method('getConfigSet')->with('global/events/' . $eventName . '/observer')->will($this->returnValue($observers));
     $observerMock = $this->getMockForAbstractClass('\\Magelight\\Observer', [], '', false, false, true, ['execute']);
     \Magelight\Observer::forgeMock($observerMock);
     $this->eventManager->dispatchEvent('test_event');
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
파일: Web.php 프로젝트: rganin/magelight
 /**
  * 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;
         }
     }
 }
예제 #4
0
 public function testDispatchAction()
 {
     $action = ['module' => 'Magelight', 'controller' => 'controller', 'action' => 'index'];
     $requestMock = $this->getMock(\Magelight\Http\Request::class, [], [], '', false);
     \Magelight\Http\Request::forgeMock($requestMock);
     class_alias(\Magelight\Controller::class, '\\Magelight\\Controllers\\Controller');
     $controllerMock = $this->getMockForAbstractClass(\Magelight\Controller::class, [], '', false, false, false, ['indexAction', 'init', 'beforeExecute', 'afterExecute']);
     \Magelight\Controller::forgeMock($controllerMock);
     $controllerMock->expects($this->once())->method('indexAction');
     $controllerMock->expects($this->once())->method('init')->with($action);
     $controllerMock->expects($this->once())->method('beforeExecute');
     $controllerMock->expects($this->once())->method('afterExecute');
     $this->eventManagerMock->expects($this->at(0))->method('dispatchEvent')->with('app_dispatch_action', ['action' => $action, 'request' => $requestMock]);
     $this->eventManagerMock->expects($this->at(1))->method('dispatchEvent')->with('app_controller_init', ['controller' => $controllerMock, 'action' => $action, 'request' => $requestMock]);
     $this->eventManagerMock->expects($this->at(2))->method('dispatchEvent')->with('app_controller_initialized', ['controller' => $controllerMock, 'action' => $action, 'request' => $requestMock]);
     $this->eventManagerMock->expects($this->at(3))->method('dispatchEvent')->with('app_controller_executed', ['controller' => $controllerMock, 'action' => $action, 'request' => $requestMock]);
     $this->app->dispatchAction($action);
     $this->assertEquals($action, $this->app->getCurrentAction());
 }
예제 #5
0
 /**
  * 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;
         }
     }
 }
예제 #6
0
파일: App.php 프로젝트: rganin/magelight
 /**
  * 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;
 }