@param string $className The resulting object class name.
@param mixed  $value     The raw parameter value to convert to an object.

@return object

@throws HttpException If the object cannot be instantiated.
504832
private function getObject(string $className, $value)
    {
        $packedObject = new PackedObject($className, $value);

        try {
            $object = $this->objectPacker->unpack($packedObject);
        }
        catch (ObjectNotConvertibleException $e) {
            throw new HttpBadRequestException($e->getMessage(), $e);
        }
        catch (ObjectNotFoundException $e) {
            throw new HttpNotFoundException($e->getMessage(), $e);
        }

        if ($object === null) {
            throw new HttpInternalServerErrorException('No object packer available for ' . $className);
        }

        return $object;
    }
562448
public function transform($value)
    {
        if ($value instanceof JsonSerializable || $value instanceof StdClass) {
            return json_encode($value);
        }

        // If a toJson() method exists, the object can cast itself automatically.
        if (method_exists($value, 'toJson')) {
            return $value;
        }

        // Otherwise, if the object doesn't even have a __toString() method, we can't proceed.
        if (! method_exists($value, '__toString')) {
            throw new \Exception('Cannot transform this object to JavaScript.');
        }

        return "'{$value}'";
    }
225760
public static function FromValue( $value )
	{
		if ( is_string( $value ) && ( ! is_numeric( $value ) || ( ! is_int( $value + 0 ) && is_double( $value + 0 ) ) ) )
		{
			throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $value, "integer" ) );
		}

		if ( is_numeric( $value ) )
		{
			if ( is_infinite( $value ) )
				throw XPath2Exception::withErrorCodeAndParams( "FOAR0001", Resources::FOAR0001, array( $value, "integer" ) );

			if ( $value > PHP_INT_MAX || $value < PHP_INT_MIN )
				throw XPath2Exception::withErrorCodeAndParams( "FOAR0002", Resources::FOAR0002, array( $value, "integer" ) );
		}

		return new Integer( $value );
	}
723099
public static function unserialize(Serializer $serializer, $className, array $value)
    {
        $dateTimeZone = DateTimeZoneSerializer::unserialize(
            $serializer,
            'DateTimeZone',
            array($serializer->unserialize($value['data']['timezone']))
        );

        $ref = new ReflectionClass($className);

        return $ref->newInstanceArgs(
            array($serializer->unserialize($value['data']['date']), $dateTimeZone)
        );
    }
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);
    }
935347
final public static function resolveName($value): ?string
    {
        if ($value instanceof DomainId) {
            $class = \get_class($value);

            /** @var string $type */
            foreach (self::$mapping as $type => $mapping) {
                if ($class === $mapping['class']) {
                    return $type::NAME;
                }
            }

            return self::NAME;
        }

        return null;
    }
279860
protected function createValue(&$value)
    {
        $instance = $this->instance($value);
        if (null !== $instance) {
            return $instance;
        }

        $variableType = gettype($value);
        switch ($variableType) {
            case 'boolean':
                return new Value\BooleanValue($value);
            case 'integer':
                return new Value\IntegerValue($value);
            case 'double':
                return new Value\FloatingPointValue($value);
            case 'NULL':
                return new Value\NullValue;
            case 'string':
                return new Value\StringValue($value);
            case 'array':
                return $this->createArray($value);
            case 'object':
                if ($value instanceof DateTime) {
                    return new Value\DateTimeValue($value);
                }

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

        throw new Exception\UnsupportedValueTypeException($value);
    }
917148
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!is_object($value) || is_callable($value)) {
            throw new TransformationFailedException('Expected an object.');
        }

        $className = ClassUtils::getClass($value);

        if ($className !== $this->className && !is_subclass_of($className, $this->className)) {
            throw new TransformationFailedException(sprintf('Expected entity %s.', $this->className));
        }

        $identifierValues = $this->metadata->getIdentifierValues($value);

        return reset($identifierValues);
    }
964537
public function newInstance($name, $value)
    {
        $class = $this->getClassFor($name);
        return new $class($this->consumerService, $name, $value);
    }
172578
private function getClass($value)
    {
        if (\is_string($value)) {
            if (!class_exists($value) && !interface_exists($value, false)) {
                throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value));
            }

            return ltrim($value, '\\');
        }

        if (!\is_object($value)) {
            throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value)));
        }

        return \get_class($value);
    }
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;
    }
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;
        }
    }
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)));
    }
725968
private function getValue(string $class, string $method, $value)
    {
        $parameter = new ReflectionParameter(array($class, $method), 0);
        $type = $parameter->getType();

        if ($type) {
            $dataType = $type->getName();
            if ($dataType === 'DateTimeImmutable') {
                $value = new DateTimeImmutable($value);
            }
            if ($dataType === 'DateTime') {
                $value = new DateTime($value);
            }
        }

        return $value;
    }
314588
private function toObject(string $formalClass, $value)
    {
        if ($this->typeAdapter->isClassRegistered($formalClass)) {
            try {
                return $this->typeAdapter->toObject($value);
            } catch (TypeCastException $exception) {
                throw new InvalidParamsException('Class cast failed');
            }
        }

        throw new InvalidParamsException('Class hint failed');
    }
506152
final public static function create($value)
    {
        $key = get_called_class() . $value;

        if (isset(self::$instances[$key])) {
            return self::$instances[$key];
        }

        $values = static::values();
        if (!in_array($value, $values)) {
            throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class());
        }

        self::$instances[$key] = new static($value);
        return self::$instances[$key];
    }
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');
    }