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);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function findActionByRouteName($routeName)
 {
     $resourceDefinition = $this->compilerCache->findResourceDefinition($routeName);
     if ($resourceDefinition !== null) {
         return $resourceDefinition->findActionByRouteName($routeName);
     }
     return null;
 }
 public function load($resource, $type = null)
 {
     foreach ($this->compilerCache->getResourceDefinitions() as $resourceDefinition) {
         foreach ($resourceDefinition->getActions() as $action) {
             $this->processAction($action);
         }
     }
     return $this->routes;
 }
 protected function exportModel(ContextInterface $context = null, ResourceInterface $resource, CompiledTransformMappingInterface $transformMapping, $instance, $allFields = false)
 {
     $item = [];
     $resourceDefinition = $this->compilerCache->findResourceDefinitionForModelClass(get_class($instance));
     $href = $this->makeUrlForInstance($resourceDefinition, $instance);
     $fields = $transformMapping->getFields(GetterField::OPERATION);
     foreach ($fields as $def) {
         if ($allFields === true || $context->wantsField($def->getName()) === true) {
             $callable = $def->getCallback();
             if ($callable !== null) {
                 if (is_array($callable) === true) {
                     $val = call_user_func($callable, $instance);
                 } else {
                     $val = $this->getFieldValue($instance, $callable);
                 }
                 $item[$def->getName()] = $this->exportValue($def, $val);
             }
         }
     }
     $response = $this->factory->createInstanceResponse($resourceDefinition, $resource, $context, $href, $item, $instance);
     $this->exportEmbeds($transformMapping, $context, $response, $instance);
     return $response;
 }
 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);
     }
 }