From 9b677f2ff365e29c3cf6f64efcc9637030e8d2cd Mon Sep 17 00:00:00 2001 From: Guilhem N Date: Thu, 29 Dec 2016 15:31:10 +0100 Subject: [PATCH] Re-add symfony 2.8 support --- .../Compiler/AddDescribersPass.php | 1 - .../Compiler/AddRouteDescribersPass.php | 1 - .../Compiler/PriorityTaggedServiceTrait.php | 55 +++++++++++++++++++ composer.json | 16 +++--- 4 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 DependencyInjection/Compiler/PriorityTaggedServiceTrait.php diff --git a/DependencyInjection/Compiler/AddDescribersPass.php b/DependencyInjection/Compiler/AddDescribersPass.php index 1d6df09..ff7173d 100644 --- a/DependencyInjection/Compiler/AddDescribersPass.php +++ b/DependencyInjection/Compiler/AddDescribersPass.php @@ -12,7 +12,6 @@ namespace Nelmio\ApiDocBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; class AddDescribersPass implements CompilerPassInterface diff --git a/DependencyInjection/Compiler/AddRouteDescribersPass.php b/DependencyInjection/Compiler/AddRouteDescribersPass.php index d1b3e23..0e0ec19 100644 --- a/DependencyInjection/Compiler/AddRouteDescribersPass.php +++ b/DependencyInjection/Compiler/AddRouteDescribersPass.php @@ -12,7 +12,6 @@ namespace Nelmio\ApiDocBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; class AddRouteDescribersPass implements CompilerPassInterface diff --git a/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php new file mode 100644 index 0000000..1d7f7e2 --- /dev/null +++ b/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Nelmio\ApiDocBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Trait that allows a generic method to find and sort service by priority option in the tag. + * + * @author Iltar van der Berg + * + * @internal extracted from Symfony, to keep sf 2.8 support. + */ +trait PriorityTaggedServiceTrait +{ + /** + * Finds all services with the given tag name and order them by their priority. + * + * The order of additions must be respected for services having the same priority, + * and knowing that the \SplPriorityQueue class does not respect the FIFO method, + * we should not use this class. + * + * @see https://bugs.php.net/bug.php?id=53710 + * @see https://bugs.php.net/bug.php?id=60926 + * + * @param string $tagName + * @param ContainerBuilder $container + * + * @return Reference[] + */ + private function findAndSortTaggedServices($tagName, ContainerBuilder $container) + { + $services = array(); + foreach ($container->findTaggedServiceIds($tagName) as $serviceId => $tags) { + foreach ($tags as $attributes) { + $priority = isset($attributes['priority']) ? $attributes['priority'] : 0; + $services[$priority][] = new Reference($serviceId); + } + } + if ($services) { + krsort($services); + $services = call_user_func_array('array_merge', $services); + } + return $services; + } +} diff --git a/composer.json b/composer.json index a97db83..e508fd0 100644 --- a/composer.json +++ b/composer.json @@ -16,17 +16,17 @@ ], "require": { "php": "~7.0|~7.1", - "symfony/framework-bundle": "^3.2", + "symfony/framework-bundle": "^2.8|^3.0", "exsyst/swagger": "~0.2.2" }, "require-dev": { - "symfony/twig-bundle": "^3.2", - "symfony/console": "^3.2", - "symfony/config": "^3.2", - "symfony/validator": "^3.2", - "symfony/property-access": "^3.2", - "symfony/browser-kit": "^3.2", - "symfony/cache": "^3.2", + "symfony/twig-bundle": "^2.8|^3.0", + "symfony/console": "^2.8|^3.0", + "symfony/config": "^2.8|^3.0", + "symfony/validator": "^2.8|^3.0", + "symfony/property-access": "^2.8|^3.0", + "symfony/browser-kit": "^2.8|^3.0", + "symfony/cache": "^3.1", "symfony/phpunit-bridge": "^3.2", "sensio/framework-extra-bundle": "^3.0", "phpunit/phpunit": "^5.4",