private function processResource($class) { $definition = $class::createResourceDefinition($this->factory); $compiledDefinition = $this->compiler->compile($definition); foreach ($compiledDefinition->getActions() as $action) { $this->compilerCache->registerResourceDefinition($action->getRouteName(), $compiledDefinition); } }
private function addRoutesFromResourceDefinition(CompilerInterface $compiler, CompilerCacheInterface $cache, Router $router, ResourceDefinition $definition, $resourceClass) { $compiledDefinition = $compiler->compile($definition); foreach ($compiledDefinition->getActions() as $action) { $href = $action->getEndpointUrl(false); $routeName = $action->getRouteName(); $controller = sprintf('%s@preHandle', $resourceClass); $route = $router->{$action->getHttpMethod()}($href, ['as' => $routeName, 'uses' => $controller, '_rested' => ['action' => $action->getType(), 'controller' => $action->getControllerName(), 'route_name' => $routeName]]); // add constraints and validators to the cache foreach ($action->getTokens() as $token) { if ($token->acceptAnyValue() === false) { $route->where($token->getName(), Parameter::getValidatorPattern($token->getDataType())); } } $cache->registerResourceDefinition($routeName, $compiledDefinition); } }