Ejemplo n.º 1
0
 /**
  * Constructor
  * @param   array $userSettings
  * @return  void
  */
 public function __construct($userSettings = array())
 {
     //Merge application settings
     $this->settings = array_merge(array('mode' => 'development', 'log.enable' => false, 'log.logger' => null, 'log.path' => './logs', 'log.level' => 4, 'debug' => true, 'templates.path' => './templates', 'view' => 'Slim_View', 'cookies.lifetime' => '20 minutes', 'cookies.path' => '/', 'cookies.domain' => '', 'cookies.secure' => false, 'cookies.httponly' => false, 'cookies.secret_key' => 'CHANGE_ME', 'cookies.cipher' => MCRYPT_RIJNDAEL_256, 'cookies.cipher_mode' => MCRYPT_MODE_CBC, 'cookies.encrypt' => true, 'cookies.user_id' => 'DEFAULT', 'session.handler' => new Slim_Session_Handler_Cookies(), 'session.flash_key' => 'flash', 'http.version' => null), $userSettings);
     //Determine application mode
     $this->getMode();
     //Setup HTTP request and response handling
     $this->request = new Slim_Http_Request();
     $this->response = new Slim_Http_Response($this->request);
     $this->response->setCookieJar(new Slim_Http_CookieJar($this->settings['cookies.secret_key'], array('high_confidentiality' => $this->settings['cookies.encrypt'], 'mcrypt_algorithm' => $this->settings['cookies.cipher'], 'mcrypt_mode' => $this->settings['cookies.cipher_mode'], 'enable_ssl' => $this->settings['cookies.secure'])));
     $this->response->httpVersion($this->settings['http.version']);
     $this->router = new Slim_Router($this->request);
     //Start session if not already started
     if (session_id() === '') {
         $sessionHandler = $this->config('session.handler');
         if ($sessionHandler instanceof Slim_Session_Handler) {
             $sessionHandler->register($this);
         }
         session_cache_limiter(false);
         session_start();
     }
     //Setup view with flash messaging
     $this->view($this->config('view'))->setData('flash', new Slim_Session_Flash($this->config('session.flash_key')));
     //Set app name
     if (!isset(self::$apps['default'])) {
         $this->setName('default');
     }
     //Set global Error handler after Slim app instantiated
     set_error_handler(array('Slim', 'handleErrors'));
 }
 /**
  * Test can set HTTP version
  */
 public function testCannotSetInvalidHttpVersion()
 {
     $this->setExpectedException('InvalidArgumentException');
     $r = new Slim_Http_Response(new Slim_Http_Request());
     $r->httpVersion('1.2');
 }