diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index c25b547e21..885d5e0af2 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -602,7 +602,7 @@ Workflow * `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead. * `WorkflowInterface::apply()` has a third argument: `array $context = []`. * `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`. - * Removed support of `initial_place`. Use `initial_places` instead. + * Removed support of `initial_place`. Use `initial_marking` instead. * `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead. * `DefinitionBuilder::setInitialPlace()` has been removed, use `DefinitionBuilder::setInitialPlaces()` instead. diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php b/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php index 037d0f067c..a1660aea71 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php @@ -36,7 +36,14 @@ class HttpCache extends BaseHttpCache $this->kernel = $kernel; $this->cacheDir = $cacheDir; - parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge(['debug' => $kernel->isDebug()], $this->getOptions())); + $isDebug = $kernel->isDebug(); + $options = ['debug' => $isDebug]; + + if ($isDebug) { + $options['stale_if_error'] = 0; + } + + parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($options, $this->getOptions())); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php b/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php index 883a68613c..047d8d5804 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php +++ b/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php @@ -47,7 +47,9 @@ class SodiumVault extends AbstractVault implements EnvVarLoaderInterface $this->lastMessage = null; if (null === $this->encryptionKey && '' !== $this->decryptionKey = (string) $this->decryptionKey) { - throw new \LogicException('Cannot generate keys when a decryption key has been provided while instantiating the vault.'); + $this->lastMessage = 'Cannot generate keys when a decryption key has been provided while instantiating the vault.'; + + return false; } try { diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php b/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php index 62be170ddc..e7f9df1221 100644 --- a/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php +++ b/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php @@ -12,7 +12,10 @@ namespace Symfony\Bundle\SecurityBundle\Debug; use Symfony\Bundle\SecurityBundle\EventListener\FirewallListener; +use Symfony\Bundle\SecurityBundle\Security\FirewallContext; +use Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext; use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\Security\Http\Firewall\AbstractListener; /** * Firewall collecting called listeners. @@ -21,7 +24,7 @@ use Symfony\Component\HttpKernel\Event\RequestEvent; */ final class TraceableFirewallListener extends FirewallListener { - private $wrappedListeners; + private $wrappedListeners = []; public function getWrappedListeners() { @@ -30,14 +33,47 @@ final class TraceableFirewallListener extends FirewallListener protected function callListeners(RequestEvent $event, iterable $listeners) { + $wrappedListeners = []; + $wrappedLazyListeners = []; + foreach ($listeners as $listener) { - $wrappedListener = new WrappedListener($listener); - $wrappedListener($event); - $this->wrappedListeners[] = $wrappedListener->getInfo(); + if ($listener instanceof LazyFirewallContext) { + \Closure::bind(function () use (&$wrappedLazyListeners, &$wrappedListeners) { + $listeners = []; + foreach ($this->listeners as $listener) { + if ($listener instanceof AbstractListener) { + $listener = new WrappedLazyListener($listener); + $listeners[] = $listener; + $wrappedLazyListeners[] = $listener; + } else { + $listeners[] = function (RequestEvent $event) use ($listener, &$wrappedListeners) { + $wrappedListener = new WrappedListener($listener); + $wrappedListener($event); + $wrappedListeners[] = $wrappedListener->getInfo(); + }; + } + } + $this->listeners = $listeners; + }, $listener, FirewallContext::class)(); + + $listener($event); + } else { + $wrappedListener = $listener instanceof AbstractListener ? new WrappedLazyListener($listener) : new WrappedListener($listener); + $wrappedListener($event); + $wrappedListeners[] = $wrappedListener->getInfo(); + } if ($event->hasResponse()) { break; } } + + if ($wrappedLazyListeners) { + foreach ($wrappedLazyListeners as $lazyListener) { + $this->wrappedListeners[] = $lazyListener->getInfo(); + } + } + + $this->wrappedListeners = array_merge($this->wrappedListeners, $wrappedListeners); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/TraceableListenerTrait.php b/src/Symfony/Bundle/SecurityBundle/Debug/TraceableListenerTrait.php new file mode 100644 index 0000000000..4f889f485c --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Debug/TraceableListenerTrait.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Debug; + +/** + * @author Robin Chalas + * + * @internal + */ +trait TraceableListenerTrait +{ + private $response; + private $listener; + private $time; + private $stub; + + /** + * Proxies all method calls to the original listener. + */ + public function __call(string $method, array $arguments) + { + return $this->listener->{$method}(...$arguments); + } + + public function getWrappedListener() + { + return $this->listener; + } +} diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedLazyListener.php b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedLazyListener.php new file mode 100644 index 0000000000..736e8e8a25 --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedLazyListener.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Debug; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\Security\Core\Exception\LazyResponseException; +use Symfony\Component\Security\Http\Firewall\AbstractListener; +use Symfony\Component\VarDumper\Caster\ClassStub; + +/** + * Wraps a lazy security listener. + * + * @author Robin Chalas + * + * @internal + */ +final class WrappedLazyListener extends AbstractListener +{ + use TraceableListenerTrait; + + public function __construct(AbstractListener $listener) + { + $this->listener = $listener; + } + + public function supports(Request $request): ?bool + { + return $this->listener->supports($request); + } + + /** + * {@inheritdoc} + */ + public function authenticate(RequestEvent $event) + { + $startTime = microtime(true); + + try { + $ret = $this->listener->authenticate($event); + } catch (LazyResponseException $e) { + $this->response = $e->getResponse(); + + throw $e; + } finally { + $this->time = microtime(true) - $startTime; + } + + $this->response = $event->getResponse(); + + return $ret; + } + + public function getInfo(): array + { + return [ + 'response' => $this->response, + 'time' => $this->time, + 'stub' => $this->stub ?? $this->stub = ClassStub::wrapCallable($this->listener), + ]; + } +} diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php index 6cdb04773c..11b921627f 100644 --- a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php +++ b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php @@ -23,11 +23,7 @@ use Symfony\Component\VarDumper\Caster\ClassStub; */ final class WrappedListener { - private $response; - private $listener; - private $time; - private $stub; - private static $hasVarDumper; + use TraceableListenerTrait; public function __construct(callable $listener) { @@ -42,46 +38,12 @@ final class WrappedListener $this->response = $event->getResponse(); } - /** - * Proxies all method calls to the original listener. - */ - public function __call(string $method, array $arguments) - { - return $this->listener->{$method}(...$arguments); - } - - public function getWrappedListener(): callable - { - return $this->listener; - } - public function getInfo(): array { - if (null !== $this->stub) { - // no-op - } elseif (self::$hasVarDumper ?? self::$hasVarDumper = class_exists(ClassStub::class)) { - $this->stub = ClassStub::wrapCallable($this->listener); - } elseif (\is_array($this->listener)) { - $this->stub = (\is_object($this->listener[0]) ? \get_class($this->listener[0]) : $this->listener[0]).'::'.$this->listener[1]; - } elseif ($this->listener instanceof \Closure) { - $r = new \ReflectionFunction($this->listener); - if (false !== strpos($r->name, '{closure}')) { - $this->stub = 'closure'; - } elseif ($class = $r->getClosureScopeClass()) { - $this->stub = $class->name.'::'.$r->name; - } else { - $this->stub = $r->name; - } - } elseif (\is_string($this->listener)) { - $this->stub = $this->listener; - } else { - $this->stub = \get_class($this->listener).'::__invoke'; - } - return [ 'response' => $this->response, 'time' => $this->time, - 'stub' => $this->stub, + 'stub' => $this->stub ?? $this->stub = ClassStub::wrapCallable($this->listener), ]; } } diff --git a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php index 01400c86ba..86ab270cd8 100644 --- a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php +++ b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php @@ -35,6 +35,8 @@ trait FilesystemCommonTrait throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0])); } $directory .= \DIRECTORY_SEPARATOR.$namespace; + } else { + $directory .= \DIRECTORY_SEPARATOR.'@'; } if (!file_exists($directory)) { @mkdir($directory, 0777, true); diff --git a/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php index b7a26f9508..467f38b6d4 100644 --- a/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php @@ -145,13 +145,13 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest ); $this->assertOutputContains(<< EOT - , $output); + , $output, true); } public function testChoiceQuestionCustomPrompt() @@ -168,9 +168,9 @@ EOT $this->assertOutputContains(<<ccc> + >ccc> EOT - , $output); + , $output, true); } protected function getInputStream($input) @@ -200,10 +200,15 @@ EOT return $mock; } - private function assertOutputContains($expected, StreamOutput $output) + private function assertOutputContains($expected, StreamOutput $output, $normalize = false) { rewind($output->getStream()); $stream = stream_get_contents($output->getStream()); + + if ($normalize) { + $stream = str_replace(PHP_EOL, "\n", $stream); + } + $this->assertStringContainsString($expected, $stream); } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 6aa92da4fb..cb97f43438 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -52,7 +52,7 @@ class PassConfig new ValidateEnvPlaceholdersPass(), new ResolveChildDefinitionsPass(), new RegisterServiceSubscribersPass(), - new ResolveParameterPlaceHoldersPass(false), + new ResolveParameterPlaceHoldersPass(false, false), new ResolveFactoryClassPass(), new ResolveNamedArgumentsPass(), new AutowireRequiredMethodsPass(), diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php index 91bba7ddb1..b1c81ee3a1 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php @@ -24,10 +24,12 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass { private $bag; private $resolveArrays; + private $throwOnResolveException; - public function __construct(bool $resolveArrays = true) + public function __construct($resolveArrays = true, $throwOnResolveException = true) { $this->resolveArrays = $resolveArrays; + $this->throwOnResolveException = $throwOnResolveException; } /** @@ -61,7 +63,16 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass protected function processValue($value, bool $isRoot = false) { if (\is_string($value)) { - $v = $this->bag->resolveValue($value); + try { + $v = $this->bag->resolveValue($value); + } catch (ParameterNotFoundException $e) { + if ($this->throwOnResolveException) { + throw $e; + } + + $v = null; + $this->container->getDefinition($this->currentId)->addError($e->getMessage()); + } return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php index b5f02de940..2504ff112c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php @@ -14,6 +14,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; class ResolveParameterPlaceHoldersPassTest extends TestCase { @@ -71,6 +72,31 @@ class ResolveParameterPlaceHoldersPassTest extends TestCase $this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue); } + public function testParameterNotFoundExceptionsIsThrown() + { + $this->expectException(ParameterNotFoundException::class); + $this->expectExceptionMessage('The service "baz_service_id" has a dependency on a non-existent parameter "non_existent_param".'); + + $containerBuilder = new ContainerBuilder(); + $definition = $containerBuilder->register('baz_service_id'); + $definition->setArgument(0, '%non_existent_param%'); + + $pass = new ResolveParameterPlaceHoldersPass(); + $pass->process($containerBuilder); + } + + public function testParameterNotFoundExceptionsIsNotThrown() + { + $containerBuilder = new ContainerBuilder(); + $definition = $containerBuilder->register('baz_service_id'); + $definition->setArgument(0, '%non_existent_param%'); + + $pass = new ResolveParameterPlaceHoldersPass(true, false); + $pass->process($containerBuilder); + + $this->assertCount(1, $definition->getErrors()); + } + private function createContainerBuilder(): ContainerBuilder { $containerBuilder = new ContainerBuilder(); diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index c0f839b9db..c639e0b585 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -240,7 +240,7 @@ class EventDispatcher implements EventDispatcherInterface $this->sorted[$eventName] = []; foreach ($this->listeners[$eventName] as &$listeners) { - foreach ($listeners as $k => $listener) { + foreach ($listeners as $k => &$listener) { if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure && 2 >= \count($listener)) { $listener[0] = $listener[0](); $listener[1] = $listener[1] ?? '__invoke';