comparison 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
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
11 11
12 namespace Symfony\Component\Routing\Loader; 12 namespace Symfony\Component\Routing\Loader;
13 13
14 use Symfony\Component\Config\Loader\FileLoader; 14 use Symfony\Component\Config\Loader\FileLoader;
15 use Symfony\Component\Config\Resource\FileResource; 15 use Symfony\Component\Config\Resource\FileResource;
16 use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
16 use Symfony\Component\Routing\RouteCollection; 17 use Symfony\Component\Routing\RouteCollection;
17 18
18 /** 19 /**
19 * PhpFileLoader loads routes from a PHP file. 20 * PhpFileLoader loads routes from a PHP file.
20 * 21 *
35 public function load($file, $type = null) 36 public function load($file, $type = null)
36 { 37 {
37 $path = $this->locator->locate($file); 38 $path = $this->locator->locate($file);
38 $this->setCurrentDir(dirname($path)); 39 $this->setCurrentDir(dirname($path));
39 40
40 $collection = self::includeFile($path, $this); 41 // the closure forbids access to the private scope in the included file
42 $loader = $this;
43 $load = \Closure::bind(function ($file) use ($loader) {
44 return include $file;
45 }, null, ProtectedPhpFileLoader::class);
46
47 $result = $load($path);
48
49 if ($result instanceof \Closure) {
50 $collection = new RouteCollection();
51 $result(new RoutingConfigurator($collection, $this, $path, $file), $this);
52 } else {
53 $collection = $result;
54 }
55
41 $collection->addResource(new FileResource($path)); 56 $collection->addResource(new FileResource($path));
42 57
43 return $collection; 58 return $collection;
44 } 59 }
45 60
48 */ 63 */
49 public function supports($resource, $type = null) 64 public function supports($resource, $type = null)
50 { 65 {
51 return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type); 66 return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
52 } 67 }
68 }
53 69
54 /** 70 /**
55 * Safe include. Used for scope isolation. 71 * @internal
56 * 72 */
57 * @param string $file File to include 73 final class ProtectedPhpFileLoader extends PhpFileLoader
58 * @param PhpFileLoader $loader the loader variable is exposed to the included file below 74 {
59 *
60 * @return RouteCollection
61 */
62 private static function includeFile($file, PhpFileLoader $loader)
63 {
64 return include $file;
65 }
66 } 75 }