8000 Fluid interface for building routes in PHP by weaverryan · Pull Request #15778 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fluid interface for building routes in PHP #15778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
51f60fc
Adding a new framework-specific Route class
weaverryan Sep 9, 2015
6891ec8
Adding a class to make adding/importing routes easier and more fluid
weaverryan Sep 9, 2015
4e430a0
Maintaining all the RouteCollection abilities to RouteCollectionBuilder
weaverryan Sep 12, 2015
0ddadc5
Moving the prefix to the builder, so that it's consistent with other …
weaverryan Sep 13, 2015
06ea900
Adding phpdoc
weaverryan Sep 13, 2015
6b922a6
Using InvalidArgumentException
weaverryan Sep 13, 2015
14518ed
No change - renaming variable
weaverryan Sep 13, 2015
7972fc9
Adding many more tests, which included a few small bug fixes with val…
weaverryan Sep 13, 2015
e11b7e0
Removed prefix argument from mount() - and added it instead to create…
weaverryan Sep 13, 2015
4d90916
fabbot!
weaverryan Sep 14, 2015
729ccbb
Renaming flush() to build()
weaverryan Sep 15, 2015
e509953
Not clearing everything on build - unnecessary, and the RouteCollecti…
weaverryan Sep 15, 2015
01e1329
Fixing phpdoc
weaverryan Sep 15, 2015
e39e0c4
Removing the FrameworkBundle Route and the ability to call Route::set…
weaverryan Sep 16, 2015
df1849f
Simplifying by transforming RouteCollection's into RouteCollectionBui…
weaverryan Sep 16, 2015
97b1eea
Fixing a bug with knowing which keys should be auto-generated
weaverryan Sep 16, 2015
e1ecde4
Minor code improvement to centralize things
weaverryan Sep 16, 2015
ecf4346
Renaming methods for clarity and consistency
weaverryan Sep 16, 2015
0dce55d
fabbot and possible test fixes
weaverryan Sep 16, 2015
f3d71ad
Allowing LoaderInterface instead of Loader
weaverryan Sep 17, 2015
8132fcb
Updating setRequirements to avoid deprecated calls
weaverryan Sep 17, 2015
b2676ec
phpdoc typo
weaverryan Sep 26, 2015
bf6790b
Making RouteCollectionBuilder's LoaderInteface optional
weaverryan Sep 30, 2015
61e4bf7
removing extra spaces
weaverryan Sep 30, 2015
8f0b956
moving into the component
weaverryan Sep 30, 2015
fbab6d4
Removing the ability to set a prefix on a builder: that only happens …
weaverryan Sep 30, 2015
012cb92
Removing the prefix from import, and making the user actually put tha…
weaverryan Sep 30, 2015
33255dd
Fixing a bug with route name collission because the prefix wasn't acc…
weaverryan Sep 30, 2015
356b114
Refactoring into private method
weaverryan Sep 30, 2015
7cb8996
fabbot
weaverryan Sep 30, 2015
573a7f1
Small tweaks suggested by fabpot, including removal of addResource(),…
weaverryan Sep 30, 2015
83f3194
stretching out logic into multiple lines: there's some discussion abo…
weaverryan Sep 30, 2015
26d656b
Fabbot
weaverryan Sep 30, 2015
42e73a2
Adding throws
weaverryan Oct 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing a bug with knowing which keys should be auto-generated
  • Loading branch information
weaverryan committed Sep 30, 2015
commit 97b1eea7f5e8b0146cfa1dd0c2156c693bdfd603
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,7 @@ public function add($path, $controller, $name = null)
{
$route = new Route($path);
$route->setDefault('_controller', $controller);

if (null === $name) {
// un-named routes have integer keys, are named later
$this->routes[] = $route;
} else {
// case the $name into a string, to make sure a number is a string
$this->routes[(string)$name] = $route;
}
$this->addRoute($route, $name);

return $route;
}
Expand Down Expand Up @@ -141,7 +134,7 @@ public function addRouteCollection(RouteCollection $collection)
// create a builder from the RouteCollection
$builder = new self($this->loader);
foreach ($collection->all() as $name => $route) 8000 {
$builder->routes[(string) $name] = $route;
$builder->addRoute($route, $name);
}

foreach ($collection->getResources() as $resource) {
Expand All @@ -153,6 +146,25 @@ public function addRouteCollection(RouteCollection $collection)
return $builder;
}

/**
* Adds a Route object to the builder.
*
* @param Route $route
* @param string|null $name
* @return $this
*/
public function addRoute(Route $route, $name = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Symfony, we try to use simple add/get/set/has for the main object being manipulated by a collection. So, I would expect add() here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seen the add() method, nvm then

{
if (null === $name) {
// used as a flag to know which routes will need a name later
$name = '_unnamed_route_'.spl_object_hash($route);
}

$this->routes[$name] = $route;

return $this;
}

/**
* Sets a prefix (e.g. /admin) to be used with all embedded routes.
*
Expand Down Expand Up @@ -316,8 +328,8 @@ public function build()

foreach ($this->routes as $name => $route) {
if ($route instanceof Route) {
// auto-generate the route name if it is just an index key
if (is_int($name)) {
// auto-generate the route name if it's been marked
if ('_unnamed_route_' === substr($name, 0, 15)) {
$name = $this->generateRouteName($route);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ public function testFlushSetsRouteNames()
$collectionBuilder->add('/blogs', 'AppBundle:Blog:list')
->setMethods('GET');

// integer route names are allowed - they don't confuse things
$collectionBuilder->add('/products', 'AppBundle:Product:list', 100);

$actualCollection = $collectionBuilder->build();
$actualRouteNames = array_keys($actualCollection->all());
$this->assertEquals(array(
'admin_dashboard',
'GET_blogs',
'100'
), $actualRouteNames);
}

Expand Down
0