Upgrade framework
This commit is contained in:
@@ -12,9 +12,10 @@
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Symfony\Component\Debug\DebugClassLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\ErrorHandler\DebugClassLoader;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
/**
|
||||
@@ -36,23 +37,17 @@ class AddAnnotatedClassesToCachePass implements CompilerPassInterface
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$classes = array();
|
||||
$annotatedClasses = array();
|
||||
$annotatedClasses = [];
|
||||
foreach ($container->getExtensions() as $extension) {
|
||||
if ($extension instanceof Extension) {
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
$classes = array_merge($classes, $extension->getClassesToCompile());
|
||||
}
|
||||
$annotatedClasses = array_merge($annotatedClasses, $extension->getAnnotatedClassesToCompile());
|
||||
$annotatedClasses[] = $extension->getAnnotatedClassesToCompile();
|
||||
}
|
||||
}
|
||||
|
||||
$annotatedClasses = array_merge($this->kernel->getAnnotatedClassesToCompile(), ...$annotatedClasses);
|
||||
|
||||
$existingClasses = $this->getClassesInComposerClassMaps();
|
||||
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
$classes = $container->getParameterBag()->resolveValue($classes);
|
||||
$this->kernel->setClassCache($this->expandClasses($classes, $existingClasses));
|
||||
}
|
||||
$annotatedClasses = $container->getParameterBag()->resolveValue($annotatedClasses);
|
||||
$this->kernel->setAnnotatedClassCache($this->expandClasses($annotatedClasses, $existingClasses));
|
||||
}
|
||||
@@ -62,16 +57,14 @@ class AddAnnotatedClassesToCachePass implements CompilerPassInterface
|
||||
*
|
||||
* @param array $patterns The class patterns to expand
|
||||
* @param array $classes The existing classes to match against the patterns
|
||||
*
|
||||
* @return array A list of classes derivated from the patterns
|
||||
*/
|
||||
private function expandClasses(array $patterns, array $classes)
|
||||
private function expandClasses(array $patterns, array $classes): array
|
||||
{
|
||||
$expanded = array();
|
||||
$expanded = [];
|
||||
|
||||
// Explicit classes declared in the patterns are returned directly
|
||||
foreach ($patterns as $key => $pattern) {
|
||||
if (substr($pattern, -1) !== '\\' && false === strpos($pattern, '*')) {
|
||||
if (!str_ends_with($pattern, '\\') && !str_contains($pattern, '*')) {
|
||||
unset($patterns[$key]);
|
||||
$expanded[] = ltrim($pattern, '\\');
|
||||
}
|
||||
@@ -91,20 +84,20 @@ class AddAnnotatedClassesToCachePass implements CompilerPassInterface
|
||||
return array_unique($expanded);
|
||||
}
|
||||
|
||||
private function getClassesInComposerClassMaps()
|
||||
private function getClassesInComposerClassMaps(): array
|
||||
{
|
||||
$classes = array();
|
||||
$classes = [];
|
||||
|
||||
foreach (spl_autoload_functions() as $function) {
|
||||
if (!is_array($function)) {
|
||||
if (!\is_array($function)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($function[0] instanceof DebugClassLoader) {
|
||||
if ($function[0] instanceof DebugClassLoader || $function[0] instanceof LegacyDebugClassLoader) {
|
||||
$function = $function[0]->getClassLoader();
|
||||
}
|
||||
|
||||
if (is_array($function) && $function[0] instanceof ClassLoader) {
|
||||
if (\is_array($function) && $function[0] instanceof ClassLoader) {
|
||||
$classes += array_filter($function[0]->getClassMap());
|
||||
}
|
||||
}
|
||||
@@ -112,19 +105,19 @@ class AddAnnotatedClassesToCachePass implements CompilerPassInterface
|
||||
return array_keys($classes);
|
||||
}
|
||||
|
||||
private function patternsToRegexps($patterns)
|
||||
private function patternsToRegexps(array $patterns): array
|
||||
{
|
||||
$regexps = array();
|
||||
$regexps = [];
|
||||
|
||||
foreach ($patterns as $pattern) {
|
||||
// Escape user input
|
||||
$regex = preg_quote(ltrim($pattern, '\\'));
|
||||
|
||||
// Wildcards * and **
|
||||
$regex = strtr($regex, array('\\*\\*' => '.*?', '\\*' => '[^\\\\]*?'));
|
||||
$regex = strtr($regex, ['\\*\\*' => '.*?', '\\*' => '[^\\\\]*?']);
|
||||
|
||||
// If this class does not end by a slash, anchor the end
|
||||
if (substr($regex, -1) !== '\\') {
|
||||
if ('\\' !== substr($regex, -1)) {
|
||||
$regex .= '$';
|
||||
}
|
||||
|
||||
@@ -134,12 +127,12 @@ class AddAnnotatedClassesToCachePass implements CompilerPassInterface
|
||||
return $regexps;
|
||||
}
|
||||
|
||||
private function matchAnyRegexps($class, $regexps)
|
||||
private function matchAnyRegexps(string $class, array $regexps): bool
|
||||
{
|
||||
$blacklisted = false !== strpos($class, 'Test');
|
||||
$isTest = str_contains($class, 'Test');
|
||||
|
||||
foreach ($regexps as $regex) {
|
||||
if ($blacklisted && false === strpos($regex, 'Test')) {
|
||||
if ($isTest && !str_contains($regex, 'Test')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\AddClassesToCachePass class is deprecated since version 3.3 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Sets the classes to compile in the cache for the container.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class AddClassesToCachePass extends AddAnnotatedClassesToCachePass
|
||||
{
|
||||
}
|
||||
@@ -37,9 +37,6 @@ abstract class ConfigurableExtension extends Extension
|
||||
|
||||
/**
|
||||
* Configures the passed container according to the merged configuration.
|
||||
*
|
||||
* @param array $mergedConfig
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
abstract protected function loadInternal(array $mergedConfig, ContainerBuilder $container);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
/**
|
||||
* Gathers and configures the argument value resolvers.
|
||||
@@ -25,24 +28,26 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface
|
||||
{
|
||||
use PriorityTaggedServiceTrait;
|
||||
|
||||
private $argumentResolverService;
|
||||
private $argumentValueResolverTag;
|
||||
|
||||
public function __construct($argumentResolverService = 'argument_resolver', $argumentValueResolverTag = 'controller.argument_value_resolver')
|
||||
{
|
||||
$this->argumentResolverService = $argumentResolverService;
|
||||
$this->argumentValueResolverTag = $argumentValueResolverTag;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition($this->argumentResolverService)) {
|
||||
if (!$container->hasDefinition('argument_resolver')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$resolvers = $this->findAndSortTaggedServices('controller.argument_value_resolver', $container);
|
||||
|
||||
if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class) && $container->has('debug.stopwatch')) {
|
||||
foreach ($resolvers as $resolverReference) {
|
||||
$id = (string) $resolverReference;
|
||||
$container->register("debug.$id", TraceableValueResolver::class)
|
||||
->setDecoratedService($id)
|
||||
->setArguments([new Reference("debug.$id.inner"), new Reference('debug.stopwatch')]);
|
||||
}
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition($this->argumentResolverService)
|
||||
->replaceArgument(1, new IteratorArgument($this->findAndSortTaggedServices($this->argumentValueResolverTag, $container)))
|
||||
->getDefinition('argument_resolver')
|
||||
->replaceArgument(1, new IteratorArgument($resolvers))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,51 +20,16 @@ use Symfony\Component\DependencyInjection\Extension\Extension as BaseExtension;
|
||||
*/
|
||||
abstract class Extension extends BaseExtension
|
||||
{
|
||||
private $classes = array();
|
||||
private $annotatedClasses = array();
|
||||
|
||||
/**
|
||||
* Gets the classes to cache.
|
||||
*
|
||||
* @return array An array of classes
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function getClassesToCompile()
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since version 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return $this->classes;
|
||||
}
|
||||
private array $annotatedClasses = [];
|
||||
|
||||
/**
|
||||
* Gets the annotated classes to cache.
|
||||
*
|
||||
* @return array An array of classes
|
||||
*/
|
||||
public function getAnnotatedClassesToCompile()
|
||||
public function getAnnotatedClassesToCompile(): array
|
||||
{
|
||||
return $this->annotatedClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds classes to the class cache.
|
||||
*
|
||||
* @param array $classes An array of class patterns
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function addClassesToCompile(array $classes)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since version 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->classes = array_merge($this->classes, $classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds annotated classes to the class cache.
|
||||
*
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
|
||||
@@ -25,28 +25,15 @@ use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
|
||||
*/
|
||||
class FragmentRendererPass implements CompilerPassInterface
|
||||
{
|
||||
private $handlerService;
|
||||
private $rendererTag;
|
||||
|
||||
/**
|
||||
* @param string $handlerService Service name of the fragment handler in the container
|
||||
* @param string $rendererTag Tag name used for fragments
|
||||
*/
|
||||
public function __construct($handlerService = 'fragment.handler', $rendererTag = 'kernel.fragment_renderer')
|
||||
{
|
||||
$this->handlerService = $handlerService;
|
||||
$this->rendererTag = $rendererTag;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition($this->handlerService)) {
|
||||
if (!$container->hasDefinition('fragment.handler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition($this->handlerService);
|
||||
$renderers = array();
|
||||
foreach ($container->findTaggedServiceIds($this->rendererTag, true) as $id => $tags) {
|
||||
$definition = $container->getDefinition('fragment.handler');
|
||||
$renderers = [];
|
||||
foreach ($container->findTaggedServiceIds('kernel.fragment_renderer', true) as $id => $tags) {
|
||||
$def = $container->getDefinition($id);
|
||||
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
|
||||
/**
|
||||
@@ -23,54 +24,24 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
class LazyLoadingFragmentHandler extends FragmentHandler
|
||||
{
|
||||
private $container;
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
private $rendererIds = array();
|
||||
private $initialized = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ContainerInterface $container A container
|
||||
* @param RequestStack $requestStack The Request stack that controls the lifecycle of requests
|
||||
* @param bool $debug Whether the debug mode is enabled or not
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
public function __construct(ContainerInterface $container, RequestStack $requestStack, $debug = false)
|
||||
private array $initialized = [];
|
||||
|
||||
public function __construct(ContainerInterface $container, RequestStack $requestStack, bool $debug = false)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
parent::__construct($requestStack, array(), $debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a service as a fragment renderer.
|
||||
*
|
||||
* @param string $name The service name
|
||||
* @param string $renderer The render service id
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
public function addRendererService($name, $renderer)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->rendererIds[$name] = $renderer;
|
||||
parent::__construct($requestStack, [], $debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($uri, $renderer = 'inline', array $options = array())
|
||||
public function render(string|ControllerReference $uri, string $renderer = 'inline', array $options = []): ?string
|
||||
{
|
||||
// BC 3.x, to be removed in 4.0
|
||||
if (isset($this->rendererIds[$renderer])) {
|
||||
$this->addRenderer($this->container->get($this->rendererIds[$renderer]));
|
||||
unset($this->rendererIds[$renderer]);
|
||||
|
||||
return parent::render($uri, $renderer, $options);
|
||||
}
|
||||
|
||||
if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
|
||||
$this->addRenderer($this->container->get($renderer));
|
||||
$this->initialized[$renderer] = true;
|
||||
|
||||
41
vendor/symfony/http-kernel/DependencyInjection/LoggerPass.php
vendored
Normal file
41
vendor/symfony/http-kernel/DependencyInjection/LoggerPass.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Log\Logger;
|
||||
|
||||
/**
|
||||
* Registers the default logger if necessary.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class LoggerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$container->setAlias(LoggerInterface::class, 'logger')
|
||||
->setPublic(false);
|
||||
|
||||
if ($container->has('logger')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$container->register('logger', Logger::class)
|
||||
->setPublic(false);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,11 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
*/
|
||||
class MergeExtensionConfigurationPass extends BaseMergeExtensionConfigurationPass
|
||||
{
|
||||
private $extensions;
|
||||
private array $extensions;
|
||||
|
||||
/**
|
||||
* @param string[] $extensions
|
||||
*/
|
||||
public function __construct(array $extensions)
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
@@ -31,8 +34,8 @@ class MergeExtensionConfigurationPass extends BaseMergeExtensionConfigurationPas
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
foreach ($this->extensions as $extension) {
|
||||
if (!count($container->getExtensionConfig($extension))) {
|
||||
$container->loadFromExtension($extension, array());
|
||||
if (!\count($container->getExtensionConfig($extension))) {
|
||||
$container->loadFromExtension($extension, []);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Target;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
|
||||
@@ -22,6 +23,9 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* Creates the service-locators required by ServiceValueResolver.
|
||||
@@ -30,33 +34,34 @@ use Symfony\Component\DependencyInjection\TypedReference;
|
||||
*/
|
||||
class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
{
|
||||
private $resolverServiceId;
|
||||
private $controllerTag;
|
||||
|
||||
public function __construct($resolverServiceId = 'argument_resolver.service', $controllerTag = 'controller.service_arguments')
|
||||
{
|
||||
$this->resolverServiceId = $resolverServiceId;
|
||||
$this->controllerTag = $controllerTag;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (false === $container->hasDefinition($this->resolverServiceId)) {
|
||||
if (!$container->hasDefinition('argument_resolver.service') && !$container->hasDefinition('argument_resolver.not_tagged_controller')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parameterBag = $container->getParameterBag();
|
||||
$controllers = array();
|
||||
$controllers = [];
|
||||
|
||||
foreach ($container->findTaggedServiceIds($this->controllerTag, true) as $id => $tags) {
|
||||
$publicAliases = [];
|
||||
foreach ($container->getAliases() as $id => $alias) {
|
||||
if ($alias->isPublic() && !$alias->isPrivate()) {
|
||||
$publicAliases[(string) $alias][] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($container->findTaggedServiceIds('controller.service_arguments', true) as $id => $tags) {
|
||||
$def = $container->getDefinition($id);
|
||||
$def->setPublic(true);
|
||||
$class = $def->getClass();
|
||||
$autowire = $def->isAutowired();
|
||||
$bindings = $def->getBindings();
|
||||
|
||||
// resolve service class, taking parent definitions into account
|
||||
while (!$class && $def instanceof ChildDefinition) {
|
||||
while ($def instanceof ChildDefinition) {
|
||||
$def = $container->findDefinition($def->getParent());
|
||||
$class = $def->getClass();
|
||||
$class = $class ?: $def->getClass();
|
||||
$bindings += $def->getBindings();
|
||||
}
|
||||
$class = $parameterBag->resolveValue($class);
|
||||
|
||||
@@ -66,14 +71,14 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
$isContainerAware = $r->implementsInterface(ContainerAwareInterface::class) || is_subclass_of($class, AbstractController::class);
|
||||
|
||||
// get regular public methods
|
||||
$methods = array();
|
||||
$arguments = array();
|
||||
$methods = [];
|
||||
$arguments = [];
|
||||
foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $r) {
|
||||
if ('setContainer' === $r->name && $isContainerAware) {
|
||||
continue;
|
||||
}
|
||||
if (!$r->isConstructor() && !$r->isDestructor() && !$r->isAbstract()) {
|
||||
$methods[strtolower($r->name)] = array($r, $r->getParameters());
|
||||
$methods[strtolower($r->name)] = [$r, $r->getParameters()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,15 +88,15 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
$autowire = true;
|
||||
continue;
|
||||
}
|
||||
foreach (array('action', 'argument', 'id') as $k) {
|
||||
foreach (['action', 'argument', 'id'] as $k) {
|
||||
if (!isset($attributes[$k][0])) {
|
||||
throw new InvalidArgumentException(sprintf('Missing "%s" attribute on tag "%s" %s for service "%s".', $k, $this->controllerTag, json_encode($attributes, JSON_UNESCAPED_UNICODE), $id));
|
||||
throw new InvalidArgumentException(sprintf('Missing "%s" attribute on tag "controller.service_arguments" %s for service "%s".', $k, json_encode($attributes, \JSON_UNESCAPED_UNICODE), $id));
|
||||
}
|
||||
}
|
||||
if (!isset($methods[$action = strtolower($attributes['action'])])) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid "action" attribute on tag "%s" for service "%s": no public "%s()" method found on class "%s".', $this->controllerTag, $id, $attributes['action'], $class));
|
||||
throw new InvalidArgumentException(sprintf('Invalid "action" attribute on tag "controller.service_arguments" for service "%s": no public "%s()" method found on class "%s".', $id, $attributes['action'], $class));
|
||||
}
|
||||
list($r, $parameters) = $methods[$action];
|
||||
[$r, $parameters] = $methods[$action];
|
||||
$found = false;
|
||||
|
||||
foreach ($parameters as $p) {
|
||||
@@ -105,30 +110,55 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid "%s" tag for service "%s": method "%s()" has no "%s" argument on class "%s".', $this->controllerTag, $id, $r->name, $attributes['argument'], $class));
|
||||
throw new InvalidArgumentException(sprintf('Invalid "controller.service_arguments" tag for service "%s": method "%s()" has no "%s" argument on class "%s".', $id, $r->name, $attributes['argument'], $class));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($methods as list($r, $parameters)) {
|
||||
foreach ($methods as [$r, $parameters]) {
|
||||
/** @var \ReflectionMethod $r */
|
||||
|
||||
// create a per-method map of argument-names to service/type-references
|
||||
$args = array();
|
||||
$args = [];
|
||||
foreach ($parameters as $p) {
|
||||
/** @var \ReflectionParameter $p */
|
||||
$type = $target = ProxyHelper::getTypeHint($r, $p, true);
|
||||
$type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\');
|
||||
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
|
||||
|
||||
if (isset($arguments[$r->name][$p->name])) {
|
||||
$target = $arguments[$r->name][$p->name];
|
||||
if ('?' !== $target[0]) {
|
||||
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
$invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
|
||||
} elseif ('' === $target = (string) substr($target, 1)) {
|
||||
throw new InvalidArgumentException(sprintf('A "%s" tag must have non-empty "id" attributes for service "%s".', $this->controllerTag, $id));
|
||||
throw new InvalidArgumentException(sprintf('A "controller.service_arguments" tag must have non-empty "id" attributes for service "%s".', $id));
|
||||
} elseif ($p->allowsNull() && !$p->isOptional()) {
|
||||
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
|
||||
}
|
||||
} elseif (!$type || !$autowire) {
|
||||
} elseif (isset($bindings[$bindingName = $type.' $'.$name = Target::parseName($p)]) || isset($bindings[$bindingName = '$'.$name]) || isset($bindings[$bindingName = $type])) {
|
||||
$binding = $bindings[$bindingName];
|
||||
|
||||
[$bindingValue, $bindingId, , $bindingType, $bindingFile] = $binding->getValues();
|
||||
$binding->setValues([$bindingValue, $bindingId, true, $bindingType, $bindingFile]);
|
||||
|
||||
if (!$bindingValue instanceof Reference) {
|
||||
$args[$p->name] = new Reference('.value.'.$container->hash($bindingValue));
|
||||
$container->register((string) $args[$p->name], 'mixed')
|
||||
->setFactory('current')
|
||||
->addArgument([$bindingValue]);
|
||||
} else {
|
||||
$args[$p->name] = $bindingValue;
|
||||
}
|
||||
|
||||
continue;
|
||||
} elseif (!$type || !$autowire || '\\' !== $target[0]) {
|
||||
continue;
|
||||
} elseif (is_subclass_of($type, \UnitEnum::class)) {
|
||||
// do not attempt to register enum typed arguments if not already present in bindings
|
||||
continue;
|
||||
} elseif (!$p->allowsNull()) {
|
||||
$invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
if (Request::class === $type || SessionInterface::class === $type || Response::class === $type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -140,19 +170,38 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
$message .= ' Did you forget to add a use statement?';
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException($message);
|
||||
}
|
||||
$container->register($erroredId = '.errored.'.$container->hash($message), $type)
|
||||
->addError($message);
|
||||
|
||||
$args[$p->name] = $type ? new TypedReference($target, $type, $r->class, $invalidBehavior) : new Reference($target, $invalidBehavior);
|
||||
$args[$p->name] = new Reference($erroredId, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE);
|
||||
} else {
|
||||
$target = ltrim($target, '\\');
|
||||
$args[$p->name] = $type ? new TypedReference($target, $type, $invalidBehavior, Target::parseName($p)) : new Reference($target, $invalidBehavior);
|
||||
}
|
||||
}
|
||||
// register the maps as a per-method service-locators
|
||||
if ($args) {
|
||||
$controllers[$id.':'.$r->name] = ServiceLocatorTagPass::register($container, $args);
|
||||
$controllers[$id.'::'.$r->name] = ServiceLocatorTagPass::register($container, $args);
|
||||
|
||||
foreach ($publicAliases[$id] ?? [] as $alias) {
|
||||
$controllers[$alias.'::'.$r->name] = clone $controllers[$id.'::'.$r->name];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container->getDefinition($this->resolverServiceId)
|
||||
->replaceArgument(0, ServiceLocatorTagPass::register($container, $controllers));
|
||||
$controllerLocatorRef = ServiceLocatorTagPass::register($container, $controllers);
|
||||
|
||||
if ($container->hasDefinition('argument_resolver.service')) {
|
||||
$container->getDefinition('argument_resolver.service')
|
||||
->replaceArgument(0, $controllerLocatorRef);
|
||||
}
|
||||
|
||||
if ($container->hasDefinition('argument_resolver.not_tagged_controller')) {
|
||||
$container->getDefinition('argument_resolver.not_tagged_controller')
|
||||
->replaceArgument(0, $controllerLocatorRef);
|
||||
}
|
||||
|
||||
$container->setAlias('argument_resolver.controller_locator', (string) $controllerLocatorRef);
|
||||
}
|
||||
}
|
||||
|
||||
49
vendor/symfony/http-kernel/DependencyInjection/RegisterLocaleAwareServicesPass.php
vendored
Normal file
49
vendor/symfony/http-kernel/DependencyInjection/RegisterLocaleAwareServicesPass.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Register all services that have the "kernel.locale_aware" tag into the listener.
|
||||
*
|
||||
* @author Pierre Bobiet <pierrebobiet@gmail.com>
|
||||
*/
|
||||
class RegisterLocaleAwareServicesPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('locale_aware_listener')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$services = [];
|
||||
|
||||
foreach ($container->findTaggedServiceIds('kernel.locale_aware') as $id => $tags) {
|
||||
$services[] = new Reference($id);
|
||||
}
|
||||
|
||||
if (!$services) {
|
||||
$container->removeDefinition('locale_aware_listener');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition('locale_aware_listener')
|
||||
->setArgument(0, new IteratorArgument($services))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -21,21 +21,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
*/
|
||||
class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
{
|
||||
private $resolverServiceId;
|
||||
|
||||
public function __construct($resolverServiceId = 'argument_resolver.service')
|
||||
{
|
||||
$this->resolverServiceId = $resolverServiceId;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (false === $container->hasDefinition($this->resolverServiceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$serviceResolver = $container->getDefinition($this->resolverServiceId);
|
||||
$controllerLocator = $container->getDefinition((string) $serviceResolver->getArgument(0));
|
||||
$controllerLocator = $container->findDefinition('argument_resolver.controller_locator');
|
||||
$controllers = $controllerLocator->getArgument(0);
|
||||
|
||||
foreach ($controllers as $controller => $argumentRef) {
|
||||
@@ -47,19 +35,23 @@ class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
} else {
|
||||
// any methods listed for call-at-instantiation cannot be actions
|
||||
$reason = false;
|
||||
$action = substr(strrchr($controller, ':'), 1);
|
||||
$id = substr($controller, 0, -1 - strlen($action));
|
||||
[$id, $action] = explode('::', $controller);
|
||||
|
||||
if ($container->hasAlias($id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$controllerDef = $container->getDefinition($id);
|
||||
foreach ($controllerDef->getMethodCalls() as list($method, $args)) {
|
||||
foreach ($controllerDef->getMethodCalls() as [$method]) {
|
||||
if (0 === strcasecmp($action, $method)) {
|
||||
$reason = sprintf('Removing method "%s" of service "%s" from controller candidates: the method is called at instantiation, thus cannot be an action.', $action, $id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$reason) {
|
||||
if ($controllerDef->getClass() === $id) {
|
||||
$controllers[$id.'::'.$action] = $argumentRef;
|
||||
}
|
||||
// see Symfony\Component\HttpKernel\Controller\ContainerControllerResolver
|
||||
$controllers[$id.':'.$action] = $argumentRef;
|
||||
|
||||
if ('__invoke' === $action) {
|
||||
$controllers[$id] = $argumentRef;
|
||||
}
|
||||
|
||||
68
vendor/symfony/http-kernel/DependencyInjection/ResettableServicePass.php
vendored
Normal file
68
vendor/symfony/http-kernel/DependencyInjection/ResettableServicePass.php
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @author Alexander M. Turek <me@derrabus.de>
|
||||
*/
|
||||
class ResettableServicePass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->has('services_resetter')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$services = $methods = [];
|
||||
|
||||
foreach ($container->findTaggedServiceIds('kernel.reset', true) as $id => $tags) {
|
||||
$services[$id] = new Reference($id, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE);
|
||||
|
||||
foreach ($tags as $attributes) {
|
||||
if (!isset($attributes['method'])) {
|
||||
throw new RuntimeException(sprintf('Tag "kernel.reset" requires the "method" attribute to be set on service "%s".', $id));
|
||||
}
|
||||
|
||||
if (!isset($methods[$id])) {
|
||||
$methods[$id] = [];
|
||||
}
|
||||
|
||||
if ('ignore' === ($attributes['on_invalid'] ?? null)) {
|
||||
$attributes['method'] = '?'.$attributes['method'];
|
||||
}
|
||||
|
||||
$methods[$id][] = $attributes['method'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$services) {
|
||||
$container->removeAlias('services_resetter');
|
||||
$container->removeDefinition('services_resetter');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$container->findDefinition('services_resetter')
|
||||
->setArgument(0, new IteratorArgument($services))
|
||||
->setArgument(1, $methods);
|
||||
}
|
||||
}
|
||||
51
vendor/symfony/http-kernel/DependencyInjection/ServicesResetter.php
vendored
Normal file
51
vendor/symfony/http-kernel/DependencyInjection/ServicesResetter.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
||||
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
/**
|
||||
* Resets provided services.
|
||||
*
|
||||
* @author Alexander M. Turek <me@derrabus.de>
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ServicesResetter implements ResetInterface
|
||||
{
|
||||
private \Traversable $resettableServices;
|
||||
private array $resetMethods;
|
||||
|
||||
/**
|
||||
* @param \Traversable<string, object> $resettableServices
|
||||
* @param array<string, string|string[]> $resetMethods
|
||||
*/
|
||||
public function __construct(\Traversable $resettableServices, array $resetMethods)
|
||||
{
|
||||
$this->resettableServices = $resettableServices;
|
||||
$this->resetMethods = $resetMethods;
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
foreach ($this->resettableServices as $id => $service) {
|
||||
foreach ((array) $this->resetMethods[$id] as $resetMethod) {
|
||||
if ('?' === $resetMethod[0] && !method_exists($service, $resetMethod = substr($resetMethod, 1))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$service->$resetMethod();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user