Пример #1
0
 public function testMapRoute()
 {
     $restRoute = new Route('/route/one/{id}', array('_controller' => 'anything'), array('id' => '[0-9]+'), array(), '', array(), array('PUT', 'DELETE'));
     $optionsRoute = $this->mapper->mapRoute($restRoute);
     self::assertEquals(array('OPTIONS'), $optionsRoute->getMethods());
     self::assertEquals($restRoute->getRequirement('id'), $optionsRoute->getRequirement('id'));
     self::assertEquals('PUT,DELETE', $optionsRoute->getDefault('allowedMethods'));
     self::assertEquals('_ezpublish_rest.controller.options:getRouteOptions', $optionsRoute->getDefault('_controller'));
 }
 /**
  * Iterates over $restRouteCollection, and returns the corresponding RouteCollection of OPTIONS REST routes
  *
  * @param RouteCollection $restRouteCollection
  * @return RouteCollection
  */
 public function mapCollection(RouteCollection $restRouteCollection)
 {
     $optionsRouteCollection = new RouteCollection();
     foreach ($restRouteCollection->all() as $restRoute) {
         $optionsRouteName = $this->mapper->getOptionsRouteName($restRoute);
         $optionsRoute = $optionsRouteCollection->get($optionsRouteName);
         if ($optionsRoute === null) {
             $optionsRoute = $this->mapper->mapRoute($restRoute);
         } else {
             $optionsRoute = $this->mapper->mergeMethodsDefault($optionsRoute, $restRoute);
         }
         $optionsRouteCollection->add($optionsRouteName, $optionsRoute);
     }
     return $optionsRouteCollection;
 }