From 49c727984de5b853ec5c2f9e91429df7360d9d5c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 23 Nov 2015 17:51:33 -0500 Subject: [PATCH] Adding a new SelfCheckingAsseticResource for compat with 2.8-3.0+ In 2.8, the SelfCheckingResourceInterface becomes available and you must implement it for 3.0. An if statement either uses the old AsseticResource (which does not include this interface) or the new SelfCheckingAsseticResource if the interface exists. --- Config/SelfCheckingAsseticResource.php | 25 +++++++++++++++++++++++++ Routing/AsseticLoader.php | 8 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Config/SelfCheckingAsseticResource.php diff --git a/Config/SelfCheckingAsseticResource.php b/Config/SelfCheckingAsseticResource.php new file mode 100644 index 00000000..5a34b76e --- /dev/null +++ b/Config/SelfCheckingAsseticResource.php @@ -0,0 +1,25 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Config; + +use Symfony\Component\Config\Resource\SelfCheckingResourceInterface; + +/** + * Implements SelfCheckingResourceInterface required in Symfony 3.0. + * + * @author Ryan Weaver + * + * @internal + */ +class SelfCheckingAsseticResource extends AsseticResource implements SelfCheckingResourceInterface +{ +} diff --git a/Routing/AsseticLoader.php b/Routing/AsseticLoader.php index 68805cce..50d8e853 100644 --- a/Routing/AsseticLoader.php +++ b/Routing/AsseticLoader.php @@ -14,6 +14,7 @@ use Assetic\Asset\AssetInterface; use Assetic\Factory\LazyAssetManager; use Symfony\Bundle\AsseticBundle\Config\AsseticResource; +use Symfony\Bundle\AsseticBundle\Config\SelfCheckingAsseticResource; use Symfony\Component\Config\Loader\Loader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -56,7 +57,12 @@ public function load($routingResource, $type = null) $resources = array($resources); } foreach ($resources as $resource) { - $routes->addResource(new AsseticResource($resource)); + if (interface_exists('Symfony\Component\Config\Resource\SelfCheckingResourceInterface')) { + $routes->addResource(new SelfCheckingAsseticResource($resource)); + } else { + // for BC with symfony/config 2.7 and lower + $routes->addResource(new AsseticResource($resource)); + } } }