class AutowireInline
Allows inline service definition for an argument.
Using this attribute on a class autowires a new instance which is not shared between different services.
$class a FQCN, or an array to define a factory. Use the "@" prefix to reference a service.
@author Ismail Özgün Turan <oezguen.turan@dadadev.com>
Hierarchy
- class \Symfony\Component\DependencyInjection\Attribute\Autowire
- class \Symfony\Component\DependencyInjection\Attribute\AutowireInline extends \Symfony\Component\DependencyInjection\Attribute\Autowire
Expanded class hierarchy of AutowireInline
2 files declare their use of AutowireInline
- AutowirePass.php in vendor/
symfony/ dependency-injection/ Compiler/ AutowirePass.php - ResolveAutowireInlineAttributesPass.php in vendor/
symfony/ dependency-injection/ Compiler/ ResolveAutowireInlineAttributesPass.php
File
-
vendor/
symfony/ dependency-injection/ Attribute/ AutowireInline.php, line 29
Namespace
Symfony\Component\DependencyInjection\AttributeView source
class AutowireInline extends Autowire {
public function __construct(string|array|null $class = null, array $arguments = [], array $calls = [], array $properties = [], ?string $parent = null, bool|string $lazy = false) {
if (null === $class && null === $parent) {
throw new LogicException('#[AutowireInline] attribute should declare either $class or $parent.');
}
parent::__construct([
\is_array($class) ? 'factory' : 'class' => $class,
'arguments' => $arguments,
'calls' => $calls,
'properties' => $properties,
'parent' => $parent,
], lazy: $lazy);
}
public function buildDefinition(mixed $value, ?string $type, \ReflectionParameter $parameter) : Definition {
static $parseDefinition;
static $yamlLoader;
$parseDefinition ??= new \ReflectionMethod(YamlFileLoader::class, 'parseDefinition');
$yamlLoader ??= $parseDefinition->getDeclaringClass()
->newInstanceWithoutConstructor();
if (isset($value['factory'])) {
$value['class'] = $type;
$value['factory'][0] ??= $type;
$value['factory'][1] ??= '__invoke';
}
$class = $parameter->getDeclaringClass();
return $parseDefinition->invoke($yamlLoader, $class->name, $value, $class->getFileName(), [
'autowire' => true,
], true);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Autowire::$lazy | public | property | |||
Autowire::$value | public | property | |||
AutowireInline::buildDefinition | public | function | 1 | ||
AutowireInline::__construct | public | function | Use only ONE of the following. | Overrides Autowire::__construct | 1 |