예제 #1
0
 public function destroy($id)
 {
     Slim::deleteCookie($id);
 }
예제 #2
0
파일: SlimTest.php 프로젝트: rs3d/Slimplr
 /**
  * Test delete cookie
  *
  * This method ensures that the `Set-Cookie:` HTTP response
  * header is set. The implementation of setting the response
  * cookie is tested separately in another file.
  */
 public function testDeleteCookie()
 {
     Slim_Environment::mock(array('SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar', 'COOKIE' => 'foo=bar; foo2=bar2'));
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->setCookie('foo', 'bar');
         $s->deleteCookie('foo');
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $cookies = explode("\n", $header['Set-Cookie']);
     $this->assertEquals(1, count($cookies));
     $this->assertEquals(1, preg_match('@^foo=;@', $cookies[0]));
 }
예제 #3
0
파일: Slim.php 프로젝트: alanvivona/scawTP
 /**
  * Initialize Slim
  *
  * This instantiates the Slim application using the provided
  * application settings if available.
  *
  * Legacy Support:
  *
  * To support applications built with an older version of Slim,
  * this method's argument may also be a string (the name of a View class)
  * or an instance of a View class or subclass.
  *
  * @param   array|string|Slim_View  $viewClass   An array of settings;
  *                                               The name of a View class;
  *                                               A View class or subclass instance;
  * @return  void
  */
 public static function init($userSettings = array())
 {
     //Legacy support
     if (is_string($userSettings) || $userSettings instanceof Slim_View) {
         $settings = array('view' => $userSettings);
     } else {
         $settings = (array) $userSettings;
     }
     //Init app
     self::$app = new Slim($settings);
     //Init Not Found and Error handlers
     self::notFound(array('Slim', 'defaultNotFound'));
     self::error(array('Slim', 'defaultError'));
     //Init view
     self::view(Slim::config('view'));
     //Init logging
     if (Slim::config('log.enable') === true) {
         $logger = Slim::config('log.logger');
         if (empty($logger)) {
             Slim_Log::setLogger(new Slim_Logger(Slim::config('log.path'), Slim::config('log.level')));
         } else {
             Slim_Log::setLogger($logger);
         }
     }
     //Start session if not already started
     if (session_id() === '') {
         $sessionHandler = Slim::config('session.handler');
         if ($sessionHandler instanceof Slim_Session_Handler) {
             $sessionHandler->register();
         }
         session_start();
         if (isset($_COOKIE[session_id()])) {
             Slim::deleteCookie(session_id());
         }
         session_regenerate_id(true);
     }
     //Init flash messaging
     self::$app->flash = new Slim_Session_Flash(self::config('session.flash_key'));
     self::view()->setData('flash', self::$app->flash);
     //Determine mode
     if (isset($_ENV['SLIM_MODE'])) {
         self::$app->mode = (string) $_ENV['SLIM_MODE'];
     } else {
         $configMode = Slim::config('mode');
         self::$app->mode = $configMode ? (string) $configMode : 'development';
     }
 }
예제 #4
0
 /**
  * Test Slim deletes cookies
  *
  * Pre-conditions:
  * Case A: Classic cookie
  * Case B: Encrypted cookie
  *
  * Post-conditions:
  * Response Cookies replaced with empty, auto-expiring Cookies
  */
 public function testSlimDeletesCookies()
 {
     $app = new Slim();
     $cj = $app->response()->getCookieJar();
     //Case A
     $app->setCookie('foo1', 'bar1');
     $this->assertEquals('bar1', $cj->getResponseCookie('foo1')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() > time());
     $app->deleteCookie('foo1');
     $this->assertEquals('', $app->getCookie('foo1'));
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() < time());
     //Case B
     $app->setEncryptedCookie('foo2', 'bar2');
     $this->assertTrue(strlen($cj->getResponseCookie('foo2')->getValue()) > 0);
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() > time());
     $app->deleteCookie('foo2');
     $this->assertEquals('', $cj->getResponseCookie('foo2')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() < time());
 }
예제 #5
0
 /**
  * Test delete cookie
  *
  * This method ensures that the `Set-Cookie:` HTTP response
  * header is set. The implementation of setting the response
  * cookie is tested separately in another file.
  */
 public function testDeleteCookie()
 {
     Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar', 'QUERY_STRING' => 'one=foo&two=bar', 'SERVER_NAME' => 'slimframework.com', 'SERVER_PORT' => 80, 'HTTP_COOKIE' => 'foo=bar; foo2=bar2', 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => @fopen('php://stderr', 'w')));
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->setCookie('foo', 'bar');
         $s->deleteCookie('foo');
     });
     $env = $s->environment();
     list($status, $header, $body) = $s->call($env);
     $cookies = explode("\n", $header['Set-Cookie']);
     $this->assertEquals(1, count($cookies));
     $this->assertEquals(1, preg_match('@^foo=;@', $cookies[0]));
 }
예제 #6
0
 /**
  * Test Slim deletes cookies
  *
  * Pre-conditions:
  * Case A: Classic cookie
  * Case B: Encrypted cookie
  *
  * Post-conditions:
  * Response Cookies replaced with empty, auto-expiring Cookies
  */
 public function testSlimDeletesCookies()
 {
     Slim::init();
     $cj = Slim::response()->getCookieJar();
     //Case A
     Slim::setCookie('foo1', 'bar1');
     $this->assertEquals('bar1', $cj->getResponseCookie('foo1')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() > time());
     Slim::deleteCookie('foo1');
     $this->assertEquals('', Slim::getCookie('foo1'));
     $this->assertTrue($cj->getResponseCookie('foo1')->getExpires() < time());
     //Case B
     Slim::setEncryptedCookie('foo2', 'bar2');
     $this->assertTrue(strlen($cj->getResponseCookie('foo2')->getValue()) > 0);
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() > time());
     Slim::deleteCookie('foo2');
     $this->assertEquals('', $cj->getResponseCookie('foo2')->getValue());
     $this->assertTrue($cj->getResponseCookie('foo2')->getExpires() < time());
 }