當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Route::setDefaults方法代碼示例

本文整理匯總了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('/');
         }
     }
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:28,代碼來源:RouteProcessorCurrent.php

示例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;
 }
開發者ID:bigfishcmf,項目名稱:bigfishcmf,代碼行數:7,代碼來源:DatabaseLoader.php

示例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');
 }
開發者ID:netixpro,項目名稱:symfony,代碼行數:7,代碼來源:RouteTest.php

示例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;
     }
 }
開發者ID:tedbow,項目名稱:scheduled-updates-demo,代碼行數:18,代碼來源:EntityTypeModerationRouteProvider.php

示例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());
     }
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:13,代碼來源:RouteProcessorCurrent.php

示例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');
 }
開發者ID:nickaggarwal,項目名稱:sample-symfony2,代碼行數:18,代碼來源:RouteTest.php

示例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;
     }
 }
開發者ID:dmyerson,項目名稱:d8ecs,代碼行數:23,代碼來源:DefaultHtmlRouteProvider.php

示例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;
     }
 }
開發者ID:drupalbristol,項目名稱:drupal-bristol-website,代碼行數:23,代碼來源:SponsorEntityTypeHtmlRouteProvider.php

示例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('/');
         }
     }
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:18,代碼來源:RouteProcessorCurrent.php

示例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);
     }
 }
開發者ID:leapt,項目名稱:i18n-bundle,代碼行數:25,代碼來源:I18nYamlFileLoader.php

示例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');
 }
開發者ID:omusico,項目名稱:lafayettehelps.com,代碼行數:20,代碼來源:RouteTest.php

示例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;
 }
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:21,代碼來源:DefaultHtmlRouteProviderTest.php

示例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;
 }
開發者ID:EXSyst,項目名稱:ApiBundle,代碼行數:24,代碼來源:ApiClassLoaderTest.php

示例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;
 }
開發者ID:mikoweb,項目名稱:vsymfo-core-bundle,代碼行數:42,代碼來源:CrudLoader.php

示例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;
 }
開發者ID:scr-be,項目名稱:mantle-bundle,代碼行數:15,代碼來源:RouteRedirectLoader.php


注:本文中的Symfony\Component\Routing\Route::setDefaults方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。