/**
  * 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'), $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->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_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'));
 }
Пример #2
0
 /**
  * Test sets and gets CookieJar
  */
 public function testSetsAndGetsCookieJar()
 {
     $r = new Slim_Http_Response(new Slim_Http_Request());
     $cj = new Slim_Http_CookieJar('secret');
     $r->setCookieJar($cj);
     $this->assertSame($cj, $r->getCookieJar());
 }
Пример #3
0
Файл: Slim.php Проект: ntdt/Slim
 /**
  * Constructor
  *
  * @param   array $userSettings
  * @return  void
  */
 private function __construct( $userSettings = array() ) {
     $this->settings = array_merge(array(
         //Logging
         'log.enable' => false,
         'log.logger' => null,
         'log.path' => './logs',
         'log.level' => 4,
         //Debugging
         'debug' => true,
         //View
         'templates_dir' => './templates',
         'view' => 'Slim_View',
         //Settings for all cookies
         'cookies.lifetime' => '20 minutes',
         'cookies.path' => '/',
         'cookies.domain' => '',
         'cookies.secure' => false,
         'cookies.httponly' => false,
         //Settings for encrypted cookies
         'cookies.secret_key' => 'CHANGE_ME',
         'cookies.cipher' => MCRYPT_RIJNDAEL_256,
         'cookies.cipher_mode' => MCRYPT_MODE_CBC,
         'cookies.encrypt' => true,
         'cookies.user_id' => 'DEFAULT'
     ), $userSettings);
     $this->request = new Slim_Http_Request();
     $this->response = new Slim_Http_Response($this->request);
     $this->router = new Slim_Router($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']
     )));
 }