コード例 #1
0
ファイル: RequestTest.php プロジェクト: codecollab/http
 /**
  * @covers CodeCollab\Http\Request\Request::__construct
  * @covers CodeCollab\Http\Request\Request::cookie
  */
 public function testCookiesWithBeingSet()
 {
     $decryptor = $this->createMock(Decryptor::class);
     $decryptor->expects($this->once())->method('decrypt')->with($this->equalTo('bar'))->willReturn('decryptedbar');
     $request = new Request($decryptor, $this->baseRequestData['server'], $this->baseRequestData['get'], $this->baseRequestData['post'], $this->baseRequestData['files'], $this->baseRequestData['cookies'] + ['foo' => 'bar'], $this->baseRequestData['input']);
     $this->assertSame('decryptedbar', $request->cookie('foo'));
 }
コード例 #2
0
ファイル: User.php プロジェクト: iroegbu/Demo
 /**
  * Handles the cookie login
  *
  * @param \CodeCollab\Http\Request\Request          $request  The request object
  * @param \CodeCollab\Authentication\Authentication $user     The authentication object
  *
  * @return \Symfony\Component\HttpFoundation\Response The HTTP response
  */
 public function doCookieLogin(Request $request, Authentication $user) : Response
 {
     // Hardcoded user info. Normally this would be retrieved from the database.
     // This contains a user with username + password of demo + demo.
     $userInfo = ['username' => 'demo', 'name' => 'Demo Demo', 'hash' => '$2y$14$hPOMx1/RiQHriUVLgst0mOiZj1CyE7ziXk9LNf3UgZxsNuST.xnpe'];
     if ($request->cookie('rememberme') !== 'enabled' || !$user->logInRememberMe($userInfo)) {
         $this->response->addCookie('rememberme', '', (new \DateTime())->sub(new \DateInterval('P30D')));
     } else {
         $this->response->addCookie('rememberme', '', (new \DateTime())->add(new \DateInterval('P30D')));
     }
     $this->response->setStatusCode(StatusCode::FOUND);
     $this->response->addHeader('Location', $request->getBaseUrl());
     return $this->response;
 }