Ver código fonte

[Routing] moved protected to private

Fabien Potencier 14 anos atrás
pai
commit
b5857528e0

+ 5 - 5
src/Symfony/Component/Routing/Annotation/Route.php

@@ -18,11 +18,11 @@ namespace Symfony\Component\Routing\Annotation;
  */
 class Route
 {
-    protected $pattern;
-    protected $name;
-    protected $requirements;
-    protected $options;
-    protected $defaults;
+    private $pattern;
+    private $name;
+    private $requirements;
+    private $options;
+    private $defaults;
 
     /**
      * Constructor.

+ 1 - 1
src/Symfony/Component/Routing/Annotation/Routes.php

@@ -18,7 +18,7 @@ namespace Symfony\Component\Routing\Annotation;
  */
 class Routes
 {
-    protected $routes;
+    private $routes;
 
     /**
      * Constructor.

+ 5 - 5
src/Symfony/Component/Routing/CompiledRoute.php

@@ -18,11 +18,11 @@ namespace Symfony\Component\Routing;
  */
 class CompiledRoute
 {
-    protected $route;
-    protected $variables;
-    protected $tokens;
-    protected $staticPrefix;
-    protected $regex;
+    private $route;
+    private $variables;
+    private $tokens;
+    private $staticPrefix;
+    private $regex;
 
     /**
      * Constructor.

+ 6 - 1
src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php

@@ -21,7 +21,7 @@ use Symfony\Component\Routing\Route;
  */
 abstract class GeneratorDumper implements GeneratorDumperInterface
 {
-    protected $routes;
+    private $routes;
 
     /**
      * Constructor.
@@ -32,4 +32,9 @@ abstract class GeneratorDumper implements GeneratorDumperInterface
     {
         $this->routes = $routes;
     }
+
+    public function getRoutes()
+    {
+        return $this->routes;
+    }
 }

+ 9 - 0
src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumperInterface.php

@@ -11,6 +11,8 @@
 
 namespace Symfony\Component\Routing\Generator\Dumper;
 
+use Symfony\Component\Routing\RouteCollection;
+
 /**
  * GeneratorDumperInterface is the interface that all generator dumper classes must implement.
  *
@@ -31,4 +33,11 @@ interface GeneratorDumperInterface
      * @return string A PHP class representing the generator class
      */
     function dump(array $options = array());
+
+    /**
+     * Gets the routes to dump.
+     *
+     * @return RouteCollection A RouteCollection instance
+     */
+    function getRoutes();
 }

+ 8 - 8
src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

@@ -47,10 +47,10 @@ class PhpGeneratorDumper extends GeneratorDumper
         ;
     }
 
-    protected function addGenerator()
+    private function addGenerator()
     {
         $methods = array();
-        foreach ($this->routes->all() as $name => $route) {
+        foreach ($this->getRoutes()->all() as $name => $route) {
             $compiledRoute = $route->compile();
 
             $variables = str_replace("\n", '', var_export($compiledRoute->getVariables(), true));
@@ -64,7 +64,7 @@ class PhpGeneratorDumper extends GeneratorDumper
             $escapedName = str_replace('.', '__', $name);
 
             $methods[] = <<<EOF
-    protected function get{$escapedName}RouteInfo()
+    private function get{$escapedName}RouteInfo()
     {
         \$defaults = \$this->defaults;
 $defaultsMerge
@@ -96,10 +96,10 @@ $methods
 EOF;
     }
 
-    protected function startClass($class, $baseClass)
+    private function startClass($class, $baseClass)
     {
         $routes = array();
-        foreach ($this->routes->all() as $name => $route) {
+        foreach ($this->getRoutes()->all() as $name => $route) {
             $routes[] = "       '$name' => true,";
         }
         $routes  = implode("\n", $routes);
@@ -115,7 +115,7 @@ EOF;
  */
 class $class extends $baseClass
 {
-    static protected \$declaredRouteNames = array(
+    static private \$declaredRouteNames = array(
 $routes
     );
 
@@ -123,7 +123,7 @@ $routes
 EOF;
     }
 
-    protected function addConstructor()
+    private function addConstructor()
     {
         return <<<EOF
     /**
@@ -138,7 +138,7 @@ EOF;
 EOF;
     }
 
-    protected function endClass()
+    private function endClass()
     {
         return <<<EOF
 }

+ 3 - 2
src/Symfony/Component/Routing/Generator/UrlGenerator.php

@@ -21,10 +21,11 @@ use Symfony\Component\Routing\RouteCollection;
  */
 class UrlGenerator implements UrlGeneratorInterface
 {
-    protected $routes;
     protected $defaults;
     protected $context;
-    protected $cache;
+
+    private $routes;
+    private $cache;
 
     /**
      * Constructor.

+ 2 - 2
src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php

@@ -24,7 +24,7 @@ use Symfony\Component\Config\FileLocator;
  */
 class AnnotationFileLoader extends FileLoader
 {
-    protected $loader;
+    private $loader;
 
     /**
      * Constructor.
@@ -86,7 +86,7 @@ class AnnotationFileLoader extends FileLoader
      *
      * @return string|false Full class name if found, false otherwise 
      */
-    protected function findClass($file)
+    private function findClass($file)
     {
         $class = false;
         $namespace = false;

+ 1 - 1
src/Symfony/Component/Routing/Loader/AnnotationGlobLoader.php

@@ -62,7 +62,7 @@ class AnnotationGlobLoader extends AnnotationDirectoryLoader
      *
      * @return array An array of paths matching the glob pattern
      */
-    protected function getAbsolutePaths($glob)
+    private function getAbsolutePaths($glob)
     {
         $dirs = array();
         foreach ($this->paths as $path) {

+ 1 - 1
src/Symfony/Component/Routing/Loader/XmlFileLoader.php

@@ -167,7 +167,7 @@ class XmlFileLoader extends FileLoader
      *
      * @return array An array of libxml error strings
      */
-    protected function getXmlErrors()
+    private function getXmlErrors()
     {
         $errors = array();
         foreach (libxml_get_errors() as $error) {

+ 1 - 13
src/Symfony/Component/Routing/Loader/YamlFileLoader.php

@@ -42,7 +42,7 @@ class YamlFileLoader extends FileLoader
     {
         $path = $this->locator->locate($file);
 
-        $config = $this->loadFile($path);
+        $config = Yaml::load($path);
 
         $collection = new RouteCollection();
         $collection->addResource(new FileResource($path));
@@ -113,18 +113,6 @@ class YamlFileLoader extends FileLoader
         $collection->add($name, $route);
     }
 
-    /**
-     * Loads a Yaml file.
-     *
-     * @param string $file A Yaml file path
-     *
-     * @return array
-     */
-    protected function loadFile($file)
-    {
-        return Yaml::load($file);
-    }
-
     /**
      * Normalize route configuration.
      *

+ 1 - 1
src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php

@@ -43,7 +43,7 @@ class ApacheMatcherDumper extends MatcherDumper
         $rules = array("# skip \"real\" requests\nRewriteCond %{REQUEST_FILENAME} -f\nRewriteRule .* - [QSA,L]");
         $methodVars = array();
 
-        foreach ($this->routes->all() as $name => $route) {
+        foreach ($this->getRoutes()->all() as $name => $route) {
             $compiledRoute = $route->compile();
 
             // prepare the apache regex

+ 11 - 1
src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php

@@ -21,7 +21,7 @@ use Symfony\Component\Routing\Route;
  */
 abstract class MatcherDumper implements MatcherDumperInterface
 {
-    protected $routes;
+    private $routes;
 
     /**
      * Constructor.
@@ -32,4 +32,14 @@ abstract class MatcherDumper implements MatcherDumperInterface
     {
         $this->routes = $routes;
     }
+
+    /**
+     * Gets the routes to dump.
+     *
+     * @return RouteCollection A RouteCollection instance
+     */
+    public function getRoutes()
+    {
+        return $this->routes;
+    }
 }

+ 7 - 0
src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumperInterface.php

@@ -31,4 +31,11 @@ interface MatcherDumperInterface
      * @return string A PHP class representing the matcher class
      */
     function dump(array $options = array());
+
+    /**
+     * Gets the routes to match.
+     *
+     * @return RouteCollection A RouteCollection instance
+     */
+    function getRoutes();
 }

+ 5 - 5
src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

@@ -47,11 +47,11 @@ class PhpMatcherDumper extends MatcherDumper
         ;
     }
 
-    protected function addMatcher()
+    private function addMatcher()
     {
         $code = array();
 
-        foreach ($this->routes->all() as $name => $route) {
+        foreach ($this->getRoutes()->all() as $name => $route) {
             $compiledRoute = $route->compile();
 
             $conditions = array();
@@ -139,7 +139,7 @@ $code
 EOF;
     }
 
-    protected function startClass($class, $baseClass)
+    private function startClass($class, $baseClass)
     {
         return <<<EOF
 <?php
@@ -159,7 +159,7 @@ class $class extends $baseClass
 EOF;
     }
 
-    protected function addConstructor()
+    private function addConstructor()
     {
         return <<<EOF
     /**
@@ -174,7 +174,7 @@ EOF;
 EOF;
     }
 
-    protected function endClass()
+    private function endClass()
     {
         return <<<EOF
 }

+ 2 - 1
src/Symfony/Component/Routing/Matcher/UrlMatcher.php

@@ -23,10 +23,11 @@ use Symfony\Component\Routing\RouteCollection;
  */
 class UrlMatcher implements UrlMatcherInterface
 {
-    protected $routes;
     protected $defaults;
     protected $context;
 
+    private $routes;
+
     /**
      * Constructor.
      *

+ 7 - 7
src/Symfony/Component/Routing/Route.php

@@ -18,13 +18,13 @@ namespace Symfony\Component\Routing;
  */
 class Route
 {
-    protected $pattern;
-    protected $defaults;
-    protected $requirements;
-    protected $options;
-    protected $compiled;
+    private $pattern;
+    private $defaults;
+    private $requirements;
+    private $options;
+    private $compiled;
 
-    static protected $compilers = array();
+    static private $compilers = array();
 
     /**
      * Constructor.
@@ -240,7 +240,7 @@ class Route
         return $this->compiled = static::$compilers[$class]->compile($this);
     }
 
-    protected function sanitizeRequirement($key, $regex)
+    private function sanitizeRequirement($key, $regex)
     {
         if (is_array($regex)) {
             throw new \InvalidArgumentException(sprintf('Routing requirements must be a string, array given for "%s"', $key));

+ 2 - 2
src/Symfony/Component/Routing/RouteCollection.php

@@ -20,8 +20,8 @@ use Symfony\Component\Config\Resource\ResourceInterface;
  */
 class RouteCollection
 {
-    protected $routes;
-    protected $resources;
+    private $routes;
+    private $resources;
 
     /**
      * Constructor.

+ 2 - 2
src/Symfony/Component/Routing/RouteCompiler.php

@@ -119,7 +119,7 @@ class RouteCompiler implements RouteCompilerInterface
      *
      * @throws \InvalidArgumentException When route can't be parsed
      */
-    protected function tokenize()
+    private function tokenize()
     {
         $this->tokens = array();
         $buffer = $this->route->getPattern();
@@ -221,7 +221,7 @@ class RouteCompiler implements RouteCompilerInterface
     {
     }
 
-    protected function getOptions()
+    private function getOptions()
     {
         $options = $this->route->getOptions();
 

+ 8 - 8
src/Symfony/Component/Routing/Router.php

@@ -22,14 +22,14 @@ use Symfony\Component\Config\ConfigCache;
  */
 class Router implements RouterInterface
 {
-    protected $matcher;
-    protected $generator;
-    protected $options;
-    protected $defaults;
-    protected $context;
-    protected $loader;
-    protected $collection;
-    protected $resource;
+    private $matcher;
+    private $generator;
+    private $options;
+    private $defaults;
+    private $context;
+    private $loader;
+    private $collection;
+    private $resource;
 
     /**
      * Constructor.

+ 1 - 21
tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php

@@ -95,27 +95,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
      */
     public function testParseRouteThrowsExceptionWithMissingPattern()
     {
-        $loader = new CustomYamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
+        $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
         $loader->load('incomplete.yml');
     }
 }
-
-class CustomYamlFileLoader extends YamlFileLoader
-{
-    public function load($file, $type = null)
-    {
-        $path = $this->locator->locate($file);
-
-        $config = $this->loadFile($path);
-
-        $collection = new RouteCollection();
-        $collection->addResource(new FileResource($path));
-
-        foreach ($config as $name => $config) {
-            $this->parseRoute($collection, $name, $config, $path);
-        }
-
-        return $collection;
-    }
-}
-