Exemple #1
0
 /**
  * @inheritdoc
  */
 public function match(Request $request, $pathOffset = null, array $options = array())
 {
     $routeMatch = parent::match($request, $pathOffset, $options);
     if (!$routeMatch instanceof RouteMatch) {
         return $routeMatch;
     }
     $params = $routeMatch->getParams();
     foreach ($params as $key => $value) {
         if (in_array($key, $this->_hashidsParams)) {
             $routeMatch->setParam($key, $this->_decode($value));
         }
     }
     return $routeMatch;
 }
Exemple #2
0
 /**
  * @dataProvider routeProvider
  * @param        Segment $route
  * @param        string  $path
  * @param        integer $offset
  * @param        array   $params
  */
 public function testMatching(Segment $route, $path, $offset, array $params = null)
 {
     $request = new Request();
     $request->setUri('http://example.com' . $path);
     $match = $route->match($request, $offset);
     if ($params === null) {
         $this->assertNull($match);
     } else {
         $this->assertInstanceOf('Zend\\Mvc\\Router\\Http\\RouteMatch', $match);
         if ($offset === null) {
             $this->assertEquals(strlen($path), $match->getLength());
         }
         foreach ($params as $key => $value) {
             $this->assertEquals($value, $match->getParam($key));
         }
     }
 }
 public function match(Request $request, $pathOffset = null, array $options = array())
 {
     $routeMatch = parent::match($request, $pathOffset, $options);
     if ($routeMatch instanceof RouteMatch) {
         $entityName = $routeMatch->getParam('entity');
         $params = $routeMatch->getParams();
         unset($params['entity'], $params['controller'], $params['action'], $params['headTitle'], $params['pageTitle'], $params['pageDescription']);
         /** @var EntityManager $objectManager */
         $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         $objectRepository = $objectManager->getRepository($entityName);
         $entity = $objectRepository->findOneBy($params);
         if (!$entity) {
             return null;
         }
         $routeMatch->setParam('entity', $entity);
     }
     return $routeMatch;
 }
Exemple #4
0
 public function testEncodedDecode()
 {
     // every character
     $in = '%61%62%63%64%65%66%67%68%69%6a%6b%6c%6d%6e%6f%70%71%72%73%74%75%76%77%78%79%7a%41%42%43%44%45%46%47%48%49%4a%4b%4c%4d%4e%4f%50%51%52%53%54%55%56%57%58%59%5a%30%31%32%33%34%35%36%37%38%39%60%2d%3d%5b%5d%5c%3b%27%2c%2e%2f%7e%21%40%23%24%25%5e%26%2a%28%29%5f%2b%7b%7d%7c%3a%22%3c%3e%3f';
     $out = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`-=[]\\;\',./~!@#$%^&*()_+{}|:"<>?';
     $request = new Request();
     $request->setUri('http://example.com/' . $in);
     $route = new Segment('/:foo');
     $match = $route->match($request);
     $this->assertSame($out, $match->getParam('foo'));
 }
 /**
  * Match (for REST)
  *
  * Add a 'restAction' param to the RouteMatch object to indicate the action that will be taken by the
  * AbstractRestfulController
  *
  * @param Request $request
  * @param null $pathOffset
  * @param array $options
  * @return null|\Zend\Mvc\Router\Http\RouteMatch
  */
 public function match(Request $request, $pathOffset = null, array $options = array())
 {
     $routeMatch = parent::match($request, $pathOffset, $options);
     if ($routeMatch) {
         // If the route matched for this router then...
         $action = $routeMatch->getParam('action', false);
         if (!$action) {
             // Ignore actions that were already set, those get mapped to custom http methods.
             // RESTful methods
             $method = strtolower($request->getMethod());
             switch ($method) {
                 // DELETE
                 case 'delete':
                     $id = $this->getIdentifier($routeMatch, $request);
                     if ($id !== false) {
                         $action = 'delete';
                         break;
                     }
                     $action = 'deleteList';
                     break;
                     // GET
                 // GET
                 case 'get':
                     $id = $this->getIdentifier($routeMatch, $request);
                     if ($id !== false) {
                         $action = 'get';
                         break;
                     }
                     $action = 'getList';
                     break;
                     // HEAD
                 // HEAD
                 case 'head':
                     $action = 'head';
                     break;
                     // OPTIONS
                 // OPTIONS
                 case 'options':
                     $action = 'options';
                     break;
                     // PATCH
                 // PATCH
                 case 'patch':
                     $id = $this->getIdentifier($routeMatch, $request);
                     if ($id !== false) {
                         $action = 'patch';
                         break;
                     }
                     $action = 'patchList';
                     break;
                     // POST
                 // POST
                 case 'post':
                     $action = 'create';
                     break;
                     // PUT
                 // PUT
                 case 'put':
                     $id = $this->getIdentifier($routeMatch, $request);
                     if ($id !== false) {
                         $action = 'update';
                         break;
                     }
                     $action = 'replaceList';
                     break;
                     // All others...
                 // All others...
                 default:
                     $action = null;
             }
         }
         $routeMatch->setParam('restAction', $action);
     }
     return $routeMatch;
 }
Exemple #6
0
 public function testNoMatchWithoutUriMethod()
 {
     $route = new Segment('/foo');
     $request = new BaseRequest();
     $this->assertNull($route->match($request));
 }
Exemple #7
0
 public function testEncodeCache()
 {
     $params1 = array('p1' => 6.123, 'p2' => 7);
     $uri1 = 'example.com/' . join('/', $params1);
     $params2 = array('p1' => 6, 'p2' => 'test');
     $uri2 = 'example.com/' . join('/', $params2);
     $route = new Segment('example.com/:p1/:p2');
     $request = new Request();
     $request->setUri($uri1);
     $route->match($request);
     $this->assertSame($uri1, $route->assemble($params1));
     $request->setUri($uri2);
     $route->match($request);
     $this->assertSame($uri2, $route->assemble($params2));
 }
 /**
  * @param Request $request
  * @param null    $pathOffset
  * @param array   $options
  * @return null|RouteMatch
  */
 public function match(Request $request, $pathOffset = null, array $options = array())
 {
     $routeMatch = parent::match($request, $pathOffset, $options);
     if (!$routeMatch) {
         return null;
     }
     $subject = $routeMatch->getParam($this->identifier);
     try {
         $this->getSubjectManager()->findSubjectByString($subject, $this->getInstanceManager()->getInstanceFromRequest());
         return $routeMatch;
     } catch (\Exception $e) {
         return null;
     }
 }