@param array           $value
@param ReflectionClass $ref

@return object
434266
protected static function fillObjectProperties(array $value, ReflectionClass $ref)
    {
        $obj = $ref->newInstanceArgs([$value['construct']]);
        unset($value['construct']);

        foreach ($value as $k => $v) {
            $obj->$k = $v;
        }

        return $obj;
    }
431767
public static function unserialize(Serializer $serializer, $className, array $value)
    {
        $data = $serializer->unserialize($value[Serializer::SCALAR_VALUE]);

        /* @var SplFixedArray $instance */
        $ref = new ReflectionClass($className);
        $instance = $ref->newInstanceWithoutConstructor();

        $instance->setSize(count($data));
        foreach ($data as $k => $v) {
            $instance[$k] = $v;
        }

        return $instance;
    }
565633
public function createReference($value)
    {
        $ref = $this->generateNextReference();
        $this->references[$ref] = $value;

        return $ref;
    }
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);
    }
1254160
public function parseMethods(\ReflectionClass $ref)
    {
        foreach($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $method)
        {
            $this->parseMethod($ref, $method);
        }
    }
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');
    }
708105
protected function instance(&$value)
    {
        foreach ($this->instances as &$tuple) {
            if ($tuple[0] === $value) {
                if (
                    is_array($value) &&
                    !$this->isArrayReference($tuple[0], $value)
                ) {
                    continue;
                }

                return $tuple[1];
            }
        }

        return null;
    }
789749
protected function createObject(stdClass &$value)
    {
        if (property_exists($value, '$ref') && is_string($value->{'$ref'})) {
            return $this->createReferenceFromObject($value);
        }

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

        foreach (get_object_vars($value) as $property => $subValue) {
            $realProperty = $property;
            if ('_empty_' === $property) {
                $property = '';
            }

            $instance->set($property, $this->createValue($value->$realProperty));
        }

        return $instance;
    }
43224
protected function serializeObject(array $value)
    {
        if (null !== $this->mappings) {
            /** @var \NilPortugues\Api\Mapping\Mapping $mapping */
            foreach ($this->mappings as $class => $mapping) {
                RecursiveDeleteHelper::deleteProperties($this->mappings, $value, $class);
                RecursiveRenamerHelper::renameKeyValue($this->mappings, $value, $class);
            }
        }

        $this->setResponseMeta($value);
        $this->setResponseLinks($value);
        self::formatScalarValues($value);
        RecursiveDeleteHelper::deleteKeys($value, [Serializer::CLASS_IDENTIFIER_KEY]);
        self::flattenObjectsWithSingleKeyScalars($value);
        $this->recursiveSetKeysToUnderScore($value);

        return $value;
    }
415897
protected function getObjectProperties(ReflectionClass $ref, $value)
    {
        $props = [];
        foreach ($ref->getProperties() as $prop) {
            $props[] = $prop->getName();
        }

        return \array_unique(\array_merge($props, \array_keys(\get_object_vars($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');
    }
232293
public function convert($value)
	{
		if (is_array(($value))) {
			$retval = [];
			foreach ($value as $object) {
				$retval[] = $this->convert($object); // force sequential indexing
			}

			return $retval;
		} else if (is_object($value)) {
			return $this->convertObject($value);
		} else {
			return $value;
		}
	}
367713
private function getProperty(\ReflectionClass $ref, $property)
    {
        $prop = $ref->getProperty($property);
        $prop->setAccessible(true);

        return $prop;
    }
542339
protected function resolveValue(string $setterMethodName, $value)
    {
        $reflection = new ReflectionClass($this);

        $method = $reflection->getMethod($setterMethodName);

        $parameter = $method->getParameters()[0];

        return $this->resolveParameter($parameter, $value);
    }
736139
private function parseValue($value, $types, \ReflectionProperty $property, $object)
    {
        foreach ($types as $type) {
            foreach ($this->context->getParsers() as $parser) {
                if ($parser instanceof ValueParserInterface) {
                    if (is_array($value) && strpos($type, '[]') !== false) {

                        //support for nesting children
                        //https://github.com/rafrsr/lib-array2object/issues/1
                        if (count($value) === 1 && is_array(current($value))) {
                            if (array_key_exists(0, current($value))) {
                                $value = current($value);
                            }
                        }

                        $tmpArray = [];
                        foreach ($value as $key => $arrayValue) {
                            $parsedValue = $parser->toObjectValue($arrayValue, str_replace('[]', null, $type), $property, $object);
                            //the annotation [] is used alone to ignore array keys
                            if (in_array('[]', $types, true)) {
                                $tmpArray[] = $parsedValue;
                            } else {
                                $tmpArray[$key] = $parsedValue;
                            }
                        }
                        $value = $tmpArray;
                    } else {
                        $value = $parser->toObjectValue($value, str_replace('[]', null, $type), $property, $object);
                    }
                } else {
                    throw new \InvalidArgumentException(sprintf('%s is not a valid parser.', get_class($parser)));
                }
            }
        }

        return $value;
    }
308715
private function dumpValue($value)
    {
        if (is_array($value)) {
            $code = array();
            foreach ($value as $k => $v) {
                $code[$k] = $this->dumpValue($v);
            }

            return $code;
        } elseif ($value instanceof Reference) {
            return $this->getServiceCall((string) $value, $value);
        } elseif ($value instanceof Parameter) {
            return $this->getParameterCall((string) $value);
        } elseif ($value instanceof Expression) {
            return $this->getExpressionCall((string) $value);
        } elseif (is_object($value) || is_resource($value)) {
            throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
        }

        return $value;
    }
644232
public function add($value)
    {
        if (! $value instanceof SpecificationInterface) {
            throw new InvalidArgumentException(sprintf(
                '"%s" does not implement "%s"!',
                (is_object($value)) ? get_class($value) : $value,
                SpecificationInterface::class
            ));
        }

        return parent::add($value);
    }