Converts the given value so that it can be hydrated by the hydrator.

@param mixed $value The original value.
@param array $data  (optional) The original data for context.

@return mixed Returns the value that should be hydrated.
553688
public function hydrate($value, $data = [])
    {
        if (is_array($value)) {
            $coll = new ArrayCollection();
            foreach ($value as $v) {
                $coll->add($this->hydrate($v, $data));
            }
            return $coll;
        }

        if (empty($value) || 0 !== strpos($value, '{')) {
            return null;
        }

        $location = $this->getLocationEntity();
        return $location->fromString($value);
    }
419224
protected function hydrateByValue(array $data, $object)
    {
        $tryObject = $this->tryConvertArrayToObject($data, $object);
        $metadata  = $this->metadata;

        if (is_object($tryObject)) {
            $object = $tryObject;
        }

        foreach ($data as $field => $value) {
            $field  = $this->computeHydrateFieldName($field);
            $setter = 'set' . Inflector::classify($field);

            if ($metadata->hasAssociation($field)) {
                $target = $metadata->getAssociationTargetClass($field);

                if ($metadata->isSingleValuedAssociation($field)) {
                    if (! is_callable([$object, $setter])) {
                        continue;
                    }

                    $value = $this->toOne($target, $this->hydrateValue($field, $value, $data));

                    if (null === $value
                        && ! current($metadata->getReflectionClass()->getMethod($setter)->getParameters())->allowsNull()
                    ) {
                        continue;
                    }

                    $object->$setter($value);
                } elseif ($metadata->isCollectionValuedAssociation($field)) {
                    $this->toMany($object, $field, $target, $value);
                }
            } else {
                if (! is_callable([$object, $setter])) {
                    continue;
                }

                $object->$setter($this->hydrateValue($field, $value, $data));
            }

            $this->metadata = $metadata;
        }

        return $object;
    }
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
        );
    }
862720
protected function valueRetriever($value)
    {
        if ($this->useAsCallable($value)) {
            return $value;
        }

        return function ($item) use ($value) {
            return ArrayHelper::getValue($item, $value);
        };
    }
720412
public function filter($value)
    {
        if (! is_array($value)) {
            // nothing to do
            return $value;
        }

        // Convert the date to a specific format
        if ($this->isNullOnEmpty()
            && array_reduce($value, __CLASS__ . '::reduce', false)
        ) {
            return;
        }

        if ($this->isNullOnAllEmpty()
            && array_reduce($value, __CLASS__ . '::reduce', true)
        ) {
            return;
        }

        $this->filterable($value);

        ksort($value);
        $value = vsprintf($this->format, $value);

        return $value;
    }
874818
public static function convertToPhp($value)
    {
        if (!is_array($value)) {
            return [];
        }

        $elements = [];
        foreach ($value as $translatable) {
            $elements[] = TranslatableType::convertToPhp($translatable);
        }

        return $elements;
    }
1171794
public function unserialize($value)
    {
        if (\is_array($value) && isset($value[self::SCALAR_TYPE])) {
            return $this->unserializeData($value);
        }

        $this->reset();

        return $this->unserializeData($this->serializationStrategy->unserialize($value));
    }
799516
public function hydrate($value)
    {
        $objectPrototype = $this->getObjectPrototype();

        if (is_array($value)) {
            $object = $this->getPrototypeStrategy()->createObject($objectPrototype, $value);
            return $object->getHydrator()->hydrate($value, $object);
        }

        if (null === $value) {
            return $this->nullable ? null : clone $objectPrototype;
        }

        if ($value instanceof $objectPrototype) {
            return clone $value;
        }

        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid value: must be null (only if nullable option is enabled), or an array, or an instance of "%s": "%s" given',
            get_class($objectPrototype),
            is_object($value) ? get_class($value) : gettype($value)
        ));
    }
322874
private function processValue($value)
    {
        if ($value === "NOW()") {
            return $this->connection()->quote(gmdate("Y-m-d H:i:s"));
        } elseif ($value === "NULL") {
            return 'NULL';
        } elseif (is_array($value)) {
            return $this->connection()->quote(json_encode($value));
        } else {
            return $this->connection()->quote($value);
        }
    }
885810
public function set($data, $value = null): SessionInterface
    {
        if (is_array($data)) {
            $newData = [];
            foreach ($data as $key => $val) {
                $key = $this->getNamespacedKey($key);
                $newData[$key] = $val;
            }
            $data = $newData;
        } else {
            $data = $this->getNamespacedKey($data);
        }

        $this->session->set($data, $value);

        return $this;
    }
940130
public function convert($value)
    {
        if (!is_array($value)) {
            return false;
        }

        $value = json_encode($value);
        return md5($value);
    }
47513
protected function normalizeValue($value)
    {
        $normalizedValue = $value;
        // object value
        if (is_object($value)) {
            if (get_class($value) === "DateTime") {
                $normalizedValue = $value->format("Y-m-d\TH:i:s.u\Z");
            } elseif ($value instanceof DataContainerInterface || method_exists($value, 'normalizeData')) {
                $normalizedValue = $value->normalizeData();
            } else {
                throw new PropertyValueNormalizationException(
                    "Value error: object of type [" . get_class($value) . "]
                    does not implement DataContainerInterface nor have a [normalizeData] method"
                );
            }
        } elseif (is_array($value)) {
            foreach ($value as $arrProperty => $arrValue) {
                $normalizedValue[$arrProperty] = $this->normalizeValue($arrValue);
            }
        }

        return $normalizedValue;
    }
27395
protected function unserializeData($value)
    {
        if ($value === null || !is_array($value)) {
            return $value;
        }

        if (isset($value[self::MAP_TYPE]) && !isset($value[self::CLASS_IDENTIFIER_KEY])) {
            $value = $value[self::SCALAR_VALUE];

            return $this->unserializeData($value);
        }

        if (isset($value[self::SCALAR_TYPE])) {
            return $this->getScalarValue($value);
        }

        if (isset($value[self::CLASS_PARENT_KEY]) && 0 === strcmp($value[self::CLASS_PARENT_KEY], 'SplFixedArray')) {
            return SplFixedArraySerializer::unserialize($this, $value[self::CLASS_IDENTIFIER_KEY], $value);
        }

        if (isset($value[self::CLASS_IDENTIFIER_KEY])) {
            return $this->unserializeObject($value);
        }

        return \array_map([$this, __FUNCTION__], $value);
    }
741575
public function unserializeData($value)
    {
        if (\is_array($value)) {
            return $value;
        }

        if (0 === strpos($value, 'a:')) {
            return \unserialize($value, ['allowed_classes' => false]);
        }

        return $value;
    }
609777
public function setValue($value, $data = null)
    {
        // Save raw value for later validation
        $this->rawValue = $value;

        // Null case
        if (!$value) {
            $this->value = null;
            return $this;
        }

        // Re-run through formatter to tidy up (e.g. remove time component)
        $this->value = $this->tidyInternal($value);
        return $this;
    }
477144
private function hydrateMapValue($key, $value)
    {
        $row = [];
        $mode = array_key_exists($key, $this->mappings) ? $this->mappings[$key][1] : self::HYDRATE_RAW;

        if ($mode === self::HYDRATE_SINGLE) {
            $row = $this->em->getEntityHydrator($this->mappings[$key][0])->hydrateNode($value);
        } elseif ($mode === self::HYDRATE_COLLECTION) {
            $coll = [];
            foreach ($value as $i) {
                $v = $this->em->getEntityHydrator($this->mappings[$key][0])->hydrateNode($i);
                $coll[] = $v;
            }
            $row = $coll;
        } elseif ($mode === self::HYDRATE_MAP_COLLECTION) {
            $row = $this->hydrateMapCollection($value);
        } elseif ($mode === self::HYDRATE_MAP) {
            $row = $this->hydrateMap($value);
        } elseif ($mode === self::HYDRATE_RAW) {
            $row = $value;
        }
        return $row;
    }
1021143
public function hydrate($object, $data)
    {
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                // Check setMethod
                if (!$this->callSetter($object, $this->toCamelCase($key), $value)) {
                    // If no setter is defined, we reinject into array
                    $data[$key] = $value; // Change data with subObject
                }
            }
        }

        return $object;
    }