Commit 5aa6a974 authored by Igor Wiedler's avatar Igor Wiedler

refactor {routeCollection => routes}, {controllerCollection => controllers}

parent f10043eb
...@@ -36,8 +36,8 @@ use Symfony\Component\Routing\Matcher\Exception\NotFoundException; ...@@ -36,8 +36,8 @@ use Symfony\Component\Routing\Matcher\Exception\NotFoundException;
class Application extends HttpKernel implements EventSubscriberInterface class Application extends HttpKernel implements EventSubscriberInterface
{ {
private $dispatcher; private $dispatcher;
private $routeCollection; private $routes;
private $controllerCollection; private $controllers;
private $request; private $request;
/** /**
...@@ -45,8 +45,8 @@ class Application extends HttpKernel implements EventSubscriberInterface ...@@ -45,8 +45,8 @@ class Application extends HttpKernel implements EventSubscriberInterface
*/ */
public function __construct() public function __construct()
{ {
$this->routeCollection = new RouteCollection(); $this->routes = new RouteCollection();
$this->controllerCollection = new ControllerCollection($this->routeCollection); $this->controllers = new ControllerCollection($this->routes);
$this->dispatcher = new EventDispatcher(); $this->dispatcher = new EventDispatcher();
$this->dispatcher->addSubscriber($this); $this->dispatcher->addSubscriber($this);
...@@ -74,7 +74,7 @@ class Application extends HttpKernel implements EventSubscriberInterface ...@@ -74,7 +74,7 @@ class Application extends HttpKernel implements EventSubscriberInterface
*/ */
public function getRouteCollection() public function getRouteCollection()
{ {
return $this->routeCollection; return $this->routes;
} }
/** /**
...@@ -99,7 +99,7 @@ class Application extends HttpKernel implements EventSubscriberInterface ...@@ -99,7 +99,7 @@ class Application extends HttpKernel implements EventSubscriberInterface
$route = new Route($pattern, array('_controller' => $to), $requirements); $route = new Route($pattern, array('_controller' => $to), $requirements);
$controller = new Controller($route); $controller = new Controller($route);
$this->controllerCollection->add($controller); $this->controllers->add($controller);
return $controller; return $controller;
} }
...@@ -230,7 +230,7 @@ class Application extends HttpKernel implements EventSubscriberInterface ...@@ -230,7 +230,7 @@ class Application extends HttpKernel implements EventSubscriberInterface
*/ */
public function flush() public function flush()
{ {
$this->controllerCollection->flush(); $this->controllers->flush();
} }
/** /**
...@@ -254,9 +254,9 @@ class Application extends HttpKernel implements EventSubscriberInterface ...@@ -254,9 +254,9 @@ class Application extends HttpKernel implements EventSubscriberInterface
{ {
$this->request = $event->getRequest(); $this->request = $event->getRequest();
$this->controllerCollection->flush(); $this->controllers->flush();
$matcher = new UrlMatcher($this->routeCollection, array( $matcher = new UrlMatcher($this->routes, array(
'base_url' => $this->request->getBaseUrl(), 'base_url' => $this->request->getBaseUrl(),
'method' => $this->request->getMethod(), 'method' => $this->request->getMethod(),
'host' => $this->request->getHost(), 'host' => $this->request->getHost(),
......
...@@ -25,11 +25,11 @@ use Symfony\Component\Routing\RouteCollection; ...@@ -25,11 +25,11 @@ use Symfony\Component\Routing\RouteCollection;
class ControllerCollection class ControllerCollection
{ {
private $controllers = array(); private $controllers = array();
private $routeCollection; private $routes;
public function __construct(RouteCollection $routeCollection) public function __construct(RouteCollection $routes)
{ {
$this->routeCollection = $routeCollection; $this->routes = $routes;
} }
/** /**
...@@ -48,7 +48,7 @@ class ControllerCollection ...@@ -48,7 +48,7 @@ class ControllerCollection
public function flush() public function flush()
{ {
foreach ($this->controllers as $controller) { foreach ($this->controllers as $controller) {
$this->routeCollection->add($controller->getRouteName(), $controller->getRoute()); $this->routes->add($controller->getRouteName(), $controller->getRoute());
$controller->freeze(); $controller->freeze();
} }
......
...@@ -74,9 +74,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase ...@@ -74,9 +74,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
{ {
$application = new Application(); $application = new Application();
$routeCollection = $application->getRouteCollection(); $routes = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routeCollection); $this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
$this->assertEquals(0, count($routeCollection->all())); $this->assertEquals(0, count($routes->all()));
} }
public function testGetRouteCollectionWithRoutes() public function testGetRouteCollectionWithRoutes()
...@@ -91,10 +91,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase ...@@ -91,10 +91,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
return 'bar'; return 'bar';
}); });
$routeCollection = $application->getRouteCollection(); $routes = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routeCollection); $this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
$this->assertEquals(0, count($routeCollection->all())); $this->assertEquals(0, count($routes->all()));
$application->flush(); $application->flush();
$this->assertEquals(2, count($routeCollection->all())); $this->assertEquals(2, count($routes->all()));
} }
} }
...@@ -28,40 +28,40 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase ...@@ -28,40 +28,40 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
{ {
public function testGetRouteCollectionWithNoRoutes() public function testGetRouteCollectionWithNoRoutes()
{ {
$routeCollection = new RouteCollection(); $routes = new RouteCollection();
$controllerCollection = new ControllerCollection($routeCollection); $controllers = new ControllerCollection($routes);
$this->assertEquals(0, count($routeCollection->all())); $this->assertEquals(0, count($routes->all()));
$controllerCollection->flush(); $controllers->flush();
$this->assertEquals(0, count($routeCollection->all())); $this->assertEquals(0, count($routes->all()));
} }
public function testGetRouteCollectionWithRoutes() public function testGetRouteCollectionWithRoutes()
{ {
$routeCollection = new RouteCollection(); $routes = new RouteCollection();
$controllerCollection = new ControllerCollection($routeCollection); $controllers = new ControllerCollection($routes);
$controllerCollection->add(new Controller(new Route('/foo'))); $controllers->add(new Controller(new Route('/foo')));
$controllerCollection->add(new Controller(new Route('/bar'))); $controllers->add(new Controller(new Route('/bar')));
$this->assertEquals(0, count($routeCollection->all())); $this->assertEquals(0, count($routes->all()));
$controllerCollection->flush(); $controllers->flush();
$this->assertEquals(2, count($routeCollection->all())); $this->assertEquals(2, count($routes->all()));
} }
public function testControllerFreezing() public function testControllerFreezing()
{ {
$routeCollection = new RouteCollection(); $routes = new RouteCollection();
$controllerCollection = new ControllerCollection($routeCollection); $controllers = new ControllerCollection($routes);
$fooController = new Controller(new Route('/foo')); $fooController = new Controller(new Route('/foo'));
$fooController->setRouteName('foo'); $fooController->setRouteName('foo');
$controllerCollection->add($fooController); $controllers->add($fooController);
$barController = new Controller(new Route('/bar')); $barController = new Controller(new Route('/bar'));
$barController->setRouteName('bar'); $barController->setRouteName('bar');
$controllerCollection->add($barController); $controllers->add($barController);
$controllerCollection->flush(); $controllers->flush();
try { try {
$fooController->setRouteName('foo2'); $fooController->setRouteName('foo2');
......
...@@ -35,8 +35,8 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase ...@@ -35,8 +35,8 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase
->setRouteName('foo_abc'); ->setRouteName('foo_abc');
$application->flush(); $application->flush();
$routeCollection = $application->getRouteCollection(); $routes = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routeCollection->get('homepage')); $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('homepage'));
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routeCollection->get('foo_abc')); $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('foo_abc'));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment