Commit c8bd0b4f authored by alexpott's avatar alexpott

Issue #2316537 by dawehner | chx: Upgrade symfony CMF to 1.2, remove...

Issue #2316537 by dawehner | chx: Upgrade symfony CMF to 1.2, remove deprecated parameters from getRouteByName* .
parent 9c4954f6
......@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "2b2309c748ec92230880579aaedfa1e6",
"hash": "6a7a4ba69644c6cf110d03b1a5346e3e",
"packages": [
{
"name": "doctrine/annotations",
......@@ -1415,17 +1415,17 @@
},
{
"name": "symfony-cmf/routing",
"version": "1.1.0",
"version": "1.2.0",
"target-dir": "Symfony/Cmf/Component/Routing",
"source": {
"type": "git",
"url": "https://github.com/symfony-cmf/Routing.git",
"reference": "9f8607950cbf888ec678713a35f3d0088857c85f"
"reference": "c67258b875eef3cb08009bf1428499d0f01ce5e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony-cmf/Routing/zipball/9f8607950cbf888ec678713a35f3d0088857c85f",
"reference": "9f8607950cbf888ec678713a35f3d0088857c85f",
"url": "https://api.github.com/repos/symfony-cmf/Routing/zipball/c67258b875eef3cb08009bf1428499d0f01ce5e7",
"reference": "c67258b875eef3cb08009bf1428499d0f01ce5e7",
"shasum": ""
},
"require": {
......@@ -1445,7 +1445,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
"dev-master": "1.2-dev"
}
},
"autoload": {
......@@ -1469,7 +1469,7 @@
"database",
"routing"
],
"time": "2013-10-14 15:32:46"
"time": "2014-05-08 19:37:14"
},
{
"name": "symfony/class-loader",
......@@ -2445,7 +2445,6 @@
"doctrine/common": 20,
"doctrine/annotations": 20,
"kriswallsmith/assetic": 15,
"symfony-cmf/routing": 15,
"phpunit/phpunit-mock-objects": 20
},
"prefer-stable": false,
......
......@@ -134,9 +134,6 @@ public function getRouteCollectionForRequest(Request $request) {
*
* @param string $name
* The route name to fetch
* @param array $parameters
* The parameters as they are passed to the UrlGeneratorInterface::generate
* call.
*
* @return \Symfony\Component\Routing\Route
* The found route.
......@@ -144,8 +141,8 @@ public function getRouteCollectionForRequest(Request $request) {
* @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
* Thrown if there is no route with that name in this repository.
*/
public function getRouteByName($name, $parameters = array()) {
$routes = $this->getRoutesByNames(array($name), $parameters);
public function getRouteByName($name) {
$routes = $this->getRoutesByNames(array($name));
if (empty($routes)) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
......@@ -165,14 +162,11 @@ public function getRouteByName($name, $parameters = array()) {
*
* @param array $names
* The list of names to retrieve.
* @param array $parameters
* The parameters as they are passed to the UrlGeneratorInterface::generate
* call. (Only one array, not one for each entry in $names).
*
* @return \Symfony\Component\Routing\Route[]
* Iterable thing with the keys the names of the $names argument.
*/
public function getRoutesByNames($names, $parameters = array()) {
public function getRoutesByNames($names) {
if (empty($names)) {
throw new \InvalidArgumentException('You must specify the route names to load');
......
......@@ -47,8 +47,8 @@ public function getRouteCollectionForRequest(Request $request) {
/**
* Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRouteByName().
*/
public function getRouteByName($name, $parameters = array()) {
$routes = $this->getRoutesByNames(array($name), $parameters);
public function getRouteByName($name) {
$routes = $this->getRoutesByNames(array($name));
if (empty($routes)) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
......@@ -59,7 +59,7 @@ public function getRouteByName($name, $parameters = array()) {
/**
* Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRoutesByName().
*/
public function getRoutesByNames($names, $parameters = array()) {
public function getRoutesByNames($names) {
$routes = array();
foreach ($names as $name) {
$routes[] = $this->routes->get($name);
......
......@@ -92,8 +92,8 @@ function setUp() {
),
);
foreach ($return_map_values as $values) {
$route_name_return_map[] = array($values['route_name'], array(), $values['return']);
$routes_names_return_map[] = array(array($values['route_name']), array(), $values['return']);
$route_name_return_map[] = array($values['route_name'], $values['return']);
$routes_names_return_map[] = array(array($values['route_name']), $values['return']);
}
$provider->expects($this->any())
->method('getRouteByName')
......
......@@ -711,66 +711,6 @@
"spl"
]
},
{
"name": "symfony-cmf/routing",
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"target-dir": "Symfony/Cmf/Component/Routing",
"source": {
"type": "git",
"url": "https://github.com/symfony-cmf/Routing.git",
"reference": "9f8607950cbf888ec678713a35f3d0088857c85f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony-cmf/Routing/zipball/9f8607950cbf888ec678713a35f3d0088857c85f",
"reference": "9f8607950cbf888ec678713a35f3d0088857c85f",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"psr/log": "~1.0",
"symfony/http-kernel": "~2.2",
"symfony/routing": "~2.2"
},
"require-dev": {
"symfony/config": "~2.2",
"symfony/dependency-injection": "~2.0",
"symfony/event-dispatcher": "~2.1"
},
"suggest": {
"symfony/event-dispatcher": "DynamicRouter can optionally trigger an event at the start of matching. Minimal version ~2.1"
},
"time": "2013-10-14 15:32:46",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Cmf\\Component\\Routing": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony CMF Community",
"homepage": "https://github.com/symfony-cmf/Routing/contributors"
}
],
"description": "Extends the Symfony2 routing component for dynamic routes and chaining several routers",
"homepage": "http://cmf.symfony.com",
"keywords": [
"database",
"routing"
]
},
{
"name": "doctrine/annotations",
"version": "dev-master",
......@@ -2512,5 +2452,65 @@
"rest",
"web service"
]
},
{
"name": "symfony-cmf/routing",
"version": "1.2.0",
"version_normalized": "1.2.0.0",
"target-dir": "Symfony/Cmf/Component/Routing",
"source": {
"type": "git",
"url": "https://github.com/symfony-cmf/Routing.git",
"reference": "c67258b875eef3cb08009bf1428499d0f01ce5e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony-cmf/Routing/zipball/c67258b875eef3cb08009bf1428499d0f01ce5e7",
"reference": "c67258b875eef3cb08009bf1428499d0f01ce5e7",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"psr/log": "~1.0",
"symfony/http-kernel": "~2.2",
"symfony/routing": "~2.2"
},
"require-dev": {
"symfony/config": "~2.2",
"symfony/dependency-injection": "~2.0",
"symfony/event-dispatcher": "~2.1"
},
"suggest": {
"symfony/event-dispatcher": "DynamicRouter can optionally trigger an event at the start of matching. Minimal version ~2.1"
},
"time": "2014-05-08 19:37:14",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Cmf\\Component\\Routing": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony CMF Community",
"homepage": "https://github.com/symfony-cmf/Routing/contributors"
}
],
"description": "Extends the Symfony2 routing component for dynamic routes and chaining several routers",
"homepage": "http://cmf.symfony.com",
"keywords": [
"database",
"routing"
]
}
]
......@@ -8,6 +8,7 @@ php:
env:
- SYMFONY_VERSION=2.2.*
- SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=2.4.*
- SYMFONY_VERSION=dev-master
before_script:
......
Changelog
=========
1.2.0
-----
Release 1.2.0
1.2.0-RC1
---------
* **2013-12-23**: add support for ChainRouter::getRouteCollection()
* **2013-01-07**: Removed the deprecated $parameters argument in
RouteProviderInterface::getRouteByName and getRoutesByNames.
1.1.0
-----
Release 1.1.0
1.1.0-RC1
---------
......
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Candidates;
use Symfony\Component\HttpFoundation\Request;
/**
* A straightforward strategy that splits the URL on "/".
*
* If locales is set, additionally generates candidates removing the locale if
* it is one of the configured locales, for non-locale specific URLs.
*
* @author David Buchmann <mail@davidbu.ch>
*/
class Candidates implements CandidatesInterface
{
/**
* @var array
*/
protected $locales;
/**
* A limit to apply to the number of candidates generated.
*
* This is to prevent abusive requests with a lot of "/". The limit is per
* batch, that is if a locale matches you could get as many as 2 * $limit
* candidates if the URL has that many slashes.
*
* @var int
*/
protected $limit;
/**
* @param array $locales The locales to support.
* @param int $limit A limit to apply to the candidates generated.
*/
public function __construct(array $locales = array(), $limit = 20)
{
$this->setLocales($locales);
$this->limit = $limit;
}
/**
* Set the locales to support by this strategy.
*
* @param array $locales The locales to support.
*/
public function setLocales(array $locales)
{
$this->locales = $locales;
}
/**
* {@inheritDoc}
*
* Always returns true.
*/
public function isCandidate($name)
{
return true;
}
/**
* {@inheritDoc}
*
* Does nothing.
*/
public function restrictQuery($queryBuilder)
{
}
/**
* {@inheritDoc}
*/
public function getCandidates(Request $request)
{
$url = $request->getPathInfo();
$candidates = $this->getCandidatesFor($url);
$locale = $this->determineLocale($url);
if ($locale) {
$candidates = array_unique(array_merge($candidates, $this->getCandidatesFor(substr($url, strlen($locale) + 1))));
}
return $candidates;
}
/**
* Determine the locale of this URL.
*
* @param string $url The url to determine the locale from.
*
* @return string|boolean The locale if $url starts with one of the allowed locales.
*/
protected function determineLocale($url)
{
if (!count($this->locales)) {
return false;
}
$matches = array();
if (preg_match('#(' . implode('|', $this->locales) . ')(/|$)#', $url, $matches)) {
return $matches[1];
}
return false;
}
/**
* Handle a possible format extension and split the $url on "/".
*
* $prefix is prepended to every candidate generated.
*
* @param string $url The URL to split.
* @param string $prefix A prefix to prepend to every pattern.
*
* @return array Paths that could represent routes that match $url and are
* child of $prefix.
*/
protected function getCandidatesFor($url, $prefix = '')
{
$candidates = array();
if ('/' !== $url) {
// handle format extension, like .html or .json
if (preg_match('/(.+)\.[a-z]+$/i', $url, $matches)) {
$candidates[] = $prefix . $url;
$url = $matches[1];
}
$part = $url;
$count = 0;
while (false !== ($pos = strrpos($part, '/'))) {
if (++$count > $this->limit) {
return $candidates;
}
$candidates[] = $prefix . $part;
$part = substr($url, 0, $pos);
}
}
$candidates[] = $prefix ?: '/';
return $candidates;
}
}
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Candidates;
use Symfony\Component\HttpFoundation\Request;
/**
* Candidates is a subsystem useful for the route provider. It separates the
* logic for determining possible static prefixes from the route provider.
*
* @author David Buchmann <mail@davidbu.ch>
*/
interface CandidatesInterface
{
/**
* @param Request $request
*
* @return array a list of PHPCR-ODM ids
*/
public function getCandidates(Request $request);
/**
* Determine if $name is a valid candidate, e.g. in getRouteByName.
*
* @param string $name
*
* @return boolean
*/
public function isCandidate($name);
/**
* Provide a best effort query restriction to limit a query to only find
* routes that are supported.
*
* @param object $queryBuilder A query builder suited for the storage backend.
*/
public function restrictQuery($queryBuilder);
}
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing;
use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class ChainRouteCollection extends RouteCollection
{
/**
* @var RouteCollection[]
*/
private $routeCollections = array();
/**
* @var RouteCollection
*/
private $routeCollection;
public function __clone()
{
foreach ($this->routeCollections as $routeCollection) {
$this->routeCollections[] = clone $routeCollection;
}
}
/**
* Gets the current RouteCollection as an Iterator that includes all routes.
*
* It implements \IteratorAggregate.
*
* @see all()
*
* @return \ArrayIterator An \ArrayIterator object for iterating over routes
*/
public function getIterator()
{
return new \ArrayIterator($this->all());
}
/**
* Gets the number of Routes in this collection.
*
* @return int The number of routes
*/
public function count()
{
$count = 0;
foreach ($this->routeCollections as $routeCollection) {
$count+= $routeCollection->count();
}
return $count;
}
/**
* Adds a route.
*
* @param string $name The route name
* @param Route $route A Route instance
*/
public function add($name, Route $route)
{
$this->createInternalCollection();
$this->routeCollection->add($name, $route);
}
/**
* Returns all routes in this collection.
*
* @return Route[] An array of routes
*/
public function all()
{
$routeCollectionAll = new RouteCollection();
foreach ($this->routeCollections as $routeCollection) {
$routeCollectionAll->addCollection($routeCollection);
}
return $routeCollectionAll->all();
}
/**
* Gets a route by name.
*
* @param string $name The route name
*
* @return Route|null A Route instance or null when not found
*/
public function get($name)
{
foreach ($this->routeCollections as $routeCollection) {
$route = $routeCollection->get($name);
if (null !== $route) {
return $route;
}
}
return null;
}
/**
* Removes a route or an array of routes by name from the collection
*
* @param string|array $name The route name or an array of route names
*/
public function remove($name)
{
foreach ($this->routeCollections as $routeCollection) {
$route = $routeCollection->get($name);
if (null !== $route) {
$routeCollection->remove($name);
}
}
}
/**
* Adds a route collection at the end of the current set by appending all
* routes of the added collection.
*
* @param RouteCollection $collection A RouteCollection instance
*/
public function addCollection(RouteCollection $collection)
{
$this->routeCollections[] = $collection;
}
/**
* Adds a prefix to the path of all child routes.
*
* @param string $prefix An optional prefix to add before each pattern of the route collection
* @param array $defaults An array of default values
* @param array $requirements An array of requirements
*/
public function addPrefix($prefix, array $defaults = array(), array $requirements = array())
{
$this->createInternalCollection();
foreach ($this->routeCollections as $routeCollection) {
$routeCollection->addPrefix($prefix, $defaults, $requirements);
}
}
/**
* Sets the host pattern on all routes.
*
* @param string $pattern The pattern
* @param array $defaults An array of default values
* @param array $requirements An array of requirements
*/
public function setHost($pattern, array $defaults = array(), array $requirements = array())
{
$this->createInternalCollection();
foreach ($this->routeCollections as $routeCollection) {
$routeCollection->setHost($pattern, $defaults, $requirements);
}
}
/**
* Adds defaults to all routes.
*
* An existing default value under the same name in a route will be overridden.
*
* @param array $defaults An array of default values
*/
public function addDefaults(array $defaults)
{
$this->createInternalCollection();