コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function addDeleteAction($id = 'delete', $type = Parameter::TYPE_UUID)
 {
     $modelClass = $this->getDefaultTransformMapping()->getModelClass();
     $emptyTransformMapping = $this->factory->createTransformMapping($modelClass);
     $action = $this->addAction(ActionDefinition::TYPE_DELETE, $id);
     $action->addToken('id', $type);
     $action->setTransformMapping($emptyTransformMapping);
     return $action;
 }
コード例 #2
0
 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;
 }