Example #1
0
 public function testGetCodeByFrontNameReturnsAreaCode()
 {
     $expected = 'testArea';
     $this->_model = new \Magento\Framework\App\AreaList($this->objectManagerMock, $this->_resolverFactory, ['testArea' => ['frontName' => 'testFrontName']], $expected);
     $actual = $this->_model->getCodeByFrontName('testFrontName');
     $this->assertEquals($expected, $actual);
 }
Example #2
0
 public function testGetFrontNameWhenAreaCodeAndFrontNameArentSet()
 {
     $model = new \Magento\Framework\App\AreaList($this->objectManagerMock, $this->_resolverFactory);
     $code = 'testAreaCode';
     $this->assertNull($model->getCodeByFrontName($code));
     $this->assertNull($model->getFrontName($code));
     $this->assertSame([], $model->getCodes());
     $this->assertNull($model->getDefaultRouter($code));
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\App\\AreaInterface', ['areaCode' => $code])->willReturn('test');
     $this->assertSame('test', $model->getArea($code));
 }
Example #3
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_configLoader->load($areaCode));
     $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
     // This event gives possibility to launch something before sending output (allow cookie setting)
     $eventParams = array('request' => $this->_request, 'response' => $this->_response);
     $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     return $this->_response;
 }
Example #4
0
 /**
  * Observer for controller_front_send_response_before event fired in lib/internal/Magento/Framework/App/Http.php.
  *
  * $eventParams = ['request' => $this->_request, 'response' => $this->_response];
  *
  * request => Magento\Framework\App\Request\Http
  * response => Magento\Framework\Webapi\Rest\Response\Proxy
  *
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /* @var $request \Magento\Framework\App\Request\Http */
     $request = $observer->getEvent()->getRequest();
     $areaCode = $this->areaList->getCodeByFrontName($request->getFrontName());
     /**
      * Stop execution if module is not active
      * or if the current request falls within excluded areas
      * or if the current request falls within excluded actions
      */
     if (!$this->helper->isFoggylineSentinelActive() or in_array($areaCode, $this->helper->getExcludeAreas()) or in_array($request->getFullActionName(), $this->helper->getExcludeActions())) {
         //return $this;
     }
     /* @var $log \Foggyline\Sentinel\Model\AccessLog */
     $log = $this->log->create();
     $log->setRequestId($this->helper->getHttpRequestUniqueId());
     if ($this->authSession && $this->authSession->getUser()) {
         $user = $this->authSession->getUser();
         $log->setUserId($user->getId());
         $log->setUserUsername($user->getUserName());
         $log->setUserEmail($user->getEmail());
         $log->setUserName($user->getName());
     }
     $log->setActionName($request->getActionName());
     $log->setFullActionName($request->getFullActionName());
     $log->setClientIp($request->getClientIp());
     $log->setRequestString($request->getRequestString());
     $log->setRequestMethod($request->getMethod());
     $log->setHttpGetParams($_GET);
     $log->setHttpPostParams($_POST);
     $log->setHttpFilesParams($_FILES);
     $log->setModuleName($request->getModuleName());
     $log->setControllerModule($request->getControllerModule());
     $log->setArea($areaCode);
     try {
         $log->save();
     } catch (\Exception $e) {
         $this->logger->critical($e);
     }
     return $this;
 }
Example #5
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     try {
         $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
         $this->_state->setAreaCode($areaCode);
         $this->_objectManager->configure($this->_configLoader->load($areaCode));
         $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
         // This event gives possibility to launch something before sending output (allow cookie setting)
         $eventParams = array('request' => $this->_request, 'response' => $this->_response);
         $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     } catch (\Exception $exception) {
         $message = $exception->getMessage() . "\n";
         try {
             if ($this->_state->getMode() == State::MODE_DEVELOPER) {
                 $message .= '<pre>';
                 $message .= $exception->getMessage() . "\n\n";
                 $message .= $exception->getTraceAsString();
                 $message .= '</pre>';
             } else {
                 $reportData = array($exception->getMessage(), $exception->getTraceAsString());
                 // retrieve server data
                 if (isset($_SERVER)) {
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $reportData['url'] = $_SERVER['REQUEST_URI'];
                     }
                     if (isset($_SERVER['SCRIPT_NAME'])) {
                         $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
                     }
                 }
                 require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
                 $processor = new \Magento\Framework\Error\Processor($this->_response);
                 $processor->saveReport($reportData);
                 $this->_response = $processor->processReport();
             }
         } catch (\Exception $exception) {
             $message .= "Unknown error happened.";
         }
         $this->_response->setHttpResponseCode(500);
         $this->_response->setBody($message);
     }
     return $this->_response;
 }
Example #6
0
 /**
  * Run application
  *
  * @throws \InvalidArgumentException
  * @return ResponseInterface
  */
 public function launch()
 {
     $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_configLoader->load($areaCode));
     /** @var \Magento\Framework\App\FrontControllerInterface $frontController */
     $frontController = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface');
     $result = $frontController->dispatch($this->_request);
     // TODO: Temporary solution until all controllers return ResultInterface (MAGETWO-28359)
     if ($result instanceof ResultInterface) {
         $this->registry->register('use_page_cache_plugin', true, true);
         $result->renderResult($this->_response);
     } elseif ($result instanceof HttpInterface) {
         $this->_response = $result;
     } else {
         throw new \InvalidArgumentException('Invalid return type');
     }
     // This event gives possibility to launch something before sending output (allow cookie setting)
     $eventParams = ['request' => $this->_request, 'response' => $this->_response];
     $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     return $this->_response;
 }