本文整理汇总了PHP中Symfony\Component\Routing\RouteCollection::getIterator方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteCollection::getIterator方法的具体用法?PHP RouteCollection::getIterator怎么用?PHP RouteCollection::getIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RouteCollection
的用法示例。
在下文中一共展示了RouteCollection::getIterator方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compileRoutes
private function compileRoutes(RouteCollection $routes, $supportsRedirections, $parentPrefix = null)
{
$code = array();
$routeIterator = $routes->getIterator();
$keys = array_keys($routeIterator->getArrayCopy());
$keysCount = count($keys);
$i = 0;
foreach ($routeIterator as $name => $route) {
$i++;
if ($route instanceof RouteCollection) {
$prefix = $route->getPrefix();
$optimizable = $prefix && count($route->all()) > 1 && false === strpos($route->getPrefix(), '{');
$indent = '';
if ($optimizable) {
for ($j = $i; $j < $keysCount; $j++) {
if ($keys[$j] === null) {
continue;
}
$testRoute = $routeIterator->offsetGet($keys[$j]);
$isCollection = $testRoute instanceof RouteCollection;
$testPrefix = $isCollection ? $testRoute->getPrefix() : $testRoute->getPattern();
if (0 === strpos($testPrefix, $prefix)) {
$routeIterator->offsetUnset($keys[$j]);
if ($isCollection) {
$route->addCollection($testRoute);
} else {
$route->add($keys[$j], $testRoute);
}
$i++;
$keys[$j] = null;
}
}
if ($prefix !== $parentPrefix) {
$code[] = sprintf(" if (0 === strpos(\$pathinfo, %s)) {", var_export($prefix, true));
$indent = ' ';
}
}
foreach ($this->compileRoutes($route, $supportsRedirections, $prefix) as $line) {
foreach (explode("\n", $line) as $l) {
if ($l) {
$code[] = $indent . $l;
} else {
$code[] = $l;
}
}
}
if ($optimizable && $prefix !== $parentPrefix) {
$code[] = " }\n";
}
} else {
foreach ($this->compileRoute($route, $name, $supportsRedirections, $parentPrefix) as $line) {
$code[] = $line;
}
}
}
return $code;
}
示例2: compileRoutes
private function compileRoutes(RouteCollection $routes, $supportsRedirections, $parentPrefix = null)
{
$code = '';
$routeIterator = $routes->getIterator();
$keys = array_keys($routeIterator->getArrayCopy());
$keysCount = count($keys);
$i = 0;
foreach ($routeIterator as $name => $route) {
$i++;
if ($route instanceof RouteCollection) {
$prefix = $route->getPrefix();
$optimizable = $prefix && count($route->all()) > 1 && false === strpos($route->getPrefix(), '{');
$optimized = false;
if ($optimizable) {
for ($j = $i; $j < $keysCount; $j++) {
if (null === $keys[$j]) {
continue;
}
$testRoute = $routeIterator->offsetGet($keys[$j]);
$isCollection = $testRoute instanceof RouteCollection;
$testPrefix = $isCollection ? $testRoute->getPrefix() : $testRoute->getPattern();
if (0 === strpos($testPrefix, $prefix)) {
$routeIterator->offsetUnset($keys[$j]);
if ($isCollection) {
$route->addCollection($testRoute);
} else {
$route->add($keys[$j], $testRoute);
}
$i++;
$keys[$j] = null;
}
}
if ($prefix !== $parentPrefix) {
$code .= sprintf(" if (0 === strpos(\$pathinfo, %s)) {\n", var_export($prefix, true));
$optimized = true;
}
}
if ($optimized) {
foreach (explode("\n", $this->compileRoutes($route, $supportsRedirections, $prefix)) as $line) {
if ('' !== $line) {
$code .= ' ';
// apply extra indention
}
$code .= $line . "\n";
}
$code = substr($code, 0, -2);
// remove redundant last two line breaks
$code .= " }\n\n";
} else {
$code .= $this->compileRoutes($route, $supportsRedirections, $prefix);
}
} else {
$code .= $this->compileRoute($route, $name, $supportsRedirections, $parentPrefix) . "\n";
}
}
return $code;
}
示例3: execute
/**
* This method will be called if this command is triggered
*
* @param ArgumentsContainer $arguments
*
* @return mixed
*/
public function execute(ArgumentsContainer $arguments)
{
$this->dispatcher->trigger(new SimpleEvent('thinframe.routes.pre_load'));
$routesTable = [];
foreach ($this->routeCollection->getIterator() as $name => $route) {
/* @var $route Route */
if (count($route->getMethods()) == 0) {
$routesTable[$route->getPath()] = ['action' => $name, 'method' => '*'];
}
foreach ($route->getMethods() as $method) {
$routesTable[$route->getPath()] = ['action' => $name, 'method' => $method];
}
}
$maxSize = max(array_map("strlen", array_keys($routesTable)));
foreach ($routesTable as $path => $details) {
$this->outputDriver->send("[format effects='bold'] {method} \t {path} \t {action} [/format]" . PHP_EOL, ['method' => $details['method'], 'path' => str_pad($path, $maxSize + 4, " ", STR_PAD_RIGHT), 'action' => $details['action']]);
}
}
示例4: pullRoutesFromCollection
/**
* Get an array of all routes (1 level deep) for all routes in the system.
*
* @param \Symfony\Component\Routing\RouteCollection $routes
*
* @return array
*/
private static function pullRoutesFromCollection(\Symfony\Component\Routing\RouteCollection $routes)
{
$routesArray = array();
foreach ($routes->getIterator() as $key => $route) {
if ($route instanceof \Symfony\Component\Routing\RouteCollection) {
$routesArray += self::pullRoutesFromCollection($route);
} else {
$routesArray[] = $route;
}
}
return $routesArray;
}
示例5: testUniqueRouteWithGivenName
public function testUniqueRouteWithGivenName()
{
$collection1 = new RouteCollection();
$collection1->add('foo', new Route('/old'));
$collection2 = new RouteCollection();
$collection3 = new RouteCollection();
$collection3->add('foo', $new = new Route('/new'));
$collection1->addCollection($collection2);
$collection2->addCollection($collection3);
$collection1->add('stay', new Route('/stay'));
$iterator = $collection1->getIterator();
$this->assertSame($new, $collection1->get('foo'), '->get() returns new route that overrode previous one');
// size of 2 because collection1 contains collection2 and /stay but not /old anymore
$this->assertCount(2, $iterator, '->addCollection() removes previous routes when adding new routes with the same name');
$this->assertInstanceOf('Symfony\\Component\\Routing\\RouteCollection', $iterator->current(), '->getIterator returns both Routes and RouteCollections');
$iterator->next();
$this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $iterator->current(), '->getIterator returns both Routes and RouteCollections');
}
示例6: testUniqueRouteWithGivenName
public function testUniqueRouteWithGivenName()
{
$collection1 = new RouteCollection();
$collection1->add('foo', new Route('/old'));
$collection2 = new RouteCollection();
$collection3 = new RouteCollection();
$collection3->add('foo', $new = new Route('/new'));
$collection2->addCollection($collection3);
$collection1->addCollection($collection2);
$this->assertSame($new, $collection1->get('foo'), '->get() returns new route that overrode previous one');
// size of 1 because collection1 contains /new but not /old anymore
$this->assertCount(1, $collection1->getIterator(), '->addCollection() removes previous routes when adding new routes with the same name');
}
示例7: addParentNamePrefix
/**
* Adds a name prefix to the route name of all collection routes.
*
* @param RouteCollection $collection Route collection
* @param array $namePrefix NamePrefix to add in each route name of the route collection
*
* @return RouteCollection
*/
public function addParentNamePrefix(RouteCollection $collection, $namePrefix)
{
if (!isset($namePrefix) || ($namePrefix = trim($namePrefix)) === "") {
return $collection;
}
$iterator = $collection->getIterator();
foreach ($iterator as $key1 => $route1) {
$collection->add($namePrefix . $key1, $route1);
$collection->remove($key1);
}
return $collection;
}
示例8: getRouteList
/**
* @return array
*/
public function getRouteList()
{
return $this->SymfonyRouteCollection->getIterator()->getArrayCopy();
}