value = static::filter( ($value instanceof self) ? $value->getValue() : $value ); } public function __debugInfo() { return [ 'value' => $this->value, ]; } /** * @param null|mixed $value * @throws TypeException */ public static function get($value = null): self { static $instantiated = null; if ($value === null) { if (static::DEFAULT_VALUE === null) { throw new TypeException('The type has not default value.'); } return static::get( static::DEFAULT_VALUE ); } if (is_object($value)) { if ($value instanceof static) { return $value; } $identity = spl_object_hash($value); } else { $identity = (string) $value; } return $instantiated[$identity] = $instantiated[$identity] ?? new static($value); } public function getValue() { return $this->value; } public function getTypeNameInJava(): string { return $this->nameInJava; } public function getTypeNameInPHP(): string { return $this->nameInPHP; } public function __toString(): string { return (string) $this->getValue(); } public static function isValid($value): bool { throw new TypeException('Not implemented type validation.'); } protected static function filter($value) { return $value; } }