Пример #1
0
 /**
  * @param ResourceTransformer $transformer
  * @param $entity
  * @param Field $field
  * @param Context $context
  * @return array
  * @throws InvalidPropertyException
  */
 protected function resolvePath(ResourceTransformer $transformer, $entity, Field $field, Context $context)
 {
     $path = $this->splitPathParameters($field->getName());
     $name = array_pop($path);
     // If the water is deep enough, we need to first fetch the corresponding entity.
     // We will NOT create the entity if it doesn't exist.
     // Relationships support this functionality. Regular setters do not.
     if (count($path) > 0) {
         $entity = $this->resolveChildPath($transformer, $entity, $path, $field, $context);
     }
     list($name, $parameters) = $this->getPropertyNameAndParameters($transformer, $name, $context, $field, $entity);
     return [$entity, $name, $parameters];
 }
Пример #2
0
 /**
  * @param ResourceTransformer $transformer
  * @param mixed $entity
  * @param Field $field
  * @param Context $context
  * @return mixed
  * @throws InvalidPropertyException
  */
 public function resolveProperty(ResourceTransformer $transformer, $entity, Field $field, Context $context)
 {
     $path = $this->splitPathParameters($field->getName());
     return $this->resolveChildPath($transformer, $entity, $path, $field, $context);
 }
Пример #3
0
 /**
  * @param ResourceTransformer $transformer
  * @param array $parameters
  * @param Context $context
  * @param Field $field
  * @param null $entity
  * @return \mixed[]
  * @throws VariableNotFoundInContext
  */
 protected function parseParameters(ResourceTransformer $transformer, array $parameters, Context $context, Field $field = null, $entity = null)
 {
     $out = [];
     foreach ($parameters as $v) {
         if ($parameter = $this->getParameter($v)) {
             $value = $this->parseParameter($transformer, $parameter, $context, $entity);
             if ($value !== null) {
                 $out[] = $value;
             } else {
                 if ($field) {
                     throw new VariableNotFoundInContext('Field ' . $field->getName() . ' requires a parameter $' . $parameter . ' to be set in the context, but no such parameter was defined.');
                 } else {
                     throw new VariableNotFoundInContext('A parameter $' . $parameter . ' is required to be set in the context, but no such parameter was defined.');
                 }
             }
         } else {
             $out[] = $v;
         }
     }
     return $out;
 }