当前位置: 首页>>代码示例>>PHP>>正文


PHP RouteCollection::addPrefix方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\RouteCollection::addPrefix方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteCollection::addPrefix方法的具体用法?PHP RouteCollection::addPrefix怎么用?PHP RouteCollection::addPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\RouteCollection的用法示例。


在下文中一共展示了RouteCollection::addPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addCollection

 /**
  * Adds a route collection to the current set of routes (at the end of the current set).
  *
  * @param RouteCollection $collection A RouteCollection instance
  * @param string          $prefix     An optional prefix to add before each pattern of the route collection
  */
 public function addCollection(RouteCollection $collection, $prefix = '')
 {
     $collection->addPrefix($prefix);
     foreach ($collection->getResources() as $resource) {
         $this->addResource($resource);
     }
     $this->routes = array_merge($this->routes, $collection->all());
 }
开发者ID:noelg,项目名称:symfony-demo,代码行数:14,代码来源:RouteCollection.php

示例2: testAddPrefix

 public function testAddPrefix()
 {
     $collection = new RouteCollection();
     $collection->add('foo', $foo = new Route('/foo'));
     $collection->add('bar', $bar = new Route('/bar'));
     $collection->addPrefix('/admin');
     $this->assertEquals('/admin/foo', $collection->get('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
     $this->assertEquals('/admin/bar', $collection->get('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
 }
开发者ID:notbrain,项目名称:symfony,代码行数:9,代码来源:RouteCollectionTest.php

示例3: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $collection = new RouteCollection();
     $collection->addPrefix('en');
     $collection->add('test', new Route('/hello', array('controller' => 'AppBundle/Controller/HelloController', 'action' => 'index')));
     $secondCollection = new RouteCollection();
     $secondCollection->addPrefix('prod');
     $collection->addCollection($secondCollection);
 }
开发者ID:radudemetrescu,项目名称:symfony,代码行数:9,代码来源:RequestListener.php

示例4: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new RuntimeException('load(): Do not add this loader twice.');
     }
     $this->generatesRoutes();
     $this->generateAdminHomeRoute();
     $this->routes->addPrefix($this->adminRoutePrefix);
     return $this->routes;
 }
开发者ID:MrCue,项目名称:DatatablesBundle,代码行数:13,代码来源:DatatablesRoutingLoader.php

示例5: load

 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     $nRoutes = $this->nRouteManager->getNestedRoutes();
     foreach ($nRoutes as $nRoute) {
         $flattenRoutes = $this->flattenRouteFactory->getFlattenRoutes($nRoute);
         $this->fRouteManager->addFlattenRoute($flattenRoutes);
         $registerRoutes = $this->flattenRouteFactory->getRoutes($flattenRoutes);
         foreach ($registerRoutes as $key => $route) {
             $routes->add($key, $route);
         }
         $reflection = new ReflectionObject($nRoute);
         $routes->addResource(new FileResource($reflection->getFileName()));
     }
     $routes->addPrefix($this->rootPath);
     return $routes;
 }
开发者ID:uneak,项目名称:RoutesManagerBundle,代码行数:17,代码来源:RoutesLoader.php

示例6: loadRoutes

 protected function loadRoutes(RouteCollection $routes = null)
 {
     $routes = $this->beforeLoadRoutes($routes);
     if ($routes) {
         $this->routes = $routes;
     } else {
         $this->routes = new RouteCollection();
         foreach ($this->getComponentsRoutes() as $name => $routes) {
             $this->routes->addCollection($routes);
         }
         $this->routes->addCollection($this->getRootRoutes());
     }
     //var_dump(BASE_URL);
     if (BASE_URL != '/') {
         //добавляем префикс /админ
         $this->routes->addPrefix(BASE_URL);
         //die('ok');
     }
     $this->afterLoadRoutes($this->routes);
     //echo '<pre>';var_dump($this->routes);
 }
开发者ID:php-nik,项目名称:core,代码行数:21,代码来源:BaseApp.php

示例7: addPrefix

 /**
  * {@inheritdoc}
  */
 public function addPrefix($prefix, array $defaults = array(), array $requirements = array())
 {
     $originalPrefix = false;
     if (is_array($prefix)) {
         foreach ($prefix as $locale => $localePrefix) {
             $prefix[$locale] = trim(trim($localePrefix), '/');
         }
         $this->localizeRoutes(array_keys($prefix));
     } elseif (is_string($prefix) && preg_match(self::LOCALE_REGEX, $prefix)) {
         $originalPrefix = trim(trim($prefix), '/');
         $prefix = array();
     } else {
         parent::addPrefix($prefix, $defaults, $requirements);
         return;
     }
     foreach ($this->all() as $name => $route) {
         $locale = $route->getDefault(self::LOCALE_PARAM);
         $routePrefix = $this->localizePrefix($locale, $prefix, $originalPrefix, $name);
         $route->setPath('/' . $routePrefix . $route->getPath());
         $route->addDefaults($defaults);
         $route->addRequirements($requirements);
     }
 }
开发者ID:cesco69,项目名称:BeSimpleI18nRoutingBundle,代码行数:26,代码来源:I18nRouteCollection.php

示例8: flush

 /**
  * Persists and freezes staged controllers.
  *
  * @param string $prefix
  *
  * @return RouteCollection A RouteCollection instance
  */
 public function flush($prefix = '')
 {
     $routes = new RouteCollection();
     foreach ($this->controllers as $controller) {
         if (!($name = $controller->getRouteName())) {
             $name = $controller->generateRouteName($prefix);
             while ($routes->get($name)) {
                 $name .= '_';
             }
             $controller->bind($name);
         }
         $routes->add($name, $controller->getRoute());
         $controller->freeze();
     }
     $routes->addPrefix($prefix);
     $this->controllers = array();
     return $routes;
 }
开发者ID:robihidayat,项目名称:silex-mongodb-parks,代码行数:25,代码来源:ControllerCollection.php

示例9: addCollection

    /**
     * Adds a route collection to the current set of routes (at the end of the current set).
     *
     * @param RouteCollection $collection A RouteCollection instance
     * @param string          $prefix     An optional prefix to add before each pattern of the route collection
     */
    public function addCollection(RouteCollection $collection, $prefix = '')
    {
        $collection->addPrefix($prefix);

        $this->routes[] = $collection;
    }
开发者ID:nacef,项目名称:symfony,代码行数:12,代码来源:RouteCollection.php

示例10: testAddPrefixOverridesDefaultsAndRequirements

 public function testAddPrefixOverridesDefaultsAndRequirements()
 {
     $collection = new RouteCollection();
     $collection->add('foo', $foo = new Route('/foo'));
     $collection->add('bar', $bar = new Route('/bar', array(), array('_scheme' => 'http')));
     $collection->addPrefix('/admin', array(), array('_scheme' => 'https'));
     $this->assertEquals('https', $collection->get('foo')->getRequirement('_scheme'), '->addPrefix() overrides existing requirements');
     $this->assertEquals('https', $collection->get('bar')->getRequirement('_scheme'), '->addPrefix() overrides existing requirements');
 }
开发者ID:JPunto,项目名称:Symfony,代码行数:9,代码来源:RouteCollectionTest.php

示例11: getRouteCollections

 public function getRouteCollections()
 {
     /* test case 1 */
     $collection = new RouteCollection();
     $collection->add('overridden', new Route('/overridden'));
     // defaults and requirements
     $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'), array('bar' => 'baz|symfony')));
     // method requirement
     $collection->add('bar', new Route('/bar/{foo}', array(), array('_method' => 'GET|head')));
     // GET method requirement automatically adds HEAD as valid
     $collection->add('barhead', new Route('/barhead/{foo}', array(), array('_method' => 'GET')));
     // simple
     $collection->add('baz', new Route('/test/baz'));
     // simple with extension
     $collection->add('baz2', new Route('/test/baz.html'));
     // trailing slash
     $collection->add('baz3', new Route('/test/baz3/'));
     // trailing slash with variable
     $collection->add('baz4', new Route('/test/{foo}/'));
     // trailing slash and method
     $collection->add('baz5', new Route('/test/{foo}/', array(), array('_method' => 'post')));
     // complex name
     $collection->add('baz.baz6', new Route('/test/{foo}/', array(), array('_method' => 'put')));
     // defaults without variable
     $collection->add('foofoo', new Route('/foofoo', array('def' => 'test')));
     // pattern with quotes
     $collection->add('quoter', new Route('/{quoter}', array(), array('quoter' => '[\']+')));
     // space in pattern
     $collection->add('space', new Route('/spa ce'));
     // prefixes
     $collection1 = new RouteCollection();
     $collection1->add('overridden', new Route('/overridden1'));
     $collection1->add('foo1', new Route('/{foo}'));
     $collection1->add('bar1', new Route('/{bar}'));
     $collection1->addPrefix('/b\'b');
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1);
     $collection2->add('overridden', new Route('/{var}', array(), array('var' => '.*')));
     $collection1 = new RouteCollection();
     $collection1->add('foo2', new Route('/{foo1}'));
     $collection1->add('bar2', new Route('/{bar1}'));
     $collection1->addPrefix('/b\'b');
     $collection2->addCollection($collection1);
     $collection2->addPrefix('/a');
     $collection->addCollection($collection2);
     // overridden through addCollection() and multiple sub-collections with no own prefix
     $collection1 = new RouteCollection();
     $collection1->add('overridden2', new Route('/old'));
     $collection1->add('helloWorld', new Route('/hello/{who}', array('who' => 'World!')));
     $collection2 = new RouteCollection();
     $collection3 = new RouteCollection();
     $collection3->add('overridden2', new Route('/new'));
     $collection3->add('hey', new Route('/hey/'));
     $collection2->addCollection($collection3);
     $collection1->addCollection($collection2);
     $collection1->addPrefix('/multi');
     $collection->addCollection($collection1);
     // "dynamic" prefix
     $collection1 = new RouteCollection();
     $collection1->add('foo3', new Route('/{foo}'));
     $collection1->add('bar3', new Route('/{bar}'));
     $collection1->addPrefix('/b');
     $collection1->addPrefix('{_locale}');
     $collection->addCollection($collection1);
     // route between collections
     $collection->add('ababa', new Route('/ababa'));
     // collection with static prefix but only one route
     $collection1 = new RouteCollection();
     $collection1->add('foo4', new Route('/{foo}'));
     $collection1->addPrefix('/aba');
     $collection->addCollection($collection1);
     // prefix and host
     $collection1 = new RouteCollection();
     $route1 = new Route('/route1', array(), array(), array(), 'a.example.com');
     $collection1->add('route1', $route1);
     $collection2 = new RouteCollection();
     $route2 = new Route('/c2/route2', array(), array(), array(), 'a.example.com');
     $collection1->add('route2', $route2);
     $route3 = new Route('/c2/route3', array(), array(), array(), 'b.example.com');
     $collection1->add('route3', $route3);
     $route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
     $collection1->add('route4', $route4);
     $route5 = new Route('/route5', array(), array(), array(), 'c.example.com');
     $collection1->add('route5', $route5);
     $route6 = new Route('/route6', array(), array(), array(), null);
     $collection1->add('route6', $route6);
     $collection->addCollection($collection1);
     // host and variables
     $collection1 = new RouteCollection();
     $route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com');
     $collection1->add('route11', $route11);
     $route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com');
     $collection1->add('route12', $route12);
     $route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com');
     $collection1->add('route13', $route13);
     $route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com');
     $collection1->add('route14', $route14);
     $route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com');
     $collection1->add('route15', $route15);
     $route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null);
//.........这里部分代码省略.........
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:101,代码来源:PhpMatcherDumperTest.php

示例12: initRouting

/**
 * @param ContainerInterface $container
 * @return UrlMatcher
 */
function initRouting(ContainerInterface $container)
{
    $routeCollection = new RouteCollection();
    $viewRoute = new Route('/view', ['_controller' => 'Crud', '_action' => 'view']);
    $routeCollection->add('crud_view', $viewRoute);
    $addRoute = new Route('/add', ['_controller' => 'Crud', '_action' => 'add']);
    $routeCollection->add('crud_add', $addRoute);
    $editRoute = new Route('/edit/{id}', ['_controller' => 'Crud', '_action' => 'edit'], ['id' => '.+']);
    $routeCollection->add('crud_edit', $editRoute);
    $routeCollection->addPrefix('/{_locale}/crud');
    $routeCollection->addDefaults(['_locale' => 'ru']);
    $routeCollection->addRequirements(['_locale' => 'ru|en']);
    $locator = new FileLocator([SRC_PATH . 'Resources/config']);
    $loader = new YamlFileLoader($locator);
    $collection = $loader->load('routes.yml');
    $routeCollection->addCollection($collection);
    $closureLoader = new ClosureLoader();
    $collection = $closureLoader->load(function () {
        return new RouteCollection();
    });
    $requestContext = new RequestContext();
    $requestContext->fromRequest(Request::createFromGlobals());
    $matcher = new UrlMatcher($routeCollection, $requestContext);
    $container->set('url_matcher', $matcher);
    $urlGenerator = new UrlGenerator($routeCollection, $requestContext);
    $container->set('url_generator', $urlGenerator);
    return $matcher;
}
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:32,代码来源:init.php

示例13: testCannotRelyOnPrefix

 public function testCannotRelyOnPrefix()
 {
     $coll = new RouteCollection();
     $subColl = new RouteCollection();
     $subColl->add('bar', new Route('/bar'));
     $subColl->addPrefix('/prefix');
     // overwrite the pattern, so the prefix is not valid anymore for this route in the collection
     $subColl->get('bar')->setPattern('/new');
     $coll->addCollection($subColl);
     $matcher = new UrlMatcher($coll, new RequestContext());
     $this->assertEquals(array('_route' => 'bar'), $matcher->match('/new'));
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:12,代码来源:UrlMatcherTest.php

示例14: getRouteCollection

 private function getRouteCollection()
 {
     $collection = new RouteCollection();
     // defaults and requirements
     $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'), array('bar' => 'baz|symfony')));
     // defaults parameters in pattern
     $collection->add('foobar', new Route('/foo/{bar}', array('bar' => 'toto')));
     // method requirement
     $collection->add('bar', new Route('/bar/{foo}', array(), array('_method' => 'GET|head')));
     // method requirement (again)
     $collection->add('baragain', new Route('/baragain/{foo}', array(), array('_method' => 'get|post')));
     // simple
     $collection->add('baz', new Route('/test/baz'));
     // simple with extension
     $collection->add('baz2', new Route('/test/baz.html'));
     // trailing slash
     $collection->add('baz3', new Route('/test/baz3/'));
     // trailing slash with variable
     $collection->add('baz4', new Route('/test/{foo}/'));
     // trailing slash and safe method
     $collection->add('baz5', new Route('/test/{foo}/', array(), array('_method' => 'get')));
     // trailing slash and unsafe method
     $collection->add('baz5unsafe', new Route('/testunsafe/{foo}/', array(), array('_method' => 'post')));
     // complex
     $collection->add('baz6', new Route('/test/baz', array('foo' => 'bar baz')));
     // space in path
     $collection->add('baz7', new Route('/te st/baz'));
     // space preceded with \ in path
     $collection->add('baz8', new Route('/te\\ st/baz'));
     // space preceded with \ in requirement
     $collection->add('baz9', new Route('/test/{baz}', array(), array('baz' => 'te\\\\ st')));
     $collection1 = new RouteCollection();
     $route1 = new Route('/route1', array(), array(), array(), 'a.example.com');
     $collection1->add('route1', $route1);
     $collection2 = new RouteCollection();
     $route2 = new Route('/route2', array(), array(), array(), 'a.example.com');
     $collection2->add('route2', $route2);
     $route3 = new Route('/route3', array(), array(), array(), 'b.example.com');
     $collection2->add('route3', $route3);
     $collection2->addPrefix('/c2');
     $collection1->addCollection($collection2);
     $route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
     $collection1->add('route4', $route4);
     $route5 = new Route('/route5', array(), array(), array(), 'c.example.com');
     $collection1->add('route5', $route5);
     $route6 = new Route('/route6', array(), array(), array(), null);
     $collection1->add('route6', $route6);
     $collection->addCollection($collection1);
     // host and variables
     $collection1 = new RouteCollection();
     $route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com');
     $collection1->add('route11', $route11);
     $route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com');
     $collection1->add('route12', $route12);
     $route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com');
     $collection1->add('route13', $route13);
     $route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com');
     $collection1->add('route14', $route14);
     $route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com');
     $collection1->add('route15', $route15);
     $route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null);
     $collection1->add('route16', $route16);
     $route17 = new Route('/route17', array(), array(), array(), null);
     $collection1->add('route17', $route17);
     $collection->addCollection($collection1);
     return $collection;
 }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:67,代码来源:LegacyApacheMatcherDumperTest.php

示例15: addCollection

 /**
  * Adds a route collection to the current set of routes (at the end of the current set).
  *
  * @param RouteCollection $collection A RouteCollection instance
  * @param string          $prefix     An optional prefix to add before each pattern of the route collection
  *
  * @api
  */
 public function addCollection(RouteCollection $collection, $prefix = '')
 {
     $collection->setParent($this);
     $collection->addPrefix($prefix);
     // remove all routes with the same name in all existing collections
     foreach (array_keys($collection->all()) as $name) {
         $this->remove($name);
     }
     $this->routes[] = $collection;
 }
开发者ID:hermann106,项目名称:PasaGlProject,代码行数:18,代码来源:RouteCollection.php


注:本文中的Symfony\Component\Routing\RouteCollection::addPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。