Esempio n. 1
0
 public function testResourceRoute()
 {
     /* @var Dispatcher $dispatcher */
     $dispatcher = $this->getMock(Dispatcher::class);
     $router = new Router($dispatcher, null);
     $routeHelper = new RouteHelper($router);
     $routeHelper->resource('test', 'TestController')->get('get_test', 'get_test')->post('post_test', 'post_test')->put('put_test', 'put_test')->patch('patch_test', 'patch_test')->delete('delete_test', 'delete_test')->rawGet('rawget', 'rawget')->rawPost('rawpost', 'rawpost')->rawPut('rawput', 'rawput')->rawPatch('rawpatch', 'rawpatch')->rawDelete('rawdelete', 'rawdelete')->done();
     $routes = $router->getRoutes();
     $this->assertRoute($routes, 'test', 'GET', 'TestController@index');
     $this->assertRoute($routes, 'test?' . RouteHelper::PAGINATION_URI, 'GET', 'TestController@index');
     $this->assertRoute($routes, 'test', 'POST', 'TestController@store');
     $this->assertRoute($routes, 'test/{test}', 'GET', 'TestController@show');
     $this->assertRoute($routes, 'test/{test}', 'PUT', 'TestController@update');
     $this->assertRoute($routes, 'test/{test}', 'PATCH', 'TestController@update');
     $this->assertRoute($routes, 'test/{test}', 'DELETE', 'TestController@destroy');
     $this->assertRoute($routes, 'test/{test}/get_test', 'GET', 'TestController@get_test');
     $this->assertRoute($routes, 'test/{test}/post_test', 'POST', 'TestController@post_test');
     $this->assertRoute($routes, 'test/{test}/put_test', 'PUT', 'TestController@put_test');
     $this->assertRoute($routes, 'test/{test}/patch_test', 'PATCH', 'TestController@patch_test');
     $this->assertRoute($routes, 'test/{test}/delete_test', 'DELETE', 'TestController@delete_test');
     $this->assertRoute($routes, 'test/rawget', 'GET', 'TestController@rawget');
     $this->assertRoute($routes, 'test/rawpost', 'POST', 'TestController@rawpost');
     $this->assertRoute($routes, 'test/rawput', 'PUT', 'TestController@rawput');
     $this->assertRoute($routes, 'test/rawpatch', 'PATCH', 'TestController@rawpatch');
     $this->assertRoute($routes, 'test/rawdelete', 'DELETE', 'TestController@rawdelete');
 }
Esempio n. 2
0
 /**
  * @param Router|null $router
  * @return RouteHelper
  */
 protected function createRouteHelper(Router $router = null)
 {
     if ($router === null) {
         $router = $this->createRouter();
     }
     return RouteHelper::make($router);
 }
 /**
  * @param HalApiLink $link
  */
 private function addSubordinateRoutes(HalApiLink $link)
 {
     $subordinateRoutes = $this->routeHelper->subordinates($link->getRoute());
     foreach ($subordinateRoutes as $subRoute) {
         /** @var HalApiController $class */
         list($class, $method) = explode('@', $subRoute->getActionName());
         $this->link($class::getRelation($method), $this->linkFactory->create($subRoute, $link->getParameters()));
     }
 }
Esempio n. 4
0
 /**
  * @param HalApiControllerParameters $parameters
  */
 public function __construct(HalApiControllerParameters $parameters)
 {
     $this->app = $parameters->getApplication();
     $this->linkFactory = $parameters->getLinkFactory();
     $this->representationFactory = $parameters->getRepresentationFactory();
     $this->routeHelper = $parameters->getRouteHelper();
     $this->responseFactory = $parameters->getResponseFactory();
     $this->request = $parameters->getRequest();
     $this->parameters = new SafeIndexArray($this->request->input());
     $this->body = new SafeIndexArray($this->request->json()->all());
     /** @var Route $route */
     $route = $this->request->route();
     if ($route) {
         $routeParameters = $route->parameters();
         $this->self = $this->linkFactory->create($route, $routeParameters);
         $this->parent = $this->linkFactory->create($this->routeHelper->parent($route), $routeParameters);
     }
 }