diff vendor/symfony/routing/Loader/PhpFileLoader.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
line wrap: on
line diff
--- a/vendor/symfony/routing/Loader/PhpFileLoader.php	Mon Apr 23 09:33:26 2018 +0100
+++ b/vendor/symfony/routing/Loader/PhpFileLoader.php	Mon Apr 23 09:46:53 2018 +0100
@@ -13,6 +13,7 @@
 
 use Symfony\Component\Config\Loader\FileLoader;
 use Symfony\Component\Config\Resource\FileResource;
+use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
 use Symfony\Component\Routing\RouteCollection;
 
 /**
@@ -37,7 +38,21 @@
         $path = $this->locator->locate($file);
         $this->setCurrentDir(dirname($path));
 
-        $collection = self::includeFile($path, $this);
+        // the closure forbids access to the private scope in the included file
+        $loader = $this;
+        $load = \Closure::bind(function ($file) use ($loader) {
+            return include $file;
+        }, null, ProtectedPhpFileLoader::class);
+
+        $result = $load($path);
+
+        if ($result instanceof \Closure) {
+            $collection = new RouteCollection();
+            $result(new RoutingConfigurator($collection, $this, $path, $file), $this);
+        } else {
+            $collection = $result;
+        }
+
         $collection->addResource(new FileResource($path));
 
         return $collection;
@@ -50,17 +65,11 @@
     {
         return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
     }
+}
 
-    /**
-     * Safe include. Used for scope isolation.
-     *
-     * @param string        $file   File to include
-     * @param PhpFileLoader $loader the loader variable is exposed to the included file below
-     *
-     * @return RouteCollection
-     */
-    private static function includeFile($file, PhpFileLoader $loader)
-    {
-        return include $file;
-    }
+/**
+ * @internal
+ */
+final class ProtectedPhpFileLoader extends PhpFileLoader
+{
 }