/** * Test add log message */ public function testAdd() { $configMock = $this->getMock(\Magelight\Config::class, [], [], '', false); \Magelight\Config::forgeMock($configMock); $configMock->expects($this->any())->method('getConfig')->with('global/log/file', \Magelight\Log::DEFAUL_LOG_FILE)->will($this->returnValue('application.log')); $this->log->expects($this->once())->method('writeMessage')->with($this->matchesRegularExpression("/[\\-\\:\\d]+\\s\\-\\serror/i")); $this->log->add('error'); }
/** * No route action */ public function no_routeAction() { $this->view->set('title', 'Page not found'); /* @var $block \SampleApp\Blocks\Error */ $block = \SampleApp\Blocks\Error::forge(); $block->setTemplate(\SampleApp\Blocks\Error::TEMPLATE_404); $this->view->sectionReplace('content', $block); \Magelight\Log::getInstance()->add('404 - not found ' . $this->request()->getRequestRoute()); $this->renderView(); }
/** * 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; } } }