Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
simplified previous merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 3, 2015
1 parent 091240e commit 401674e
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/Silex/ControllerCollection.php
Expand Up @@ -42,7 +42,6 @@ class ControllerCollection
protected $defaultRoute;
protected $defaultController;
protected $prefix;
protected $routes;

public function __construct(Route $defaultRoute)
{
Expand All @@ -52,16 +51,6 @@ public function __construct(Route $defaultRoute)
};
}

/**
* Use existing route collection to resolve conflicting autogenerated route names among mounted routes
*
* @param RouteCollection $routes
*/
public function shareRoutes(RouteCollection $routes)
{
$this->routes = $routes;
}

/**
* Mounts controllers under the given route prefix.
*
Expand All @@ -70,10 +59,6 @@ public function shareRoutes(RouteCollection $routes)
*/
public function mount($prefix, ControllerCollection $controllers)
{
if (!($this->routes instanceof RouteCollection)) {
$this->routes = new RouteCollection();
}
$controllers->shareRoutes($this->routes);
$controllers->prefix = $prefix;

$this->controllers[] = $controllers;
Expand Down Expand Up @@ -201,13 +186,15 @@ public function __call($method, $arguments)
*
* @return RouteCollection A RouteCollection instance
*/
public function flush($prefix = '')
public function flush($prefix = '', $routes = null)
{
if ($prefix !== '') {
$prefix = '/'.trim(trim($prefix), '/');
}

$routes = $this->routes ?: new RouteCollection();
if (null === $routes) {
$routes = new RouteCollection();
}

foreach ($this->controllers as $controller) {
if ($controller instanceof Controller) {
Expand All @@ -222,7 +209,7 @@ public function flush($prefix = '')
$routes->add($name, $controller->getRoute());
$controller->freeze();
} else {
$routes->addCollection($controller->flush($prefix.$controller->prefix));
$routes->addCollection($controller->flush($prefix.$controller->prefix, $routes));
}
}

Expand Down

0 comments on commit 401674e

Please sign in to comment.