本文整理汇总了PHP中Symfony\Component\Routing\RouteCollection::addOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteCollection::addOptions方法的具体用法?PHP RouteCollection::addOptions怎么用?PHP RouteCollection::addOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RouteCollection
的用法示例。
在下文中一共展示了RouteCollection::addOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCollection
/**
* 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
*
* @api
*/
public function addCollection(RouteCollection $collection)
{
// This is to keep BC for getParent() and getRoot(). It does not prevent
// infinite loops by recursive referencing. But we don't need that logic
// anymore as the tree logic has been deprecated and we are just widening
// the accepted range.
$collection->parent = $this;
// this is to keep BC
$numargs = func_num_args();
if ($numargs > 1) {
$collection->addPrefix($this->prefix . func_get_arg(1));
if ($numargs > 2) {
$collection->addDefaults(func_get_arg(2));
if ($numargs > 3) {
$collection->addRequirements(func_get_arg(3));
if ($numargs > 4) {
$collection->addOptions(func_get_arg(4));
}
}
}
} else {
// the sub-collection must have the prefix of the parent (current instance) prepended because it does not
// necessarily already have it applied (depending on the order RouteCollections are added to each other)
// this will be removed when the BC layer for getPrefix() is removed
$collection->addPrefix($this->prefix);
}
// we need to remove all routes with the same names first because just replacing them
// would not place the new route at the end of the merged array
foreach ($collection->all() as $name => $route) {
unset($this->routes[$name]);
$this->routes[$name] = $route;
}
$this->resources = array_merge($this->resources, $collection->getResources());
}
示例2: testAddDefaultsAndRequirementsAndOptions
public function testAddDefaultsAndRequirementsAndOptions()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/{placeholder}'));
$collection1 = new RouteCollection();
$collection1->add('bar', new Route('/{placeholder}', array('_controller' => 'fixed', 'placeholder' => 'default'), array('placeholder' => '.+'), array('option' => 'value')));
$collection->addCollection($collection1);
$collection->addDefaults(array('placeholder' => 'new-default'));
$this->assertEquals(array('placeholder' => 'new-default'), $collection->get('foo')->getDefaults(), '->addDefaults() adds defaults to all routes');
$this->assertEquals(array('_controller' => 'fixed', 'placeholder' => 'new-default'), $collection->get('bar')->getDefaults(), '->addDefaults() adds defaults to all routes and overwrites existing ones');
$collection->addRequirements(array('placeholder' => '\\d+'));
$this->assertEquals(array('placeholder' => '\\d+'), $collection->get('foo')->getRequirements(), '->addRequirements() adds requirements to all routes');
$this->assertEquals(array('placeholder' => '\\d+'), $collection->get('bar')->getRequirements(), '->addRequirements() adds requirements to all routes and overwrites existing ones');
$collection->addOptions(array('option' => 'new-value'));
$this->assertEquals(array('option' => 'new-value', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), $collection->get('bar')->getOptions(), '->addOptions() adds options to all routes and overwrites existing ones');
}