@param mixed $value Array

@return mixed Instance of registered class
354817
public function toObject($value)
    {
        if (!is_array($value)) {
            throw new TypeCastException('Is not array');
        }

        foreach ($this->rules as $class => $rule) {
            if ($this->isMatch($rule, $value)) {
                return $this->createInstance($class, $value);
            }
        }

        throw new TypeCastException('Rule not found');
    }
608080
public static function getType( $value )
    {
        $type = gettype($value);
        switch( $type ){
        case 'string':
            return $type . '(' . strlen($value) . ')';
            break;
        case 'integer':
        case 'float':
        case 'boolean':
            return $type . '(' . $value . ')';
            break;
        case 'NULL':
        case 'unknown type':
            return $type;
            break;
        case 'array':
            return $type . '(' . count($value) . ')';
            break;
        case 'object':
            if ( $value instanceof \Countable ){
                return get_class( $value ) . '(' . count($value) . ')';
            }
            elseif ( $value instanceof HashableInterface ){
                return get_class( $value ) . '(hash=' . $value->hash() . ')';
            }
            return get_class( $value );
            break;
        }
        return '';
    }
1190078
protected function serializeObject($value)
    {
        if (self::$objectStorage->contains($value)) {
            return [self::CLASS_IDENTIFIER_KEY => '@'.self::$objectStorage[$value]];
        }

        self::$objectStorage->attach($value, self::$objectMappingIndex++);

        $reflection = new ReflectionClass($value);
        $className = $reflection->getName();

        return $this->serializeInternalClass($value, $className, $reflection);
    }
161455
private function deserializeValue($value)
    {
        if (is_array($value) && isset($value['class']) && isset($value['payload'])) {
            return $this->deserializeObjectRecursively($value);
        } elseif (is_array($value)) {
            return $this->deserializeArrayRecursively($value);
        }

        return $value;
    }
775561
private function getValues($value)
    {
        if (is_array($value)) {
            $newValue = array();

            foreach ($value as $itemValue) {
                $newValue = array_merge($newValue, $this->getValues($itemValue));
            }

            return array($newValue);
        }

        if (is_object($value) && $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) {
            $class = $this->em->getClassMetadata(get_class($value));
            if ($class->isIdentifierComposite) {
                $newValue = array();

                foreach ($class->getIdentifierValues($value) as $innerValue) {
                    $newValue = array_merge($newValue, $this->getValues($innerValue));
                }

                return $newValue;
            }
        }

        return array($this->getIndividualValue($value));
    }
913028
public function toArray($value)
    {
        if (!is_object($value)) {
            throw new TypeCastException('Is not object');
        }

        foreach ($this->rules as $class => $rule)
        {
            if (get_class($value) === $class) {
                return $this->createMap($class, $value);
            }
        }

        throw new TypeCastException('Rule not found');
    }
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;
    }
1272707
static function fromValue($value)
    {
        $key = self::getKey($value);

        return self::$instanceCache[static::class][$key]
            ?? (self::$instanceCache[static::class][$key] = new static($key, static::getValue($key)));
    }
851826
private static function getClass($value)
    {
        if (\is_object($value)) {
            return new \ReflectionObject($value);
        }

        if (!\is_string($value)) {
            throw new \InvalidArgumentException('Mirror expects an object or class');
        } elseif (!\class_exists($value) && !\interface_exists($value) && !\trait_exists($value)) {
            throw new \InvalidArgumentException('Unknown class or function: ' . $value);
        }

        return new \ReflectionClass($value);
    }
112413
public static function cast($value)
    {
        $currentClass = get_called_class();
        if (!is_object($value) || get_class($value) !== $currentClass) {
            $value = new $currentClass($value);
        }
        return $value;
    }
1255740
protected function createArray(array &$value)
    {
        $size = count($value);
        if ($size > 0 && array_keys($value) !== range(0, $size - 1)) {
            return $this->createObjectFromArray($value);
        }

        $instance = new Value\ArrayValue;
        $this->register($value, $instance);

        foreach ($value as $key => &$subValue) {
            $instance->set($key, $this->createValue($subValue));
        }

        return $instance;
    }
957480
protected function valueToJsonLd($value)
    {
        if (is_array($value)) {
            $return = [];
            foreach ($value as $item) {
                $return[] = $this->valueToJsonLd($item);
            }

            return $return;
        } elseif ($value instanceof Type\EnumerationType || $value instanceof Type\Enumeration) {
            return $value->getSchemaUrl();
        } elseif ($value instanceof Type\TypeInterface) {
            return $this->typeToJsonLd($value);
        } elseif ($value instanceof Property\PropertyInterface) {
            return $this->propertyToJsonLd($value);
        } elseif ($value instanceof DataType\DataTypeInterface) {
            return $this->dataTypeToJsonLd($value);
        }

        throw new \Exception('Unexpected data type '.gettype($value));
    }
1262653
public function objectProperty($value)
    {
        switch (true) {
            case $value instanceof Int64:
                return [
                    'integerValue' => $value->get()
                ];

                break;
            case $value instanceof Blob:
                return [
                    'blobValue' => ($this->encode)
                        ? base64_encode((string) $value)
                        : (string) $value
                ];

                break;

            case $value instanceof \DateTimeInterface:
                return [
                    'timestampValue' => $value->format(self::DATE_FORMAT)
                ];

                break;

            case $value instanceof EntityInterface:
                return [
                    'entityValue' => $this->objectToRequest($value)
                ];

                break;

            case $value instanceof GeoPoint:
                return [
                    'geoPointValue' => $value->point()
                ];

                break;

            case $value instanceof Key:
                return [
                    'keyValue' => $value->keyObject()
                ];

                break;

            case $value instanceof \stdClass:
                return $this->convertArrayToEntityValue((array) $value);

            default:
                throw new \InvalidArgumentException(
                    sprintf('Value of type `%s` could not be serialized', get_class($value))
                );

                break;
        }
    }
593388
protected function castToClass($value)
    {
        if (!class_exists($this->class)) {
            return $this->dontCast($value, "Class doesn't exist");
        }

        if (is_object($value) && is_a($value, $this->class)) {
            return $value;
        }

        $value = $this->createWithSetState($value);

        if (!is_a($value, $this->class)) {
            $class = $this->class;
            $value = new $class($value);
        }

        return $value;
    }
882876
public static function fromValue($value)
    {
        $values = static::getValues();
        if (array_key_exists($value, $values)) {
            return new static($values[$value], $value);
        }
        throw new \InvalidArgumentException("No enum constant value '$value' class " . get_called_class());
    }
147874
private function castToObject($value, $class)
    {
        if (!class_exists($class) || $value instanceof $class) {
            return $value;
        }

        $parentClasses = class_parents($class);

        if (in_array(Enum::class, $parentClasses) || in_array(AbstractObject::class, $parentClasses)) {
            return new $class($value);
        }

        if (in_array(Model::class, $parentClasses)) {
            return new $class($this->getClient(), $value);
        }

        if (in_array(ListObject::class, $parentClasses)) {
            return new $class($value);
        }

        return $value;
    }
590405
public static function create($value)
    {
        $class = static::class;
        if (!array_key_exists($class, self::$instances)) {
            self::$instances[$class] = [];
        }
        if (!array_key_exists($value, self::$instances[$class])) {
            self::$instances[$class][$value] = new static($value);
        }

        return self::$instances[$class][$value];
    }