Converts raw query results to node/relation entities.

@param mixed $value One query result.
@return Node|Relationship The entity.
505167
private function convertValue($value)
    {
        if ($value instanceof Node)
        {
            return $this->em->loadNode($value);
        }

        elseif ($value instanceof Relationship)
        {
            return $this->em->loadRelation($value);
        }

        else
        {
            return $value;
        }
    }
763264
public function convertValue($value)
    {
        if ($value === null || ($value === "" && $this->type !== self::TYPE_STRING)) {
            return;
        }

        if (self::isScalarType($this->type) || $this->type === self::TYPE_ARRAY) {
            // Scalar and array

            if ($this->type === self::TYPE_BOOLEAN && strtolower($value) === "false") {
                return false;
            }

            if (is_scalar($value) || $this->type === self::TYPE_ARRAY) {
                if (settype($value, $this->type)) {
                    return $value;
                }
            }
        } elseif ($this->type === self::TYPE_DATETIME
            || $this->type === self::TYPE_DATE
        ) {
            // DateTime

            if ($value instanceof \DateTime) {
                return $value;
            } elseif (is_array($value) && isset($value["date"])) {
                $date = $value["date"];
            } elseif (is_object($value) && isset($value->date)) {
                $date = $value->date;
            } else {
                $date = $value;
            }

            if (isset($date)) {
                try {
                    return new \DateTime($date);
                } catch (\Exception $e) {

                }
            }
        } elseif ($this->type === self::TYPE_COLLECTION
            && Validator::isTraversable($value)
        ) {
            // Collection

            return new Entity\Collection($this->typeOption, $value);
        } elseif ($this->type === self::TYPE_ENTITY
            && Validator::isTraversable($value)
        ) {
            // Entity

            return Entity\Reflection::load($this->typeOption)->createEntity($value);
        }

        throw new Exception\InvalidArgumentException(
            "Can not convert value on property '" . $this->name
            . "' automatically!",
            $value
        );
    }
576898
private function convertArrayToEntityValue(array $value)
    {
        $excludes = $this->pluck(Entity::EXCLUDE_FROM_INDEXES, $value, false) ?: [];

        $properties = [];
        foreach ($value as $key => $val) {
            $properties[$key] = $this->valueObject(
                $val,
                in_array($key, $excludes)
            );
        }

        if (!$properties) {
            $properties = (object) $properties;
        }

        return [
            'entityValue' => [
                'properties' => $properties
            ]
        ];
    }
1127362
protected function prepeareQuery($value)
    {
        $query = \Doctrine_Query::create($this->getConnection())
                ->select($this->getField())
                ->from($this->getTable())
                ->where(sprintf('%s = ?', $this->getField()), $value);

        foreach ($this->getExclude() as $exclude => $value) {
            $query->andWhere(sprintf('%s != ?', $exclude), $value);
        }

        foreach ($this->getInclude() as $include => $value) {
            $query->andWhere(sprintf('%s = ?', $include), $value);
        }

        return $query;
    }
1135924
public function transform($value)
    {
        if (null === $value) {
            return "";
        }

        if (false === $value instanceof NodeTranslation) {
            throw new TransformationFailedException("Value must be instance of NodeTranslation");
        }

        return $this->router->generate('_slug', [
            '_locale' => $value->getLang(),
            'url' => $value->getUrl(),
        ]);
    }
3971
public function setRelations($value)
    {
        if (is_array($value)) {
            $bag = new Bag();
            foreach ($value as $itemParameters) {
                $bag->add(new Relation($itemParameters));
            }
            $value = $bag;
        }
        return $this->setParameter('relations', $value);
    }
873259
protected function _findOneBy(string $key, $value): ?Entity
    {
        $result = $this->_findBy($key, $value);

        $entity = $result->first();

        return $entity === false ? null : $entity;
    }
127659
protected function prepareAnrEquivalentQuery($value)
    {
        return $this->orFilter(function (Builder $query) use ($value) {
            $locateBy = [
                $this->schema->name(),
                $this->schema->email(),
                $this->schema->userId(),
                $this->schema->lastName(),
                $this->schema->firstName(),
                $this->schema->commonName(),
                $this->schema->displayName(),
            ];

            foreach ($locateBy as $attribute) {
                $query->whereEquals($attribute, $value);
            }
        });
    }
63219
protected function normalizeValue($value)
    {
        if (is_null($value)) {
            return $value;
        }

        $entityClass = $this->getEntity();
        // Validate Many2many attribute value
        if (!$this->isArray($value) && !$this->isArrayObject($value) && !$this->isInstanceOf($value, EntityCollection::class)) {
            $exception = new ValidationException(ValidationException::DATA_TYPE, [
                'array, ArrayObject or EntityCollection',
                gettype($value)
            ]);
            $exception->setAttribute($this->getName());
            throw $exception;
        }

        /* @var $entityAttribute One2ManyAttribute */
        $values = [];
        foreach ($value as $item) {
            $itemEntity = false;

            // $item can be an array of data, AbstractEntity or a simple mongo ID string
            if ($this->isInstanceOf($item, $entityClass)) {
                $itemEntity = $item;
            } elseif ($this->isArray($item) || $this->isArrayObject($item)) {
                $itemEntity = $entityClass::findById(isset($item['id']) ? $item['id'] : false);
            } elseif ($this->isString($item) && Entity::getInstance()->getDatabase()->isId($item)) {
                $itemEntity = $entityClass::findById($item);
            }

            // If instance was not found, create a new entity instance
            if (!$itemEntity) {
                $itemEntity = new $entityClass;
            }

            // If $item is an array - use it to populate the entity instance
            if ($this->isArray($item) || $this->isArrayObject($item)) {
                $itemEntity->populate($item);
            }

            $values[] = $itemEntity;
        }

        return new EntityCollection($this->getEntity(), $values);
    }
881112
public function serialize($value): string
    {
        $id = $this->entityManager->getClassMetadata($this->className)->getIdentifierValues($value);

        return (string) reset($id);
    }
507833
public function toBigQuery($value)
    {
        if ($value instanceof ValueInterface || $value instanceof Int64) {
            return (string) $value;
        }

        if ($value instanceof \DateTime) {
            return $value->format(self::DATETIME_FORMAT_INSERT);
        }

        if (is_array($value)) {
            foreach ($value as $key => $item) {
                $value[$key] = $this->toBigQuery($item);
            }

            return $value;
        }

        return $value;
    }
28501
public function setRelated($value)
    {
        $this->loadData(true);

        if (is_null($value)) {
            $value = [];
        }

        if (!is_array($value)) {
            throw new RelationException("HasMany relation can only be set with array of entities");
        }

        //Do not add items twice
        $matched = [];
        foreach ($value as $index => $record) {
            if (is_null($record)) {
                unset($value[$index]);
                continue;
            }

            $this->assertValid($record);
            if (!empty($instance = $this->matchOne($record))) {
                $matched[] = $instance;
                unset($value[$index]);
            }
        }

        //Unlink records
        foreach (array_diff($this->instances, $matched) as $record) {
            $this->unlink($record);
        }

        //Add new record
        foreach ($value as $record) {
            $this->link($record);
        }
    }
454263
public function with($value)
    {
        $withs = explode(',', $value);
        $model = $this->builder->getModel();
        $withs = collect($withs)->filter(function ($with) use($model) {
            if (str_contains($with, '.')) return ($model->{explode('.', $with)[0]}() instanceof Relation);
            return ($model->{$with}() instanceof Relation);
        })->toArray();
        return $this->builder->when(count($withs), function (Builder $query) use($withs) {
            $query->with($withs);
        });
    }
1095287
private function makeSerializable($value)
    {
        if (null === $value) {
            return $value;
        }

        if ($value instanceof Traversable || is_array($value)) {
            $value = ArrayUtils::iteratorToArray($value);

            foreach ($value as $key => $val) {
                $value[$key] = $this->makeSerializable($val);
            }

            return $value;
        }

        if (is_scalar($value)) {
            return $value;
        }

        if (is_resource($value)) {
            return 'resource';
        }

        return new ObjectStub($value);
    }
400407
protected function persistRelatedEntities($value)
    {
        if (!is_array($value) && !$value instanceof \Iterator) {
            $value = [$value];
        }
        foreach ($value as $element) {
            if (is_object($element) && $element instanceof PersistenceMagicInterface) {
                $this->persistenceManager->isNewObject($element) ? $this->persistenceManager->add($element) : $this->persistenceManager->update($element);
            }
        }
    }
386703
public static function fromValue($value) {
    if (is_array($value)) {
      $elements = [];
      foreach ($value as $k => $v) {
        $elements[] = ArrayPairNode::create(static::fromValue($k), static::fromValue($v));
      }
      return ArrayNode::create($elements);
    }
    elseif (is_string($value)) {
      return StringNode::create(var_export($value, TRUE));
    }
    elseif (is_integer($value)) {
      return new IntegerNode(T_LNUMBER, $value);
    }
    elseif (is_float($value)) {
      return new FloatNode(T_DNUMBER, $value);
    }
    elseif (is_bool($value)) {
      return BooleanNode::create($value);
    }
    elseif (is_null($value)) {
      return NullNode::create('NULL');
    }
    else {
      throw new \InvalidArgumentException();
    }
  }
1008520
protected function resolveQueueableEntity($value)
	{
		if (is_string($value) && starts_with($value, '::entity::'))
		{
			list($marker, $type, $id) = explode('|', $value, 3);

			return $this->getEntityResolver()->resolve($type, $id);
		}

		return $value;
	}