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

@param array|\Traversable|null $value The original value.
@return \ArrayAccess|null Returns the value that should be hydrated.
2420
public function hydrate($value)
    {
        if ($this->nullable && $value === null) {
            return null;
        }

        $this->hasOneStrategy->setPrototypeStrategy($this->getPrototypeStrategy());
        $return = clone $this->arrayObjectPrototype;
        if (is_array($value) || $value instanceof \Traversable) {
            foreach ($value as $key => $data) {
                $return[$key] = $this->hasOneStrategy->hydrate($data);
            }
        } else {
            throw new Exception\InvalidArgumentException(sprintf(
                'Value must be null (only if nullable option is enabled), or an array, or a Traversable: "%s" given',
                is_object($value) ? get_class($value) : gettype($value)
            ));
        }

        return $return;
    }
1296993
public static function convertToPhp($value)
    {
        if (is_array($value) && isset($value['$ref'], $value['$id'])) {
            return ExtReference::create($value['$ref'], $value['$id']);
        } elseif (is_object($value) && isset($value->{'$ref'}, $value->{'$id'})) {
            return ExtReference::create($value->{'$ref'}, $value->{'$id'});
        } else {
            return null;
        }
    }
195788
public function reverseTransform($value)
    {
        return null !== $value && !empty($value)
            ? $this->contentTypeService->loadContentTypeByIdentifier($value)
            : null;
    }
4258
public function convertQueryCondition($value)
    {
        // First fetch the type
        if (null === $value) {
            return 0;
        }

        if (!is_array($value)) {
            $value = [$value];
        }

        $hasOperator = false;

        // FIXME Sorry for this
        if (!Misc::isIndexed($value)) {
            // We have an operator.
            $operator = array_keys($value)[0];
            $values = $value[$operator][0];
            $hasOperator = true;
        } else {
            $values = $value;
        }

        foreach ($values as $key => $type) {
            if (null === $type) {
                $values[$key] = 0;
            } else if ($typeId = $this->getTypeId($type, false)) {
                $values[$key] = $typeId;
            } else {
                unset($values[$key]);
            }
        }

        if (empty($values)) {
            // It should not have been empty, this is an impossible
            // condition
            $values = [-1];
        }

        if ($hasOperator) {
            return [$operator => $values];
        } else {
            return $values;
        }
    }
1166852
public static function get($key, $value = null)
    {
        if (self::check($key, !is_null($value))) {
            return self::reach($key, $value);
        }

        static::set($key, $value);

        return $value;
    }
25134
protected function transformRecursive($value)
    {
        if (is_array($value) || $value instanceof \Traversable) {
            foreach ($value as &$subvalue) {
                $subvalue = $this->transformRecursive($subvalue);
            }
        } else {
            $value = $this->transformer->transform($value);
        }

        return $value;
    }
276456
public function query($key, $value = null)
    {
        if ($value) {
            return $this->replicate(['query' => [$key => $value]]);
        }

        return $this->replicate(['query' => $key]);
    }
85879
public function toHash(SPIValue $value)
    {
        if ($this->isEmptyValue($value)) {
            return null;
        }

        return $this->hashConverter->convertFromValue($value);
    }
454265
protected function receiveTokenFieldValueFromRequest($value = null)
    {
        $requestQueryParameter = $this->getRequest()->getQueryParams();
        $requestBody           = $this->getRequest()->getParsedBody();
        $fieldname             = $this->getFieldnameToken();

        if (true === isset($requestQueryParameter[$fieldname])) {
            $value = $requestQueryParameter[$fieldname];
        } elseif (true === isset($requestBody[$fieldname])) {
            $value = $requestBody[$fieldname];
        }

        return $value;
    }
472027
public function keyOf($value)
    {
        foreach ($this->items as $key => $iValue) {
            if ($value === $iValue) {
                return $key;
            }
        }

        return null;
    }
703223
public static function allToArray($value)
    {
        if ($value instanceof \Traversable) {
            $value = iterator_to_array($value);
        }

        if (is_object($value)) {
            $value = get_object_vars($value);
        }

        $value = (array) $value;

        foreach ($value as $k => $v) {
            if (!static::isValidValue($v)) {
                throw new \InvalidArgumentException('Value :' . $value . ' is invalid.');
            }
        }

        return $value;
    }
1098392
public function filter($value)
    {
        return in_array($value, $this->getList(), $this->getStrict()) ? $value : null;
    }
513520
public function sanitize($value)
    {
        if ($value instanceof Traversable) {
            return $this->sanitize(iterator_to_array($value));
        } elseif (is_array($value)) {
            return array_map([$this, 'sanitize'], $value);
        } elseif (is_object($value)) {
            return $this->sanitizeObject($value);
        } elseif (is_resource($value)) {
            return get_resource_type($value);
        }

        return $value;
    }
1280751
private static function convertToArrayAccess($value)
    {
        if ($value instanceof \ArrayAccess) {
            $array = $value;
        } elseif ($value instanceof \Traversable) {
            $array = SequenceType::convertToRewindable($value);
            if ($array instanceof \Traversable) {
                set_error_handler(function ($severity, $message) {
                    return $severity === E_WARNING
                        ? $message === 'Illegal offset type'
                        : preg_match('/^Resource ID#([0-9]+) used as offset, casting to integer \\(\\1\\)$/', $message);
                }, E_WARNING | (PHP_MAJOR_VERSION === 5 ? E_STRICT : E_NOTICE));
                $array = iterator_to_array($array);
                restore_error_handler();
            }
        } else {
            $array = (array)$value;
        }
        
        return $array;
    }
1328429
public function prepareValue($value)
    {
        return $value === null ? null : Carbon::createFromFormat($this->format, $value)->toDateString();
    }
220083
public function key($value)
    {
        if ($value instanceof Cacheable) {
            return $value->cacheId();
        }

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

        if (is_array($value)) {
            return $this->arrayToKey($value);
        }

        if (is_object($value)) {
            return $this->objectToKey($value);
        }

        return null;
    }
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
        );
    }