/**
  * {@inheritdoc}
  */
 public function handle(Request $request, RequestContext $context, Closure $next)
 {
     if (!$request->getCookieBag()->has('username')) {
         return new Response('Please logged in first.');
     }
     return $next();
 }
 /**
  * Get extension functions.
  *
  * @return array
  */
 public function getFunctions()
 {
     $functions = array(new Twig_Function('route', array($this, 'generateRoute')));
     if (null !== $this->request) {
         $functions[] = new Twig_Function('url', array($this->request->getUrl(), 'getUrlForPath'));
     }
     return $functions;
 }
Exemplo n.º 3
0
 public function testRequest()
 {
     $request = Request::create('https://localhost:8000/index.php/view/page?username=iqbal&firstName=Iqbal', Request::HTTP_METHOD_GET, array('lastName' => 'Maulana'), array('username' => 'test'), array('HTTP_USER_AGENT' => 'Php-Unit', 'SCRIPT_FILENAME' => '/index.php', 'SCRIPT_NAME' => '/index.php'));
     $this->assertEquals('Php-Unit', $request->getServerBag()->get('HTTP_USER_AGENT'));
     $this->assertEquals('https', $request->getSchemaHost()->getSchema());
     $this->assertTrue($request->getHeaderBag()->has('host'));
     $this->assertTrue($request->getSchemaHost()->isSecure());
     $this->assertSame(8000, $request->getSchemaHost()->getPort());
     $this->assertEquals('localhost', $request->getSchemaHost()->getHost());
     $this->assertEquals('localhost:8000', $request->getSchemaHost()->getHttpHost());
     $this->assertTrue($request->isMethod('GET'));
     $request->setMethod('POST');
     $this->assertTrue($request->isMethod('POST'));
     $this->assertEquals('/view/page', $request->getUri()->getPathInfo());
     $this->assertCount(3, $request->getQueryBag());
     $this->assertEquals('iqbal', $request->get('username'));
     $this->assertEquals('Maulana', $request->get('lastName'));
     $this->assertEquals('https://localhost:8000/index.php', $request->getUrl()->getBaseUrl());
     $this->assertEquals('https://localhost:8000/index.php/home/landing', $request->getUrl()->getUrlForPath('home/landing'));
     $this->assertEquals('/index.php/demo/uri', $request->getUri()->getUriForPath('demo/uri'));
     $this->assertEquals('https://localhost:8000/index.php/view/page?firstName=Iqbal&lastName=Maulana&username=iqbal', $request->getUrl()->getFullUrl());
     $this->assertSame(2, count($request->getLanguages()));
     $this->assertEquals('en-US', $request->getLanguages()[0]);
     $this->assertSame(3, count($request->getCharsets()));
     $this->assertEquals('utf-8', $request->getCharsets()[1]);
     $this->assertNull($request->getParameterBag()->get('lastName'));
     $this->assertInstanceOf('\\Borobudur\\Http\\Session', $request->getSession());
     $this->assertInstanceOf('\\Borobudur\\Http\\UploadFileBag', $request->getFileBag());
     $this->assertContains('test', $request->getCookieBag()->values());
     $this->assertFalse($request->isXmlHttpRequest());
     $this->assertFalse($request->isReadOnly());
     $this->assertEmpty($request->getContent());
     $request->setContent('test content');
     $this->assertSame('test content', $request->getContent());
 }
 public function testLogoutOnLoginController()
 {
     $request = Request::create('/logout', Request::HTTP_METHOD_GET);
     $request->getCookieBag()->set('username', 'iqbal');
     $kernel = $this->buildKernel($this->getRouteCollection(), $request);
     $kernel->boot();
     $this->assertEquals('Logout', $this->responseEvent->getResponse()->getContent());
 }
Exemplo n.º 5
0
 public function testErrorHandling()
 {
     $kernel = $this->buildKernel(Request::create('/'), new RouteCollection());
     $kernel->addListenerOnce(KernelEvents::EXCEPTION, array($this, 'onRequestException'));
     $kernel->boot();
     $event = $this->responseEvent;
     $this->assertEquals('No route found for "GET /".', $event->getException()->getMessage());
     $this->assertSame(404, $event->getException()->getCode());
 }
 public function testControllerWithArguments()
 {
     $collection = new RouteCollection();
     $collection->add('detail', (new Route('/detail/{id}/{slug}'))->setRequirement('id', '\\d+')->setRequirement('slug', '[a-z\\-]+')->handleWith('app.controller.default:detail'));
     $request = Request::create('/detail/5/hello-world', Request::HTTP_METHOD_POST);
     $kernel = $this->buildKernel($request, $collection);
     $kernel->boot();
     $this->assertSame('POST: hello-world-5', $this->responseEvent->getResponse()->getContent());
 }
 /**
  * {@inheritdoc}
  */
 public function send()
 {
     $data = array_merge(array('success' => $this->statusCode >= 200 && $this->statusCode <= 300, 'data' => $this->normalize($this->data)), $this->extra);
     switch (strtolower($this->request->get('format'))) {
         case 'debug':
             $this->setContent(sprintf('<pre>%s</pre>', print_r($data, true)));
             return parent::send();
             break;
         case 'rjson':
             $response = new RJsonResponse($data, $this->statusCode, $this->headers->all());
             break;
         default:
             $response = new JsonResponse($data, $this->statusCode, $this->headers->all());
     }
     return $response->send();
 }
Exemplo n.º 8
0
 /**
  * Fix content length header.
  *
  * @param Request $request
  */
 private function fixContentLength(Request $request)
 {
     if ($this->headers->has('Transfer-Encoding')) {
         $this->headers->remove('Content-Length');
     }
     if ($request->isMethod(Request::HTTP_METHOD_HEAD)) {
         $contentLengthHeader = $this->headers->first('Content-Length');
         $this->setContent(null);
         if ($length = $contentLengthHeader->getFieldValue()) {
             $this->headers->set(new ContentLengthHeader($length), true);
         }
     }
 }
Exemplo n.º 9
0
<?php

/*
 * This file is part of the Cqrs-Framework package.
 *
 * (c) Hexacodelabs <http://hexacodelabs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Borobudur\Http\Request;
require_once __DIR__ . '/../app/bootstrap.php';
require_once __DIR__ . '/../app/AppKernel.php';
$kernel = new AppKernel('prod');
$kernel->listen(Request::createFromServer());
$kernel->boot();
 public function detailAction($id, Request $request, $slug)
 {
     return new Response(sprintf('%s: %s-%d', $request->getMethod(), $slug, $id));
 }
Exemplo n.º 11
0
 /**
  * Reschedule movie.
  *
  * @param string  $id
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function rescheduleAction($id, Request $request)
 {
     $command = new RescheduleMovieCommand(MovieId::fromString($id), new DateTime($request->get('schedule')));
     $response = $this->invoke($command);
     return $this->response(!empty($response) ? $response[0][0] : null);
 }