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;
class Application extends HttpKernel implements EventSubscriberInterface
{
private $dispatcher;
private $routeCollection;
private $controllerCollection;
private $routes;
private $controllers;
private $request;
/**
......@@ -45,8 +45,8 @@ class Application extends HttpKernel implements EventSubscriberInterface
*/
public function __construct()
{
$this->routeCollection = new RouteCollection();
$this->controllerCollection = new ControllerCollection($this->routeCollection);
$this->routes = new RouteCollection();
$this->controllers = new ControllerCollection($this->routes);
$this->dispatcher = new EventDispatcher();
$this->dispatcher->addSubscriber($this);
......@@ -74,7 +74,7 @@ class Application extends HttpKernel implements EventSubscriberInterface
*/
public function getRouteCollection()
{
return $this->routeCollection;
return $this->routes;
}
/**
......@@ -99,7 +99,7 @@ class Application extends HttpKernel implements EventSubscriberInterface
$route = new Route($pattern, array('_controller' => $to), $requirements);
$controller = new Controller($route);
$this->controllerCollection->add($controller);
$this->controllers->add($controller);
return $controller;
}
......@@ -230,7 +230,7 @@ class Application extends HttpKernel implements EventSubscriberInterface
*/
public function flush()
{
$this->controllerCollection->flush();
$this->controllers->flush();
}
/**
......@@ -254,9 +254,9 @@ class Application extends HttpKernel implements EventSubscriberInterface
{
$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(),
'method' => $this->request->getMethod(),
'host' => $this->request->getHost(),
......
......@@ -25,11 +25,11 @@ use Symfony\Component\Routing\RouteCollection;
class ControllerCollection
{
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
public function flush()
{
foreach ($this->controllers as $controller) {
$this->routeCollection->add($controller->getRouteName(), $controller->getRoute());
$this->routes->add($controller->getRouteName(), $controller->getRoute());
$controller->freeze();
}
......
......@@ -74,9 +74,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
{
$application = new Application();
$routeCollection = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routeCollection);
$this->assertEquals(0, count($routeCollection->all()));
$routes = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
$this->assertEquals(0, count($routes->all()));
}
public function testGetRouteCollectionWithRoutes()
......@@ -91,10 +91,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
return 'bar';
});
$routeCollection = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routeCollection);
$this->assertEquals(0, count($routeCollection->all()));
$routes = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
$this->assertEquals(0, count($routes->all()));
$application->flush();
$this->assertEquals(2, count($routeCollection->all()));
$this->assertEquals(2, count($routes->all()));
}
}
......@@ -28,40 +28,40 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
{
public function testGetRouteCollectionWithNoRoutes()
{
$routeCollection = new RouteCollection();
$controllerCollection = new ControllerCollection($routeCollection);
$routes = new RouteCollection();
$controllers = new ControllerCollection($routes);
$this->assertEquals(0, count($routeCollection->all()));
$controllerCollection->flush();
$this->assertEquals(0, count($routeCollection->all()));
$this->assertEquals(0, count($routes->all()));
$controllers->flush();
$this->assertEquals(0, count($routes->all()));
}
public function testGetRouteCollectionWithRoutes()
{
$routeCollection = new RouteCollection();
$controllerCollection = new ControllerCollection($routeCollection);
$controllerCollection->add(new Controller(new Route('/foo')));
$controllerCollection->add(new Controller(new Route('/bar')));
$routes = new RouteCollection();
$controllers = new ControllerCollection($routes);
$controllers->add(new Controller(new Route('/foo')));
$controllers->add(new Controller(new Route('/bar')));
$this->assertEquals(0, count($routeCollection->all()));
$controllerCollection->flush();
$this->assertEquals(2, count($routeCollection->all()));
$this->assertEquals(0, count($routes->all()));
$controllers->flush();
$this->assertEquals(2, count($routes->all()));
}
public function testControllerFreezing()
{
$routeCollection = new RouteCollection();
$controllerCollection = new ControllerCollection($routeCollection);
$routes = new RouteCollection();
$controllers = new ControllerCollection($routes);
$fooController = new Controller(new Route('/foo'));
$fooController->setRouteName('foo');
$controllerCollection->add($fooController);
$controllers->add($fooController);
$barController = new Controller(new Route('/bar'));
$barController->setRouteName('bar');
$controllerCollection->add($barController);
$controllers->add($barController);
$controllerCollection->flush();
$controllers->flush();
try {
$fooController->setRouteName('foo2');
......
......@@ -35,8 +35,8 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase
->setRouteName('foo_abc');
$application->flush();
$routeCollection = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routeCollection->get('homepage'));
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routeCollection->get('foo_abc'));
$routes = $application->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('homepage'));
$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