__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
declare(strict_types=1);
namespace DI\Definition\Source;
use DI\Definition\ObjectDefinition;
use DI\Definition\ObjectDefinition\MethodInjection;
use DI\Definition\Reference;
use ReflectionNamedType;
/**
* Reads DI class definitions using reflection.
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
class ReflectionBasedAutowiring implements DefinitionSource, Autowiring
{
public function autowire(string $name, ObjectDefinition $definition = null) : ObjectDefinition|null
{
$className = $definition ? $definition->getClassName() : $name;
if (!class_exists($className) && !interface_exists($className)) {
return $definition;
}
$definition = $definition ?: new ObjectDefinition($name);
// Constructor
$class = new \ReflectionClass($className);
$constructor = $class->getConstructor();
if ($constructor && $constructor->isPublic()) {
$constructorInjection = MethodInjection::constructor($this->getParametersDefinition($constructor));
$definition->completeConstructorInjection($constructorInjection);
}
return $definition;
}
public function getDefinition(string $name) : ObjectDefinition|null
{
return $this->autowire($name);
}
/**
* Autowiring cannot guess all existing definitions.
*/
public function getDefinitions() : array
{
return [];
}
/**
* Read the type-hinting from the parameters of the function.
*/
private function getParametersDefinition(\ReflectionFunctionAbstract $constructor) : array
{
$parameters = [];
foreach ($constructor->getParameters() as $index => $parameter) {
// Skip optional parameters
if ($parameter->isOptional()) {
continue;
}
$parameterType = $parameter->getType();
if (!$parameterType) {
// No type
continue;
}
if (!$parameterType instanceof ReflectionNamedType) {
// Union types are not supported
continue;
}
if ($parameterType->isBuiltin()) {
// Primitive types are not supported
continue;
}
$parameters[$index] = new Reference($parameterType->getName());
}
return $parameters;
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| AttributeBasedAutowiring.php | File | 8.6 KB | 0777 |
|
| Autowiring.php | File | 522 B | 0777 |
|
| DefinitionArray.php | File | 3.39 KB | 0777 |
|
| DefinitionFile.php | File | 1.32 KB | 0777 |
|
| DefinitionNormalizer.php | File | 3.66 KB | 0777 |
|
| DefinitionSource.php | File | 637 B | 0777 |
|
| MutableDefinitionSource.php | File | 356 B | 0777 |
|
| NoAutowiring.php | File | 582 B | 0777 |
|
| ReflectionBasedAutowiring.php | File | 2.37 KB | 0777 |
|
| SourceCache.php | File | 2.38 KB | 0777 |
|
| SourceChain.php | File | 2.64 KB | 0777 |
|