本文整理汇总了PHP中Symfony\Component\Routing\Route::setDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::setDefaults方法的具体用法?PHP Route::setDefaults怎么用?PHP Route::setDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::setDefaults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$requirements = $current_route->getRequirements();
// Setting _method and _schema is deprecated since 2.7. Using
// setMethods() and setSchemes() are now the recommended ways.
unset($requirements['_method']);
unset($requirements['_schema']);
$route->setRequirements($requirements);
$route->setPath($current_route->getPath());
$route->setSchemes($current_route->getSchemes());
$route->setMethods($current_route->getMethods());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheContexts(['route']);
}
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例2: addCollection
public function addCollection($path, array $data = array())
{
$route = new Route($path);
// $pageClass = ($entity->getResource()->getPageClass()) ? $entity->getResource()->getPageClass() : $entity->getResource()->getPageClass();
$route->setDefaults($data);
return $route;
}
示例3: testDefaults
public function testDefaults()
{
$route = new Route('/:foo');
$route->setDefaults(array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '->setDefaults() sets the defaults');
$this->assertEquals($route, $route->setDefaults(array()), '->setDefaults() implements a fluent interface');
}
示例4: getModerationFormRoute
/**
* Gets the moderation-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getModerationFormRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('moderation-form') && $entity_type->getFormClass('moderation')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('moderation-form'));
$route->setDefaults(['_entity_form' => "{$entity_type_id}.moderation", '_title' => 'Moderation'])->setRequirement('_permission', 'administer moderation states')->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
return $route;
}
}
示例5: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>' && ($current_route = $this->routeMatch->getRouteObject())) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
}
}
示例6: testDefaults
/**
* @covers Symfony\Component\Routing\Route::setDefaults
* @covers Symfony\Component\Routing\Route::getDefaults
* @covers Symfony\Component\Routing\Route::setDefault
* @covers Symfony\Component\Routing\Route::getDefault
*/
public function testDefaults()
{
$route = new Route('/{foo}');
$route->setDefaults(array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '->setDefaults() sets the defaults');
$this->assertEquals($route, $route->setDefaults(array()), '->setDefaults() implements a fluent interface');
$route->setDefault('foo', 'bar');
$this->assertEquals('bar', $route->getDefault('foo'), '->setDefault() sets a default value');
$route->setDefault('foo2', 'bar2');
$this->assertEquals('bar2', $route->getDefault('foo2'), '->getDefault() return the default value');
$this->assertNull($route->getDefault('not_defined'), '->getDefault() return null if default value is not setted');
}
示例7: getEditFormRoute
/**
* Gets the edit-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getEditFormRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('edit-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('edit-form'));
// Use the edit form handler, if available, otherwise default.
$operation = 'default';
if ($entity_type->getFormClass('edit')) {
$operation = 'edit';
}
$route->setDefaults(['_entity_form' => "{$entity_type_id}.{$operation}", '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::editTitle'])->setRequirement('_entity_access', "{$entity_type_id}.update")->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
return $route;
}
}
示例8: getAddFormRoute
/**
* Gets the add-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getAddFormRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('add-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('add-form'));
// Use the add form handler, if available, otherwise default.
$operation = 'default';
if ($entity_type->getFormClass('add')) {
$operation = 'add';
}
$route->setDefaults(['_entity_form' => "{$entity_type_id}.{$operation}", '_title' => "Add {$entity_type->getLabel()}"])->setRequirement('_entity_create_access', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]])->setOption('_admin_route', TRUE);
return $route;
}
}
示例9: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例10: parseRoute
/**
* @param RouteCollection $collection
* @param string $name
* @param array $config
* @param string $path
*/
protected function parseRoute(RouteCollection $collection, $name, array $config, $path)
{
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
$options = isset($config['options']) ? $config['options'] : array();
$host = isset($config['host']) ? $config['host'] : '';
$schemes = isset($config['schemes']) ? $config['schemes'] : array();
$methods = isset($config['methods']) ? $config['methods'] : array();
$i18n = isset($config['i18n']) ? $config['i18n'] : true;
foreach ($this->registry->getRegisteredLocales() as $locale) {
$route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods);
if ($i18n) {
$route->setPath('/' . $locale . '/' . ltrim($this->helper->alterPath($config['path'], $locale), '/'));
$route->setDefaults($this->helper->alterDefaults($defaults, $locale));
}
$i18nName = $i18n ? $this->helper->alterName($name, $locale) : $name;
$collection->add($i18nName, $route);
}
}
示例11: testDefaults
public function testDefaults()
{
$route = new Route('/{foo}');
$route->setDefaults(array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '->setDefaults() sets the defaults');
$this->assertEquals($route, $route->setDefaults(array()), '->setDefaults() implements a fluent interface');
$route->setDefault('foo', 'bar');
$this->assertEquals('bar', $route->getDefault('foo'), '->setDefault() sets a default value');
$route->setDefault('foo2', 'bar2');
$this->assertEquals('bar2', $route->getDefault('foo2'), '->getDefault() return the default value');
$this->assertNull($route->getDefault('not_defined'), '->getDefault() return null if default value is not set');
$route->setDefault('_controller', $closure = function () {
return 'Hello';
});
$this->assertEquals($closure, $route->getDefault('_controller'), '->setDefault() sets a default value');
$route->setDefaults(array('foo' => 'foo'));
$route->addDefaults(array('bar' => 'bar'));
$this->assertEquals($route, $route->addDefaults(array()), '->addDefaults() implements a fluent interface');
$this->assertEquals(array('foo' => 'foo', 'bar' => 'bar'), $route->getDefaults(), '->addDefaults() keep previous defaults');
}
示例12: providerTestGetAddPageRoute
public function providerTestGetAddPageRoute()
{
$data = [];
$entity_type1 = $this->getEntityType();
$entity_type1->hasLinkTemplate('add-page')->willReturn(FALSE);
$data['no_add_page_link_template'] = [NULL, $entity_type1->reveal()];
$entity_type2 = $this->getEntityType();
$entity_type2->hasLinkTemplate('add-page')->willReturn(TRUE);
$entity_type2->getKey('bundle')->willReturn(NULL);
$data['no_bundle'] = [NULL, $entity_type2->reveal()];
$entity_type3 = $this->getEntityType();
$entity_type3->hasLinkTemplate('add-page')->willReturn(TRUE);
$entity_type3->getLinkTemplate('add-page')->willReturn('/the/add/page/link/template');
$entity_type3->id()->willReturn('the_entity_type_id');
$entity_type3->getKey('bundle')->willReturn('type');
$route = new Route('/the/add/page/link/template');
$route->setDefaults(['_controller' => 'Drupal\\Core\\Entity\\Controller\\EntityController::addPage', '_title_callback' => 'Drupal\\Core\\Entity\\Controller\\EntityController::addTitle', 'entity_type_id' => 'the_entity_type_id']);
$route->setRequirement('_entity_create_any_access', 'the_entity_type_id');
$data['add_page'] = [clone $route, $entity_type3->reveal()];
return $data;
}
示例13: createRoute
private function createRoute($path, array $globals, array $options = [])
{
foreach ($globals as $k => $v) {
if (is_array($v) && isset($options[$k])) {
$options[$k] = array_merge($v, $options[$k]);
} else {
$options[$k] = isset($options[$k]) ? $options[$k] : $v;
}
}
$route = new Route($path);
if (isset($options['host'])) {
$route->setHost($options['host']);
}
if (isset($options['defaults'])) {
$route->setDefaults($options['defaults']);
}
if (isset($options['requirements'])) {
$route->setRequirements($options['requirements']);
}
if (isset($options['methods'])) {
$route->setMethods($options['methods']);
}
return $route;
}
示例14: indexRoute
/**
* @param array $options
*
* @return Route[]
*/
protected function indexRoute(array $options)
{
$routes = [];
if ($options['index_pagination'] || $options['index_sort']) {
$path = '/index';
$defaults = [];
$requirements = [];
$sortParams = $this->indexSortParams($options['index_sort_params']);
if ($options['index_pagination']) {
$path .= '/{page}';
$defaults['page'] = '1';
$requirements['page'] = '\\d+';
}
if ($options['index_sort']) {
$path .= '/{sort}/{direction}';
}
$route = new Route($path);
$route->setMethods(['GET']);
$route->setRequirements($requirements);
$route->setDefaults($defaults);
$route->setDefault('_controller', $options['controller'] . ':index');
$this->addSortDefaults($route, $sortParams);
$routes['index'] = $route;
$root = new Route('/');
$root->setMethods(['GET']);
$root->setDefault('_controller', 'FrameworkBundle:Redirect:redirect');
$root->setDefault('route', $this->routePrefix($options['route_prefix']) . '_index');
$root->setDefault('_locale', null);
$routes['root'] = $root;
} else {
$route = new Route('/');
$route->setMethods(['GET']);
$route->setDefault('_controller', $options['controller'] . ':index');
$routes['index'] = $route;
}
return $routes;
}
示例15: createRoute
/**
* @param mixed[] $entry
*
* @return Route
*/
protected function createRoute($entry)
{
$route = new Route(getArrayElement('searchPath', $entry));
$route->setDefaults($this->getDynamicRouteDefaults($entry));
$this->assignRouteValue('host', $entry, $route);
$this->assignRouteValue('methods', $entry, $route);
$this->assignRouteValue('requirements', $entry, $route);
$this->assignRouteValue('schemas', $entry, $route);
return $route;
}