@param object $entity
@param string $field
@param string $getter

@return static
496979
public static function missingGetter($entity, $field, $getter)
    {
        $source = [
            'entity' => ClassUtils::getClass($entity),
            'getter' => $getter
        ];

        if ($entity instanceof JsonApiResource) {
            $source['pointer'] = $entity->getResourceKey().'.'.$field;
        }

        return static::createUnprocessable()
            ->error('missing-getter', $source, 'Missing field getter.');
    }
341983
private function callGetterMethod($object, $getter)
    {
        $methodName = $getter;
        if (strpos($getter, '(') !== false) {
            $methodName = substr($getter, 0, strpos($getter, '('));
        }

        if (!method_exists($object, $methodName)) {
            throw new SolrMappingException(sprintf('No method "%s()" found in class "%s"', $methodName, get_class($object)));
        }

        $method = new \ReflectionMethod($object, $methodName);
        // getter with arguments
        if (strpos($getter, ')') !== false) {
            $getterArguments = explode(',', substr($getter, strpos($getter, '(') + 1, -1));
            $getterArguments = array_map(function ($parameter) {
                return trim(preg_replace('#[\'"]#', '', $parameter));
            }, $getterArguments);

            return $method->invokeArgs($object, $getterArguments);
        }

        return $method->invoke($object);
    }
609572
public function setEntity($entity, $prepare = true)
	{
		if($entity instanceof EntityInterface)
		{
			$this->entity = $entity;
		}
		elseif(is_resource($entity) || $entity instanceof StreamInterface)
		{
			$this->entity = new StreamEntity($entity);
		}
		elseif((is_array($entity) || is_object($entity)) && is_callable($entity))
		{
			$this->entity = new CallbackEntity($entity);
		}
		else
		{
			$this->entity = new StringEntity($entity);
		}
		
		if($prepare)
		{
			$this->entity->prepare($this);
		}
		
		return $this;
	}
715101
public function solveFetch(Entity &$entity)
    {
        // We can use the static ::get method on the entity
        $targetEntity = $this->relation->targetEntity;

        return call_user_func($targetEntity . '::get', $entity->{$this->relation->join->column});
    }
1237064
protected function getFieldContent($entity, $fieldName, array $fieldAttr, array $mappings)
    {
        if (isset($fieldAttr['widget'])) {
            $widgetAlias = $fieldAttr['widget']['alias'];

            return $this->widgetPool->getWidget($widgetAlias)->getContent(
                $entity,
                $fieldAttr['widget']['options'],
                $fieldName
            );
        }
        if (isset($fieldAttr['service'])) {
            $method = $fieldAttr['service']['method'];

            return $this->container->get($fieldAttr['service']['id'])->$method($entity, $fieldAttr['service']['options']);
        }
        if (isset($fieldAttr['callback'])) {
            $class = $fieldAttr['callback']['class'];
            $method = $fieldAttr['callback']['method'];

            return $class::$method($entity, $fieldAttr['callback']['options']);
        }

        $content = $this->propertyAccessor->getValue($entity, $fieldName);

        return isset($mappings[$fieldName]['type'])
            ? $this->stringifier->stringify($content, $mappings[$fieldName]['type'])
            : $content;
    }
1017719
protected function fromArrayRelationCollection($v, $p, $pn, $getter, $setter,
                                                $association, $policy,
                                                Reader $ar,
                                                PolicyResolver $pr,
                                                EntityManagerInterface $em,
                                                \ReflectionClass $refClass,
                                                $idField, $class, $subPolicy) {
        // find target id field name
        $jt = $ar->getPropertyAnnotation($p, 'Doctrine\ORM\Mapping\JoinTable');
        if($jt) {
            if(count($jt->inverseJoinColumns) > 1) { throw new Exceptions\FromArrayException('Composite key relations not supported yet. Field "'.$pn.'".'); }
            $ijc = reset($jt->inverseJoinColumns); // TODO: composite keys support
            if($ijc) {
                $idField = $ijc->referencedColumnName;
            }
        }
        
        $idGetter = 'get'.ucfirst($idField);
        $collection = $this->$getter();
        $newCollection = new \Doctrine\Common\Collections\ArrayCollection();
        $existent = [];
        
        if(! $collection instanceof \Doctrine\Common\Collections\Collection) {
            throw new Exceptions\FromArrayException('Method "'.$getter.'" of the field "'.$pn.'" doesn\'t return Collection');
        }
        
        // collect internal existent and index by id
        foreach($collection as $e) { 
            $existent[$e->$idGetter()] = $e;
        }
        
        // handle input entities
        foreach($v['collection'] as $e) {
            // new entity
            if(empty($e[$idField])) { 
                if($policy instanceof Policy\Interfaces\DenyNewFrom) { continue; }
                $subEntity = new $class();
                $subEntity->fromArray($e, $em, $subPolicy, $ar, $pr);
                $newCollection->add($subEntity);
                
            } else { // existent entity
                $id = $e[$idField];
                
                // internal existent
                if(isset($existent[$id])) {
                    // UPDATING internal
                    if(!($policy instanceof Policy\Interfaces\DenyUpdateFrom) || $policy->allowExistent) {
                        $existent[$id]->fromArray($e, $em, $subPolicy, $ar, $pr);
                    }
                    $newCollection->add($existent[$id]);
                    unset($existent[$id]);
                    
                // RETRIEVING external
                } else if(!($policy instanceof Policy\Interfaces\DenyUpdateFrom) || $policy->allowExternal) { 
                    $external = $em->getReference($class, $id);
                    if($external) {
                        // UPDATING internal
                        if(!($policy instanceof Policy\Interfaces\DenyUpdateFrom) || $policy->allowExistent) {
                            $external->fromArray($e, $em, $subPolicy, $ar, $pr);
                        }
                        $newCollection->add($external);
                    }
                }
            }
        }
        
        // keep the rest for DenyUnset
        if($policy instanceof Policy\Interfaces\DenyUnsetFrom) {
            foreach($existent as $e) {
                $newCollection->add($e);
            }
        }
        $this->$setter($newCollection);
    }
1022968
public function setGetter($getter)
    {
        if (!is_bool($getter)) {
            throw new \InvalidArgumentException('The attribute getter on the class Attribute has to be boolean (' . gettype($getter) . ('object' === gettype($getter) ? ' ' . get_class($getter) : '') . ' given).');
        }

        $this->getter = $getter;

        return $this;
    }
942668
protected function generateAddMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $fieldType  = $field->getType();
        $collClass  = $this->getCollectionClassName($field);
        $methodName = 'add' . $this->getClassifiedName($field);
        $typeHint   = ($fieldType !== Type::TYPE_BYTES())
            ? $this->getDoctype($field)
            : null;

        $lines[] = 'if ($this->' . $fieldName . ' === null) {';
        $lines[] = '    $this->' . $fieldName . ' = new ' . $collClass . '();';
        $lines[] = '}';
        $lines[] = null;
        $lines[] = ($fieldType !== Type::TYPE_BYTES())
            ? '$this->' . $fieldName . '->add($value);'
            : '$this->' . $fieldName . '->add(\Protobuf\Stream::wrap($value));';

        return MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => implode(PHP_EOL, $lines),
            'parameters' => [
                [
                    'name'   => 'value',
                    'type'   => $typeHint
                ]
            ],
            'docblock'   => [
                'shortDescription' => "Add a new element to '$fieldName'",
                'tags'             => [
                    [
                        'name'        => 'param',
                        'description' => $this->getDoctype($field) . ' $value'
                    ]
                ]
            ]
        ]);
    }
210048
public function addField(Field $field)
    {
        $tmp               = $this->fields->getValue($this->entity);
        $tmp[$field->name] = $field;
        $this->fields->setValue($this->entity, $tmp);

        if ($field->role == 'id') {
            $key = new \ReflectionProperty(Entity::class, 'key');
            $key->setAccessible(true);
            $key->setValue($this->entity, $field->name);
        }
    }
542165
private function mapObjectField(Field $field)
    {
        $value = $field->getValue();
        $getter = $field->getGetterName();
        if (empty($getter)) {
            throw new SolrMappingException(sprintf('Please configure a getter for property "%s" in class "%s"', $field->name, get_class($value)));
        }
        
        $getterReturnValue = $this->callGetterMethod($value, $getter);

        if (is_object($getterReturnValue)) {
            throw new SolrMappingException(sprintf('The configured getter "%s" in "%s" must return a string or array, got object', $getter, get_class($value)));
        }

        return $getterReturnValue;
    }
604076
protected function manageFieldIndex($entity, $field)
    {
        if ($entity == null || $field == null || $this->has($this->route_name.'_'.$field.'_datatable') == false) {
            throw new \Exception('All the parameters are not correctly set');
        }
        $postDatatable = $this->get($this->route_name.'_'.$field.'_datatable');
        $postDatatable->buildDatatable(['entity' => $entity]);

        return $this->render($this->getIndexTemplate(strtolower($field)), array(
            'datatable' => $postDatatable,
            'entity' => $entity,
        ));
    }
347708
public function generateBody(Entity $entity, FieldDescriptorProto $field)
    {
        $name      = $field->getName();
        $tag       = $field->getNumber();
        $extEntity = $this->getEntity($field->getExtendee());
        $extendee  = $extEntity->getNamespacedName();

        $nameQuoted     = var_export($name, true);
        $extendeeQuoted = var_export($extendee, true);

        $sizeCallback  = $this->generateSizeCallback($entity, $field);
        $readCallback  = $this->generateReadCallback($entity, $field);
        $writeCallback = $this->generateWriteCallback($entity, $field);
        $callbacks     = array_merge($readCallback, [null], $writeCallback, [null], $sizeCallback);
        $arguments     = [
            $extendeeQuoted,
            $nameQuoted,
            $tag,
            '$readCallback',
            '$writeCallback',
            '$sizeCallback',
            '__METHOD__'
        ];

        $body[] = 'if (self::$' . $name . ' !== null) {';
        $body[] = '    return self::$' . $name . ';';
        $body[] = '}';
        $body[] = null;
        $body   = array_merge($body, $callbacks);
        $body[] = null;
        $body[] = 'return self::$' . $name . ' = new \Protobuf\Extension\ExtensionField(' . implode(', ', $arguments) . ');';

        return $body;
    }
1319267
public function setPropertyValue(&$entity, $field, $value)
    {
        $this->assertEntity($entity);

        if (is_array($entity) || $entity instanceof \ArrayAccess) {
            $entity[$field] = $value;

            return;
        }

        $ref = $this->getReflection($entity);
        if (!$ref->hasProperty($field)) {
            $entity->{$field} = $value;

            return;
        }

        $this->getProperty($ref, $field)->setValue($entity, $value);
    }
859532
public function addField($fieldName, $getMethod, $setMethod, ByConfigBuilder $include = null, $formatter = null)
    {
        if (method_exists($this->getEntityPrototype(), $getMethod) === false) {
            throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $getMethod, $this->entityClassName), 2);
        }

        if (method_exists($this->getEntityPrototype(), $setMethod) === false) {
            throw new Exception\ConfigFailed(sprintf($this->exceptions[2], $setMethod, $this->entityClassName), 2);
        }

        $this->mapping[$fieldName] = array(
            'getter'    => $getMethod,
            'setter'    => $setMethod,
            'include'   => $include,
            'formatter' => $formatter,
        );

        return $this;
    }
1253727
public static function setValue($entity, $field, $value)
    {
        $entity->{'set' . ucfirst(Str::camel($field))}($value);
    }
625971
private function createGetter(Entity $entity, $property, $annotation)
    {
        if ($annotation->getter === null) {
            $getter = new PropertyGetter($entity, $property);
        } else {
            if ($annotation->getter === true) {
                $methodName = 'get' . ucfirst($property);
            } else {
                $methodName = $annotation->getter;
            }
            $getter = new MethodGetter($entity, $methodName);
        }

        return $getter;
    }
1032848
public function get($field)
    {
        if ($this->definition->getField($field, 'value') !== null) {
            return $this->definition->getField($field, 'value');
        }

        if (!array_key_exists($field, $this->entity)) {
            return null;
        }

        $type  = $this->definition->getType($field);
        $value = $this->toType($this->entity[$field], $type);
        return $value;
    }