value = $value; } public static function __set_state(array $state): self { return new self($state['value']); } /** * Exports the encapsulated value to php code * * @throws LogicException */ public function export(): string { if (! $this->isExportable()) { throw new LogicException('Unable to export value'); } if ($this->value === null) { return 'null'; } return var_export($this->value, true); } /** * Checks wether the value can be exported for code generation or not */ public function isExportable(): bool { return $this->isExportableRecursive($this->value); } /** * Check if the provided value is exportable. * For arrays it uses recursion. * * @param mixed $value */ private function isExportableRecursive($value): bool { if (is_scalar($value) || $value === null) { return true; } if (is_array($value)) { foreach ($value as $item) { if (! $this->isExportableRecursive($item)) { return false; } } return true; } if (is_object($value) && method_exists($value, '__set_state')) { $method = new ReflectionMethod($value, '__set_state'); return $method->isStatic() && $method->isPublic(); } return false; } /** @return mixed */ public function toValue(ContainerInterface $container) { return $this->value; } /** * Get the value to inject * * @deprecated Since 3.1.0 * * @see toValue() * * @return mixed */ public function getValue() { trigger_error( __METHOD__ . ' is deprecated, please migrate to ' . self::class . '::toValue().', E_USER_DEPRECATED ); return $this->value; } }