Final Class Yiisoft\Di\Helpers\DefinitionParser
| Inheritance | Yiisoft\Di\Helpers\DefinitionParser |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| parse() | Yiisoft\Di\Helpers\DefinitionParser |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFINITION_META | 'definition' | Yiisoft\Di\Helpers\DefinitionParser | |
| IS_PREPARED_ARRAY_DEFINITION_DATA | 'isPreparedArrayDefinitionData' | Yiisoft\Di\Helpers\DefinitionParser |
Method Details
| public static parse( mixed $definition ): array | ||
| $definition | mixed |
Definition to parse. |
| return | array |
Definition parsed into an array of a special structure. |
|---|---|---|
public static function parse(mixed $definition): array
{
if (!is_array($definition)) {
return [$definition, []];
}
// Dedicated definition
if (isset($definition[self::DEFINITION_META])) {
$newDefinition = $definition[self::DEFINITION_META];
unset($definition[self::DEFINITION_META]);
return [$newDefinition, $definition];
}
// Callable definition
if (is_callable($definition, true)) {
return [$definition, []];
}
// Array definition
$meta = [];
$class = null;
$constructorArguments = [];
$methodsAndProperties = [];
foreach ($definition as $key => $value) {
if (is_string($key)) {
// Class
if ($key === ArrayDefinition::CLASS_NAME) {
$class = $value;
continue;
}
// Constructor arguments
if ($key === ArrayDefinition::CONSTRUCTOR) {
$constructorArguments = $value;
continue;
}
// Methods and properties
if (count($methodArray = explode('()', $key, 2)) === 2) {
$methodsAndProperties[$key] = [ArrayDefinition::TYPE_METHOD, $methodArray[0], $value];
continue;
}
if (count($propertyArray = explode('$', $key, 2)) === 2) {
$methodsAndProperties[$key] = [ArrayDefinition::TYPE_PROPERTY, $propertyArray[1], $value];
continue;
}
}
$meta[$key] = $value;
}
return [
[
'class' => $class,
'__construct()' => $constructorArguments,
'methodsAndProperties' => $methodsAndProperties,
self::IS_PREPARED_ARRAY_DEFINITION_DATA => true,
],
$meta,
];
}
Signup or Login in order to comment.