예제 #1
0
파일: RouteTest.php 프로젝트: arius86/core
 public function testShouldMapConstructorParametersToClassProperties()
 {
     $routeArray = ['route' => '/url', 'paths' => array('module' => 'module', 'controller' => 'controller', 'action' => 'action', 'auth' => array('auth', 'authAdmin')), 'type' => 'static', 'params' => array('param_1' => 'value_1', 'param_2' => 'value_2', 'param_3' => 'value_3')];
     $route = new Route('test', $routeArray);
     $this->assertEquals($route->getName(), 'test');
     $this->assertArrayHasKey('module', $route->getPaths());
     $this->assertArrayHasKey('controller', $route->getPaths());
     $this->assertArrayHasKey('action', $route->getPaths());
     $this->assertArrayHasKey('auth', $route->getPaths());
     $this->assertEquals('value_1', $route->getParam('param_1'));
     $this->assertEquals('value_2', $route->getParam('param_2'));
     $this->assertEquals('value_3', $route->getParam('param_3'));
     $this->assertSame(json_encode(['auth', 'authAdmin']), $route->getPaths()['auth']);
     $this->assertEquals('/url', $route->getRoute());
     $this->assertInternalType('array', $route->getParams());
     $this->assertInternalType('string', $route->getRoute());
     $this->assertInternalType('array', $route->getPaths());
     $this->assertInternalType('string', $route->getName());
 }
예제 #2
0
파일: RestRoute.php 프로젝트: arius86/core
 /**
  * {@inheritdoc}
  */
 public function add(RouterInterface $router, Route $route)
 {
     //resolves actions with http methods
     $actions = $route->getParam('actions');
     if (empty($actions)) {
         $actions = array('/' => array('index' => Method::GET));
     }
     //add routes with http method
     //for each action new route is adding with specified HTTP Method.
     foreach ($actions as $actionRoute => $actionMethods) {
         if ($actionRoute == '/') {
             $actionRoute = '';
         }
         foreach ($actionMethods as $action => $method) {
             $paths = $route->getPaths();
             $paths['action'] = $action;
             $newRoute = $router->add($route->getRoute() . $actionRoute, $paths)->via($method);
             $newRoute->setName($route->getName() . $actionRoute . '/' . $action);
             $newRoute->setHostName($route->getParam('hostname'));
         }
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function add(RouterInterface $router, Route $route)
 {
     $router->add($route->getRoute(), $route->getPaths())->setName($route->getName())->setHostName($route->getParam('hostname'));
 }