Example #1
0
 /**
  * Default Handler for Logout Controller 
  * 
  * @param mixed $request Request to process.
  *
  * @access public
  * @return void
  */
 public function _default($request)
 {
     $subject = \Native5\Identity\SecurityUtils::getSubject();
     $subject->logout();
     \Native5\Sessions\WebSessionManager::resetActiveSession();
     $this->_response = new \Native5\Route\HttpResponse();
     $this->_response->redirectTo('./login');
     //$idenService = new \Native5\Services\Identity\RemoteAuthenticationService();
     //$idenService->onLogout();
     //WebSessionManager::resetActiveSession();
     //$this->_response = new \Native5\Route\HttpResponse();
     //$this->_response->redirectTo('./');
 }
Example #2
0
 /**
  * init 
  * 
  * @param string $configFile Configuration with which to initialize an app with
  *
  * @static
  * @access public
  * @return void
  */
 public static function init($configFile = 'config/settings.yml', $localConfigFile = 'config/settings.local.yml')
 {
     // Check what php SAPI is being used
     self::$_cli = false;
     if (strcmp(php_sapi_name(), 'cli') === 0) {
         self::$_cli = true;
     }
     // Initialize application services, Store application Object as a global
     // Services are available from global app.
     $GLOBALS['app'] = $app = new self();
     $GLOBALS['logger'] = LoggerFactory::instance()->getLogger();
     $GLOBALS['routeLogger'] = LoggerFactory::instance()->getLogger();
     $configFactory = new ConfigurationFactory($configFile, $localConfigFile);
     $app->_config = $configFactory->getConfig();
     $logFolder = getcwd() . '/logs';
     if (!file_exists($logFolder)) {
         if (!mkdir($logFolder)) {
             $logFolder = sys_get_temp_dir() . '/logs';
             if (!file_exists($logFolder) && !mkdir($logFolder)) {
                 die('Insufficient privileges to create logs folder in application directory, or temp path, exiting');
             }
         }
     }
     $file = $logFolder . DIRECTORY_SEPARATOR . $app->_config->getApplicationContext() . '-debug.log';
     $GLOBALS['logger']->addHandler($file, Logger::ALL, self::$LOG_MAPPING[$app->_config->getLogLevel()]);
     $analyticsFile = $logFolder . DIRECTORY_SEPARATOR . $app->_config->getApplicationContext() . '-analytics.log';
     $GLOBALS['routeLogger']->addHandler($analyticsFile, Logger::ALL, self::$LOG_MAPPING[$app->_config->getLogLevel()], 'analytics');
     if (!self::$_cli) {
         $sessionManager = new WebSessionManager();
         $sessionManager->startSession(null, true);
         $app->_services['sessions'] = $sessionManager;
         SecurityUtils::setSecurityManager(new DefaultSecurityManager());
         $app->_subject = $app->_getSubjectFromSession($sessionManager->getActiveSession());
         $app->_services['routing'] = new RoutingEngine();
     }
     $app->_services['messaging'] = NotificationService::instance();
     return $app;
 }
 /**
  * Handles Request Execution. 
  * 
  * @param mixed $request HttpRequest @see Native5/Route/HttpRequest 
  *
  * @access public
  * @return void
  */
 public function execute($request)
 {
     ob_start();
     $logger = $GLOBALS['logger'];
     $this->_request = $request;
     $this->_response = new HttpResponse();
     try {
         WebSessionManager::updateActiveSession();
         foreach ($this->_preProcessors as $preProcessor) {
             $preProcessor->process($this->_request);
         }
         $functionToCall = $this->command->getFunction();
         if (empty($functionToCall) === true) {
             $functionToCall = 'default';
         }
         if (!is_callable(array(&$this, '_' . $functionToCall))) {
             $functionToCall = 'error';
         }
         call_user_func(array(&$this, '_' . $functionToCall), $this->_request);
         foreach ($this->_postProcessors as $postProcessor) {
             $postProcessor->process($this->_response);
         }
         ob_end_clean();
         if (empty($this->_response)) {
             $this->_response = new HttpResponse();
         }
         if ($this->_response->getEncoding() == null) {
             $responseMode = $this->_request->getParam('mode');
             if ($responseMode === 'ui') {
                 $this->_response->setEncoding('html');
             } else {
                 if ($responseMode === 'data') {
                     $this->_response->setEncoding('json');
                 }
             }
         }
         $this->_response->send();
     } catch (ServiceException $se) {
         $this->_response = new HttpResponse();
         $response->addHeader('HTTP/1.1 400 Bad Request');
         $this->_response->send();
     } catch (BadResponseException $bre) {
         $renderer = new TwigRenderer('500.html');
         if ($renderer->exists()) {
             $this->_response = new HttpResponse('none', $renderer);
         } else {
             $this->_response = new HttpResponse();
         }
         $response->addHeader('HTTP/1.1 500 Internal Server Error');
         $this->_response->send();
     }
     //end try
 }
 /**
  * destroy 
  * 
  * @param Subject $subject The subject to destroy.
  *
  * @access public
  * @return void
  */
 public function destroy(Subject $subject)
 {
     $this->removeFromSession($subject);
     WebSessionManager::resetActiveSession();
 }