Exemplo n.º 1
0
 public function match(Request $request)
 {
     if ($request->getPath() === '/a') {
         return RouteMatch::forFunction(function () {
             return (new Response())->setBody(new MessageBodyString('Hello'));
         });
     }
     if ($request->getPath() === '/b') {
         return RouteMatch::forFunction(function () {
             return (new Response())->setBody(new MessageBodyString('World'));
         });
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function match(Request $request)
 {
     $path = $request->getPath();
     foreach ($this->prefixes as $prefix) {
         if (strpos($path, $prefix) === 0) {
             return $this->route->match($request);
         }
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function match(Request $request)
 {
     $path = $request->getPath();
     if ($path == '') {
         return null;
     }
     if ($path[0] != '/') {
         return null;
     }
     $lastSlashPos = strrpos($path, '/');
     $prefix = substr($path, 0, $lastSlashPos + 1);
     $action = substr($path, $lastSlashPos + 1);
     if (!isset($this->routes[$prefix])) {
         return null;
     }
     $class = $this->routes[$prefix];
     if ($action == 'index') {
         return null;
     } elseif ($action == '') {
         $action = 'index';
     }
     $method = $this->capitalize($action) . 'Action';
     return RouteMatch::forMethod($class, $method);
 }
Exemplo n.º 4
0
 /**
  * Creates a CookieOrigin from a Request instance.
  *
  * @param Request $request
  *
  * @return CookieOrigin
  */
 public static function createFromRequest(Request $request)
 {
     return new self($request->getHost(), $request->getPath(), $request->isSecure());
 }
Exemplo n.º 5
0
 public function testGetSetPath()
 {
     $request = new Request();
     $request->setRequestUri('/user/profile?user=123');
     $this->assertSame('/user/profile', $request->getPath());
     $this->assertSame($request, $request->setPath('/user/edit'));
     $this->assertSame('/user/edit', $request->getPath());
     $this->assertSame('/user/edit?user=123', $request->getRequestUri());
 }