diff --git a/bundles/CoreBundle/DependencyInjection/Compiler/LegacyTemplatePass.php b/bundles/CoreBundle/DependencyInjection/Compiler/LegacyTemplatePass.php index 57b2c1bc8f6..dccea90761c 100644 --- a/bundles/CoreBundle/DependencyInjection/Compiler/LegacyTemplatePass.php +++ b/bundles/CoreBundle/DependencyInjection/Compiler/LegacyTemplatePass.php @@ -1,50 +1,49 @@ -hasDefinition('sensio_framework_extra.view.guesser')) { - $definition = $container->getDefinition('sensio_framework_extra.view.guesser'); - $definition - ->setPublic(true) - ->setClass(LegacyTemplateGuesser::class) - ->addArgument(new Reference('templating')); - } - - - if ($container->hasDefinition('sensio_framework_extra.view.listener')) { - $definition = $container->getDefinition('sensio_framework_extra.view.listener'); - $definition - ->setClass(LegacyTemplateListener::class) - ->addMethodCall('setTemplateEngine', [ - new Reference('templating') - ]); - } - } -} +hasDefinition('sensio_framework_extra.view.guesser')) { + $definition = $container->getDefinition('sensio_framework_extra.view.guesser'); + $definition + ->setPublic(true) + ->setClass(LegacyTemplateGuesser::class) + ->addArgument(new Reference('templating')); + } + + if ($container->hasDefinition('sensio_framework_extra.view.listener')) { + $definition = $container->getDefinition('sensio_framework_extra.view.listener'); + $definition + ->setClass(LegacyTemplateListener::class) + ->addMethodCall('setTemplateEngine', [ + new Reference('templating') + ]); + } + } +} diff --git a/bundles/CoreBundle/DependencyInjection/Compiler/RoutingLoaderPass.php b/bundles/CoreBundle/DependencyInjection/Compiler/RoutingLoaderPass.php index 3d623c22893..be6a4222ef9 100644 --- a/bundles/CoreBundle/DependencyInjection/Compiler/RoutingLoaderPass.php +++ b/bundles/CoreBundle/DependencyInjection/Compiler/RoutingLoaderPass.php @@ -1,41 +1,42 @@ -hasDefinition('routing.loader.annotation')) { - return; - } - - $definition = $container->getDefinition('routing.loader.annotation'); - $definition->setClass(AnnotatedRouteControllerLoader::class); - } -} +hasDefinition('routing.loader.annotation')) { + return; + } + + $definition = $container->getDefinition('routing.loader.annotation'); + $definition->setClass(AnnotatedRouteControllerLoader::class); + } +} diff --git a/bundles/CoreBundle/DependencyInjection/PimcoreCoreExtension.php b/bundles/CoreBundle/DependencyInjection/PimcoreCoreExtension.php index 229ef83dedb..d7afc3804f0 100644 --- a/bundles/CoreBundle/DependencyInjection/PimcoreCoreExtension.php +++ b/bundles/CoreBundle/DependencyInjection/PimcoreCoreExtension.php @@ -35,7 +35,6 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Reference; diff --git a/bundles/CoreBundle/EventListener/LegacyTemplateListener.php b/bundles/CoreBundle/EventListener/LegacyTemplateListener.php index caeab376e9b..6e90194feb7 100644 --- a/bundles/CoreBundle/EventListener/LegacyTemplateListener.php +++ b/bundles/CoreBundle/EventListener/LegacyTemplateListener.php @@ -1,120 +1,118 @@ -templateEngine; - } - - /** - * @param EngineInterface $templateEngine - */ - public function setTemplateEngine(EngineInterface $templateEngine): void - { - $this->templateEngine = $templateEngine; - } - - /** - * @inheritdoc - */ - public function onKernelView(GetResponseForControllerResultEvent $event) - { - - /* @var Template $template */ - $request = $event->getRequest(); - $template = $request->attributes->get('_template'); - - if (!$template instanceof Template) { - return; - } - - - $parameters = $event->getControllerResult(); - $owner = $template->getOwner(); - list($controller, $action) = $owner; - - // when the annotation declares no default vars and the action returns - // null, all action method arguments are used as default vars - if (null === $parameters) { - $parameters = $this->resolveDefaultParameters($request, $template, $controller, $action); - } - - // attempt to render the actual response - $templating = $this->getTemplateEngine(); - - if ($template->isStreamable()) { - $callback = function () use ($templating, $template, $parameters) { - return $templating->stream($template->getTemplate(), $parameters); - }; - - $event->setResponse(new StreamedResponse($callback)); - } - - // make sure the owner (controller+dependencies) is not cached or stored elsewhere - $template->setOwner([]); - - $event->setResponse($templating->renderResponse($template->getTemplate(), $parameters)); - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() - { - return [ - KernelEvents::CONTROLLER => ['onKernelController', -128], - KernelEvents::VIEW => 'onKernelView', - ]; - } - - private function resolveDefaultParameters(Request $request, Template $template, $controller, $action) - { - $parameters = []; - $arguments = $template->getVars(); - - if (0 === \count($arguments)) { - $r = new \ReflectionObject($controller); - - $arguments = []; - foreach ($r->getMethod($action)->getParameters() as $param) { - $arguments[] = $param; - } - } - - // fetch the arguments of @Template.vars or everything if desired - // and assign them to the designated template - foreach ($arguments as $argument) { - if ($argument instanceof \ReflectionParameter) { - $parameters[$name = $argument->getName()] = !$request->attributes->has($name) && $argument->isDefaultValueAvailable() ? $argument->getDefaultValue() : $request->attributes->get($name); - } else { - $parameters[$argument] = $request->attributes->get($argument); - } - } - - return $parameters; - } -} +templateEngine; + } + + /** + * @param EngineInterface $templateEngine + */ + public function setTemplateEngine(EngineInterface $templateEngine): void + { + $this->templateEngine = $templateEngine; + } + + /** + * @inheritdoc + */ + public function onKernelView(GetResponseForControllerResultEvent $event) + { + + /* @var Template $template */ + $request = $event->getRequest(); + $template = $request->attributes->get('_template'); + + if (!$template instanceof Template) { + return; + } + + $parameters = $event->getControllerResult(); + $owner = $template->getOwner(); + list($controller, $action) = $owner; + + // when the annotation declares no default vars and the action returns + // null, all action method arguments are used as default vars + if (null === $parameters) { + $parameters = $this->resolveDefaultParameters($request, $template, $controller, $action); + } + + // attempt to render the actual response + $templating = $this->getTemplateEngine(); + + if ($template->isStreamable()) { + $callback = function () use ($templating, $template, $parameters) { + return $templating->stream($template->getTemplate(), $parameters); + }; + + $event->setResponse(new StreamedResponse($callback)); + } + + // make sure the owner (controller+dependencies) is not cached or stored elsewhere + $template->setOwner([]); + + $event->setResponse($templating->renderResponse($template->getTemplate(), $parameters)); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return [ + KernelEvents::CONTROLLER => ['onKernelController', -128], + KernelEvents::VIEW => 'onKernelView', + ]; + } + + private function resolveDefaultParameters(Request $request, Template $template, $controller, $action) + { + $parameters = []; + $arguments = $template->getVars(); + + if (0 === \count($arguments)) { + $r = new \ReflectionObject($controller); + + $arguments = []; + foreach ($r->getMethod($action)->getParameters() as $param) { + $arguments[] = $param; + } + } + + // fetch the arguments of @Template.vars or everything if desired + // and assign them to the designated template + foreach ($arguments as $argument) { + if ($argument instanceof \ReflectionParameter) { + $parameters[$name = $argument->getName()] = !$request->attributes->has($name) && $argument->isDefaultValueAvailable() ? $argument->getDefaultValue() : $request->attributes->get($name); + } else { + $parameters[$argument] = $request->attributes->get($argument); + } + } + + return $parameters; + } +} diff --git a/bundles/CoreBundle/Templating/LegacyTemplateGuesser.php b/bundles/CoreBundle/Templating/LegacyTemplateGuesser.php index 43ff00881e0..6cfac836660 100644 --- a/bundles/CoreBundle/Templating/LegacyTemplateGuesser.php +++ b/bundles/CoreBundle/Templating/LegacyTemplateGuesser.php @@ -1,146 +1,146 @@ -kernel = $kernel; - $this->controllerPatterns = $controllerPatterns; - $this->templateEngine = $templateEngine; - - parent::__construct($kernel, $controllerPatterns); - } - - /** - * @inheritdoc - */ - public function guessTemplateName($controller, Request $request, $engine = 'php') - { - //first lookup for new template name(snake_case) - //if not found then use legacy guesser template name(camelCase) - $templateReference = parent::guessTemplateName($controller, $request); - - // Only AppBundle should use templates inside app folder - if (0 === strpos($templateReference,'@') && substr(explode('/',$templateReference)[0],1) === 'App') { - $templateReference = str_replace('@App/','',$templateReference); - } - - //update view file format(not supported by Sensio), if engine is php - if($engine == 'php') { - $templateReference = str_replace('.twig','.php',$templateReference); - } - - if($this->templateEngine->exists($templateReference)) { - return $templateReference; - } - - if (is_object($controller) && method_exists($controller, '__invoke')) { - $controller = array($controller, '__invoke'); - } elseif (!is_array($controller)) { - throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, gettype($controller))); - } - $className = $this->getRealClass(\get_class($controller[0])); - - $matchController = null; - foreach ($this->controllerPatterns as $pattern) { - if (preg_match($pattern, $className, $tempMatch)) { - $matchController = $tempMatch; - break; - } - } - if (null === $matchController) { - throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (its FQN must match one of the following regexps: "%s")', \get_class($controller[0]), implode('", "', $this->controllerPatterns))); - } - - if ($controller[1] === '__invoke') { - $matchAction = $matchController; - $matchController = null; - } elseif (!preg_match('/^(.+)Action$/', $controller[1], $matchAction)) { - $matchAction = array(null, $controller[1]); - } - - $bundle = $this->getBundleForClass($className); - if ($bundle) { - while ($bundleName = $bundle->getName()) { - if (!method_exists($bundle,'getParent') || (null === $parentBundleName = $bundle->getParent())) { - $bundleName = $bundle->getName(); - break; - } - $bundles = $this->kernel->getBundle($parentBundleName, false); - $bundle = array_pop($bundles); - } - } else { - $bundleName = null; - } - - $legacyTemplateReference = new TemplateReference($bundleName, $matchController[1], $matchAction[1], $request->getRequestFormat(), $engine); - - // Only AppBundle should use templates inside app folder - if ($legacyTemplateReference->get('bundle') === 'AppBundle') { - $legacyTemplateReference->set('bundle', ''); - } - - if(!$this->templateEngine->exists($legacyTemplateReference->getLogicalName())) { - throw new \InvalidArgumentException(sprintf('The template "%s" and fallback: "%s" does not exist.',$templateReference, $legacyTemplateReference)); - } - - return $legacyTemplateReference; - } - - /** - * @inheritdoc - */ - protected function getBundleForClass($class) - { - $reflectionClass = new \ReflectionClass($class); - $bundles = $this->kernel->getBundles(); - do { - $namespace = $reflectionClass->getNamespaceName(); - foreach ($bundles as $bundle) { - if (0 === strpos($namespace, $bundle->getNamespace())) { - return $bundle; - } - } - $reflectionClass = $reflectionClass->getParentClass(); - } while ($reflectionClass); - } - - private static function getRealClass(string $class): string - { - if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) { - return $class; - } - - return substr($class, $pos + Proxy::MARKER_LENGTH + 2); - } -} +kernel = $kernel; + $this->controllerPatterns = $controllerPatterns; + $this->templateEngine = $templateEngine; + + parent::__construct($kernel, $controllerPatterns); + } + + /** + * @inheritdoc + */ + public function guessTemplateName($controller, Request $request, $engine = 'php') + { + //first lookup for new template name(snake_case) + //if not found then use legacy guesser template name(camelCase) + $templateReference = parent::guessTemplateName($controller, $request); + + // Only AppBundle should use templates inside app folder + if (0 === strpos($templateReference, '@') && substr(explode('/', $templateReference)[0], 1) === 'App') { + $templateReference = str_replace('@App/', '', $templateReference); + } + + //update view file format(not supported by Sensio), if engine is php + if ($engine == 'php') { + $templateReference = str_replace('.twig', '.php', $templateReference); + } + + if ($this->templateEngine->exists($templateReference)) { + return $templateReference; + } + + if (is_object($controller) && method_exists($controller, '__invoke')) { + $controller = [$controller, '__invoke']; + } elseif (!is_array($controller)) { + throw new \InvalidArgumentException(sprintf('First argument of %s must be an array callable or an object defining the magic method __invoke. "%s" given.', __METHOD__, gettype($controller))); + } + $className = $this->getRealClass(\get_class($controller[0])); + + $matchController = null; + foreach ($this->controllerPatterns as $pattern) { + if (preg_match($pattern, $className, $tempMatch)) { + $matchController = $tempMatch; + break; + } + } + if (null === $matchController) { + throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (its FQN must match one of the following regexps: "%s")', \get_class($controller[0]), implode('", "', $this->controllerPatterns))); + } + + if ($controller[1] === '__invoke') { + $matchAction = $matchController; + $matchController = null; + } elseif (!preg_match('/^(.+)Action$/', $controller[1], $matchAction)) { + $matchAction = [null, $controller[1]]; + } + + $bundle = $this->getBundleForClass($className); + if ($bundle) { + while ($bundleName = $bundle->getName()) { + if (!method_exists($bundle, 'getParent') || (null === $parentBundleName = $bundle->getParent())) { + $bundleName = $bundle->getName(); + break; + } + $bundles = $this->kernel->getBundle($parentBundleName, false); + $bundle = array_pop($bundles); + } + } else { + $bundleName = null; + } + + $legacyTemplateReference = new TemplateReference($bundleName, $matchController[1], $matchAction[1], $request->getRequestFormat(), $engine); + + // Only AppBundle should use templates inside app folder + if ($legacyTemplateReference->get('bundle') === 'AppBundle') { + $legacyTemplateReference->set('bundle', ''); + } + + if (!$this->templateEngine->exists($legacyTemplateReference->getLogicalName())) { + throw new \InvalidArgumentException(sprintf('The template "%s" and fallback: "%s" does not exist.', $templateReference, $legacyTemplateReference)); + } + + return $legacyTemplateReference; + } + + /** + * @inheritdoc + */ + protected function getBundleForClass($class) + { + $reflectionClass = new \ReflectionClass($class); + $bundles = $this->kernel->getBundles(); + do { + $namespace = $reflectionClass->getNamespaceName(); + foreach ($bundles as $bundle) { + if (0 === strpos($namespace, $bundle->getNamespace())) { + return $bundle; + } + } + $reflectionClass = $reflectionClass->getParentClass(); + } while ($reflectionClass); + } + + private static function getRealClass(string $class): string + { + if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) { + return $class; + } + + return substr($class, $pos + Proxy::MARKER_LENGTH + 2); + } +} diff --git a/lib/Composer.php b/lib/Composer.php index 2949dca15f2..a3f9ebdaa16 100644 --- a/lib/Composer.php +++ b/lib/Composer.php @@ -363,6 +363,4 @@ public static function clearCache(Event $event) static::executeCommand($event, $consoleDir, 'cache:clear'.$warmup, $options['process-timeout']); } - - } diff --git a/lib/Kernel.php b/lib/Kernel.php index 793104b1e6a..87827df7fb6 100644 --- a/lib/Kernel.php +++ b/lib/Kernel.php @@ -28,7 +28,6 @@ use Pimcore\HttpKernel\Config\SystemConfigParamResource; use Presta\SitemapBundle\PrestaSitemapBundle; use Scheb\TwoFactorBundle\SchebTwoFactorBundle; -use Sensio\Bundle\DistributionBundle\SensioDistributionBundle; use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle; use Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle; use Symfony\Bundle\DebugBundle\DebugBundle;