From b5857528e0b04f6f584030090fecc7b543ce359b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 23 Mar 2011 19:24:18 +0100 Subject: [PATCH] [Routing] moved protected to private --- .../Component/Routing/Annotation/Route.php | 10 ++++----- .../Component/Routing/Annotation/Routes.php | 2 +- .../Component/Routing/CompiledRoute.php | 10 ++++----- .../Generator/Dumper/GeneratorDumper.php | 7 +++++- .../Dumper/GeneratorDumperInterface.php | 9 ++++++++ .../Generator/Dumper/PhpGeneratorDumper.php | 16 +++++++------- .../Routing/Generator/UrlGenerator.php | 5 +++-- .../Routing/Loader/AnnotationFileLoader.php | 4 ++-- .../Routing/Loader/AnnotationGlobLoader.php | 2 +- .../Routing/Loader/XmlFileLoader.php | 2 +- .../Routing/Loader/YamlFileLoader.php | 14 +----------- .../Matcher/Dumper/ApacheMatcherDumper.php | 2 +- .../Routing/Matcher/Dumper/MatcherDumper.php | 12 +++++++++- .../Matcher/Dumper/MatcherDumperInterface.php | 7 ++++++ .../Matcher/Dumper/PhpMatcherDumper.php | 10 ++++----- .../Component/Routing/Matcher/UrlMatcher.php | 3 ++- src/Symfony/Component/Routing/Route.php | 14 ++++++------ .../Component/Routing/RouteCollection.php | 4 ++-- .../Component/Routing/RouteCompiler.php | 4 ++-- src/Symfony/Component/Routing/Router.php | 16 +++++++------- .../Routing/Loader/YamlFileLoaderTest.php | 22 +------------------ 21 files changed, 88 insertions(+), 87 deletions(-) diff --git a/src/Symfony/Component/Routing/Annotation/Route.php b/src/Symfony/Component/Routing/Annotation/Route.php index 5b1c12cc81c6..516cca79bcff 100644 --- a/src/Symfony/Component/Routing/Annotation/Route.php +++ b/src/Symfony/Component/Routing/Annotation/Route.php @@ -18,11 +18,11 @@ */ class Route { - protected $pattern; - protected $name; - protected $requirements; - protected $options; - protected $defaults; + private $pattern; + private $name; + private $requirements; + private $options; + private $defaults; /** * Constructor. diff --git a/src/Symfony/Component/Routing/Annotation/Routes.php b/src/Symfony/Component/Routing/Annotation/Routes.php index 9d89276582c3..16de0686430d 100644 --- a/src/Symfony/Component/Routing/Annotation/Routes.php +++ b/src/Symfony/Component/Routing/Annotation/Routes.php @@ -18,7 +18,7 @@ */ class Routes { - protected $routes; + private $routes; /** * Constructor. diff --git a/src/Symfony/Component/Routing/CompiledRoute.php b/src/Symfony/Component/Routing/CompiledRoute.php index 384ecf5bd149..c86c9eca5b29 100644 --- a/src/Symfony/Component/Routing/CompiledRoute.php +++ b/src/Symfony/Component/Routing/CompiledRoute.php @@ -18,11 +18,11 @@ */ class CompiledRoute { - protected $route; - protected $variables; - protected $tokens; - protected $staticPrefix; - protected $regex; + private $route; + private $variables; + private $tokens; + private $staticPrefix; + private $regex; /** * Constructor. diff --git a/src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php b/src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php index 83f829e84944..d2eb91cdd6af 100644 --- a/src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php +++ b/src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php @@ -21,7 +21,7 @@ */ abstract class GeneratorDumper implements GeneratorDumperInterface { - protected $routes; + private $routes; /** * Constructor. @@ -32,4 +32,9 @@ public function __construct(RouteCollection $routes) { $this->routes = $routes; } + + public function getRoutes() + { + return $this->routes; + } } diff --git a/src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumperInterface.php b/src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumperInterface.php index bfb6263b0b75..5dc1888c63a1 100644 --- a/src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumperInterface.php +++ b/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(); } diff --git a/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php b/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php index edc57db5484d..85cad66aeeed 100644 --- a/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php +++ b/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php @@ -47,10 +47,10 @@ public function dump(array $options = array()) ; } - 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 @@ protected function addGenerator() $escapedName = str_replace('.', '__', $name); $methods[] = <<defaults; $defaultsMerge @@ -96,10 +96,10 @@ public function generate(\$name, array \$parameters, \$absolute = false) 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 @@ protected function startClass($class, $baseClass) */ class $class extends $baseClass { - static protected \$declaredRouteNames = array( + static private \$declaredRouteNames = array( $routes ); @@ -123,7 +123,7 @@ class $class extends $baseClass EOF; } - protected function addConstructor() + private function addConstructor() { return <<paths as $path) { diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index 1492aae8caf3..0675a39282c3 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -167,7 +167,7 @@ protected function validate(\DOMDocument $dom) * * @return array An array of libxml error strings */ - protected function getXmlErrors() + private function getXmlErrors() { $errors = array(); foreach (libxml_get_errors() as $error) { diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index cdf89a7b6bc9..c6b16ddd461a 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -42,7 +42,7 @@ public function load($file, $type = null) { $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 @@ protected function parseRoute(RouteCollection $collection, $name, $config, $file $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. * diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php index 4584e8ed87c9..5752d297d8f8 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php @@ -43,7 +43,7 @@ public function dump(array $options = array()) $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 diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php index 928557c2f955..20fea6c0d71a 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php @@ -21,7 +21,7 @@ */ abstract class MatcherDumper implements MatcherDumperInterface { - protected $routes; + private $routes; /** * Constructor. @@ -32,4 +32,14 @@ public function __construct(RouteCollection $routes) { $this->routes = $routes; } + + /** + * Gets the routes to dump. + * + * @return RouteCollection A RouteCollection instance + */ + public function getRoutes() + { + return $this->routes; + } } diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumperInterface.php b/src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumperInterface.php index 90c8ebaa7064..950c396089c6 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumperInterface.php +++ b/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(); } diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index f1670d67f027..5bf5f50e3afc 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -47,11 +47,11 @@ public function dump(array $options = array()) ; } - 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 @@ public function match(\$pathinfo) EOF; } - protected function startClass($class, $baseClass) + private function startClass($class, $baseClass) { return <<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)); diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index eb789313a59c..8ed7d5204ca1 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -20,8 +20,8 @@ */ class RouteCollection { - protected $routes; - protected $resources; + private $routes; + private $resources; /** * Constructor. diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index bc07fa3f9981..0bff64903e51 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -119,7 +119,7 @@ protected function postCompile() * * @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 @@ protected function compileForSeparator($separator, $regexSeparator) { } - protected function getOptions() + private function getOptions() { $options = $this->route->getOptions(); diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 8fdcfc0b9d08..5e5961d5e4eb 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -22,14 +22,14 @@ */ 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. diff --git a/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php index 04adfcf45988..e68c263166c9 100644 --- a/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Routing/Loader/YamlFileLoaderTest.php @@ -95,27 +95,7 @@ public function testLoadWithResource() */ 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; - } -} -