/**
  * {@inheritdoc}
  */
 public static function create(CompiledResourceDefinitionInterface $resourceDefinition, ContextInterface $parentContext, $name)
 {
     $parentEmbeds = $parentContext->getEmbeds();
     $parentFields = $parentContext->getFields();
     $parentFilters = $parentContext->getFilters();
     $parameters = ['embed' => array_key_exists($name, $parentEmbeds) ? $parentEmbeds[$name] : [], 'fields' => array_key_exists($name, $parentFields) ? $parentFields[$name] : [], 'filters' => array_key_exists($name, $parentFilters) ? $parentFilters[$name] : [], 'limit' => RequestParser::DEFAULT_LIMIT, 'metadata' => true, 'offset' => RequestParser::DEFAULT_OFFSET];
     return new static($parameters, null, null, $resourceDefinition);
 }
 public function __construct(RestedServiceInterface $restedService, UrlGeneratorInterface $urlGenerator, ResourceInterface $resource, ContextInterface $context, $uri = null, array $data = [])
 {
     parent::__construct($uri, $data);
     $this->context = $context;
     $this->resource = $resource;
     $this->restedService = $restedService;
     $this->urlGenerator = $urlGenerator;
     if ($context->wantsMetadata() === false) {
         $uri = null;
     }
     $this->addLink('self', $uri);
 }
 protected function addActions(CompiledResourceDefinitionInterface $resourceDefinition, array $which, $instance = null)
 {
     if ($this->context->wantsMetadata() === false) {
         return;
     }
     $actions = $resourceDefinition->getActions();
     $links = [];
     $this->data['_actions'] = [];
     foreach ($actions as $action) {
         if ($action->getType() === ActionDefinition::TYPE_COLLECTION) {
             $this->addFiltersToLink('self', $action);
         }
         if (in_array($action->getType(), $which) === false || $action->isAffordanceAvailable($this->resource, $instance) === false) {
             continue;
         }
         $links = array_merge($links, $this->addAction($resourceDefinition, $action, $instance));
     }
     foreach ($links as $rel => $routeName) {
         $this->addRestedLink($rel, $routeName);
     }
 }
 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;
 }