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


PHP RouteCollection::addResource方法代码示例

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


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

示例1: load

    public function load($resource, $type = null)
    {
        $collection = new RouteCollection();

        foreach ($this->adminFactory->getAdmins() as $adminId => $admin) {
            $routePatternPrefix = $admin->getRoutePatternPrefix();
            $routeNamePrefix = $admin->getRouteNamePrefix();

            foreach ($admin->getActions() as $action) {
                $defaults = array(
                    '_controller' => 'WhiteOctoberAdminBundle:Admin:execute',
                    '_white_october_admin.admin'  => $adminId,
                    '_white_october_admin.action' => $action->getFullName(),
                );
                $defaults = array_merge($action->getRouteDefaults(), $defaults);
                $route = new Route($routePatternPrefix.$action->getRoutePatternSuffix(), $defaults, $action->getRouteRequirements());

                $collection->add($ups = $routeNamePrefix.'_'.$action->getRouteNameSuffix(), $route);

                $reflection = new \ReflectionObject($action);
                $collection->addResource(new FileResource($reflection->getFileName()));
            }

            $reflection = new \ReflectionObject($admin);
            $collection->addResource(new FileResource($reflection->getFileName()));
        }

        return $collection;
    }
开发者ID:nibsirahsieu,项目名称:WhiteOctoberAdminBundle,代码行数:29,代码来源:AdminFactoryLoader.php

示例2: load

 /**
  * {@inheritDoc}
  */
 public function load($resource, $type = null)
 {
     $collection = new SymfonyRouteCollection();
     foreach ($this->adminServiceIds as $id) {
         $admin = $this->pool->getInstance($id);
         foreach ($admin->getRoutes()->getElements() as $code => $route) {
             $collection->add($route->getDefault('_sonata_name'), $route);
         }
         $reflection = new \ReflectionObject($admin);
         $collection->addResource(new FileResource($reflection->getFileName()));
     }
     $reflection = new \ReflectionObject($this->container);
     $collection->addResource(new FileResource($reflection->getFileName()));
     return $collection;
 }
开发者ID:kwuerl,项目名称:SonataAdminBundle,代码行数:18,代码来源:AdminPoolLoader.php

示例3: load

 public function load(RouteCollection $collection)
 {
     $i18nCollection = new RouteCollection();
     // add translation resources
     foreach ($this->locales as $locale) {
         if (file_exists($metadata = $this->cacheDir . '/translations/catalogue.' . $locale . '.php.meta')) {
             foreach (unserialize(file_get_contents($metadata)) as $resource) {
                 $i18nCollection->addResource($resource);
             }
         }
     }
     // add route resources
     foreach ($collection->getResources() as $resource) {
         $i18nCollection->addResource($resource);
     }
     foreach ($collection->all() as $name => $route) {
         if ($this->isNotTranslatable($name, $route)) {
             $i18nCollection->add($name, $route);
             continue;
         }
         $keepOriginal = false;
         $translations = new RouteCollection();
         $patterns = array();
         foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) {
             $i18nRoute = clone $route;
             // if no translation exists, we use the current pattern
             if ($name === ($i18nPattern = $this->translator->trans($name, array(), $this->catalogue, $locale))) {
                 $i18nPattern = $route->getPattern();
             }
             // prefix with locale if requested
             if (I18nRouter::STRATEGY_PREFIX === $this->strategy || I18nRouter::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) {
                 $i18nPattern = '/' . $locale . $i18nPattern;
             }
             if (isset($patterns[$i18nPattern])) {
                 $keepOriginal = true;
             }
             $patterns[$i18nPattern] = true;
             $i18nRoute->setPattern($i18nPattern);
             $i18nRoute->setDefault('_locale', $locale);
             $translations->add($locale . '_' . $name, $i18nRoute);
         }
         if ($keepOriginal || $route->getOption('i18n_keep')) {
             $i18nCollection->add($name, $route);
         }
         $i18nCollection->addCollection($translations);
     }
     return $i18nCollection;
 }
开发者ID:natxet,项目名称:JMSI18nRoutingBundle,代码行数:48,代码来源:I18nLoader.php

示例4: testImport

 public function testImport()
 {
     $resolvedLoader = $this->getMock('Symfony\\Component\\Config\\Loader\\LoaderInterface');
     $resolver = $this->getMock('Symfony\\Component\\Config\\Loader\\LoaderResolverInterface');
     $resolver->expects($this->once())->method('resolve')->with('admin_routing.yml', 'yaml')->will($this->returnValue($resolvedLoader));
     $originalRoute = new Route('/foo/path');
     $expectedCollection = new RouteCollection();
     $expectedCollection->add('one_test_route', $originalRoute);
     $expectedCollection->addResource(new FileResource(__DIR__ . '/Fixtures/file_resource.yml'));
     $resolvedLoader->expects($this->once())->method('load')->with('admin_routing.yml', 'yaml')->will($this->returnValue($expectedCollection));
     $loader = $this->getMock('Symfony\\Component\\Config\\Loader\\LoaderInterface');
     $loader->expects($this->any())->method('getResolver')->will($this->returnValue($resolver));
     // import the file!
     $routes = new RouteCollectionBuilder($loader);
     $importedRoutes = $routes->import('admin_routing.yml', '/', 'yaml');
     // we should get back a RouteCollectionBuilder
     $this->assertInstanceOf('Symfony\\Component\\Routing\\RouteCollectionBuilder', $importedRoutes);
     // get the collection back so we can look at it
     $addedCollection = $importedRoutes->build();
     $route = $addedCollection->get('one_test_route');
     $this->assertSame($originalRoute, $route);
     // should return file_resource.yml, which is in the original collection
     $this->assertCount(1, $addedCollection->getResources());
     // make sure the routes were imported into the top-level builder
     $this->assertCount(1, $routes->build());
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:26,代码来源:RouteCollectionBuilderTest.php

示例5: beatrixLoad

 public function beatrixLoad($file, $cache, $readCache = true)
 {
     $path = $this->locator->locate($file);
     $config = $cache->file('beatrixRoutes', $path, 'yml', $readCache);
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($path));
     // empty file
     if (null === $config) {
         return $collection;
     }
     // not an array
     if (!is_array($config)) {
         throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
     }
     foreach ($config as $name => $config) {
         if (isset($config['pattern'])) {
             if (isset($config['path'])) {
                 throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
             }
             $config['path'] = $config['pattern'];
             unset($config['pattern']);
         }
         $this->validate($config, $name, $path);
         if (isset($config['resource'])) {
             $this->parseImport($collection, $config, $path, $file);
         } else {
             $this->parseRoute($collection, $name, $config, $path);
         }
     }
     return $collection;
 }
开发者ID:cangit,项目名称:beatrix,代码行数:31,代码来源:YamlFileLoader.php

示例6: load

 /**
  * Loads a Yaml file.
  *
  * @param string      $file A Yaml file path
  * @param string|null $type The resource type
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When a route can't be parsed because YAML is invalid
  *
  * @api
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     if (!stream_is_local($path)) {
         throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
     }
     if (!file_exists($path)) {
         throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
     }
     if (null === $this->yamlParser) {
         $this->yamlParser = new YamlParser();
     }
     $config = $this->yamlParser->parse(file_get_contents($path));
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($path));
     // empty file
     if (null === $config) {
         return $collection;
     }
     // not an array
     if (!is_array($config)) {
         throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
     }
     foreach ($config as $name => $config) {
         $this->validate($config, $name, $path);
         if (isset($config['resource'])) {
             $this->parseImport($collection, $config, $path, $file);
         } else {
             $this->parseRoute($collection, $name, $config, $path);
         }
     }
     return $collection;
 }
开发者ID:nuwe1,项目名称:symfony,代码行数:45,代码来源:YamlFileLoader.php

示例7: testCloneWithoutHiddenWithExistingDestination

 public function testCloneWithoutHiddenWithExistingDestination()
 {
     $src = new RouteCollection();
     $src->add('route1', new Route('/route1'));
     $src->add('route2', new Route('/route2', [], [], ['hidden' => true]));
     $src->add('route3', new Route('/route3', [], [], ['hidden' => false]));
     $src->addResource(new DirectoryResource('resource1'));
     $src->addResource(new DirectoryResource('resource2'));
     $dest = new RouteCollection();
     $result = RouteCollectionUtil::cloneWithoutHidden($src, $dest);
     $this->assertSame($dest, $result);
     $this->assertCount(2, $result);
     $this->assertNotNull($result->get('route1'));
     $this->assertNotNull($result->get('route3'));
     $this->assertCount(2, $result->getResources());
 }
开发者ID:startupz,项目名称:platform-1,代码行数:16,代码来源:RouteCollectionUtilTest.php

示例8: load

 /**
  * Loads a JSON file
  *
  * @param string      $file A JSON file path
  * @param string|null $type The resource type
  *
  * @return RouteCollection
  *
  * @throws InvalidArgumentException When the JSON is invalid
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     if (!stream_is_local($path)) {
         $message = sprintf('This is not a local file "%s"', $path);
         throw new InvalidArgumentException($message);
     }
     if (!file_exists($path)) {
         $message = sprintf('File "%s" not found', $path);
         throw new InvalidArgumentException($message);
     }
     $parsedConfig = json_decode(file_get_contents($path), true);
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($path));
     // empty file
     if ($parsedConfig === null) {
         return $collection;
     }
     // not an array
     if (!is_array($parsedConfig)) {
         $message = sprintf('The file "%s" must contain a JSON object', $path);
         throw new InvalidArgumentException($message);
     }
     foreach ($parsedConfig as $name => $config) {
         $this->validate($config, $name, $path);
         if (isset($config['resource'])) {
             $this->parseImport($collection, $config, $path, $file);
         } else {
             $this->parseRoute($collection, $name, $config, $path);
         }
     }
     return $collection;
 }
开发者ID:novuso,项目名称:common-bundle,代码行数:43,代码来源:JsonFileLoader.php

示例9: getRouteCollection

 /**
  * {@inheritdoc}
  */
 public function getRouteCollection()
 {
     static $i18nCollection;
     if ($i18nCollection instanceof RouteCollection === false) {
         if (null === $this->collection) {
             $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
         }
         $i18nCollection = new RouteCollection();
         foreach ($this->collection->getResources() as $resource) {
             $i18nCollection->addResource($resource);
         }
         foreach ($this->collection->all() as $name => $route) {
             //do not add i18n routing prefix
             if ($this->shouldExcludeRoute($name, $route)) {
                 $i18nCollection->add($name, $route);
                 continue;
             }
             //add i18n routing prefix
             foreach ($this->generateI18nPatterns($name, $route) as $pattern => $locales) {
                 foreach ($locales as $locale) {
                     $localeRoute = clone $route;
                     $localeRoute->setPath($pattern);
                     $localeRoute->setDefault('_locale', $locale);
                     $i18nCollection->add($locale . self::ROUTING_PREFIX . $name, $localeRoute);
                 }
             }
         }
     }
     return $i18nCollection;
 }
开发者ID:pitpit,项目名称:HipI18nRoutingBundle,代码行数:33,代码来源:I18nRouter.php

示例10: load

 public function load($resource, $type = null)
 {
     $collection = new RouteCollection();
     $resource = str_replace('\\', '/', $resource);
     $namespace = $this->getNamespaceFromResource($resource);
     $bundle_name = $this->getBundleNameFromResource($resource);
     foreach ($this->actions as $controller => $datas) {
         $action = 'index';
         if ($controller_folder = $this->getControllerFolder($resource)) {
             $route_name = str_replace(array('/', '\\'), '_', $namespace) . '_' . $bundle_name . '_' . $controller_folder . '_' . $controller;
         } else {
             $route_name = str_replace(array('/', '\\'), '_', $namespace) . '_' . $bundle_name . '_' . $controller;
         }
         if (isset($datas['controller'])) {
             $action = $controller;
             $controller = $datas['controller'];
         }
         if ($controller_folder) {
             $datas['defaults']['_controller'] = $namespace . '\\' . $bundle_name . '\\Controller\\' . $controller_folder . '\\' . ucfirst($controller) . 'Controller::' . $action . 'Action';
         } else {
             $datas['defaults']['_controller'] = str_replace(array('/', '\\'), '_', $namespace) . $bundle_name . ':' . ucfirst($controller) . ':' . $action;
         }
         $route = new Route($datas['pattern'], $datas['defaults'], $datas['requirements']);
         $collection->add($route_name, $route);
         $collection->addResource(new FileResource($resource . ucfirst($controller) . 'Controller.php'));
     }
     return $collection;
 }
开发者ID:nibsirahsieu,项目名称:AdmingeneratorGeneratorBundle,代码行数:28,代码来源:RoutingLoader.php

示例11: load

 public function load(RouteCollection $collection)
 {
     $i18nCollection = new RouteCollection();
     foreach ($collection->getResources() as $resource) {
         $i18nCollection->addResource($resource);
     }
     $this->patternGenerationStrategy->addResources($i18nCollection);
     foreach ($collection->all() as $name => $route) {
         if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
             $i18nCollection->add($name, $route);
             continue;
         }
         foreach ($this->patternGenerationStrategy->generateI18nPatterns($name, $route) as $pattern => $locales) {
             // If this pattern is used for more than one locale, we need to keep the original route.
             // We still add individual routes for each locale afterwards for faster generation.
             if (count($locales) > 1) {
                 $catchMultipleRoute = clone $route;
                 $catchMultipleRoute->getPath($pattern);
                 $catchMultipleRoute->setDefault('_locales', $locales);
                 $i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchMultipleRoute);
             }
             foreach ($locales as $locale) {
                 $localeRoute = clone $route;
                 $localeRoute->getPath($pattern);
                 $localeRoute->setDefault('_locale', $locale);
                 $i18nCollection->add($locale . I18nLoader::ROUTING_PREFIX . $name, $localeRoute);
             }
         }
     }
     return $i18nCollection;
 }
开发者ID:AntoineLemaire,项目名称:JMSI18nRoutingBundle,代码行数:31,代码来源:I18nLoader.php

示例12: load

 public function load($routingResource, $type = null)
 {
     $routes = new RouteCollection();
     // resources
     foreach ($this->am->getResources() as $resources) {
         if (!$resources instanceof \Traversable) {
             $resources = array($resources);
         }
         foreach ($resources as $resource) {
             if (file_exists($path = (string) $resource)) {
                 $routes->addResource(new FileResource($path));
             }
         }
     }
     // routes
     foreach ($this->am->getNames() as $name) {
         $asset = $this->am->get($name);
         $defaults = array('_controller' => 'assetic.controller:render', 'name' => $name);
         if ($extension = pathinfo($asset->getTargetUrl(), PATHINFO_EXTENSION)) {
             $defaults['_format'] = $extension;
         }
         $routes->add('assetic_' . $name, new Route($asset->getTargetUrl(), $defaults));
     }
     return $routes;
 }
开发者ID:rooster,项目名称:symfony,代码行数:25,代码来源:AsseticLoader.php

示例13: load

 public function load($routingResource, $type = null)
 {
     $routes = new RouteCollection();
     // resources
     foreach ($this->am->getResources() as $resources) {
         if (!$resources instanceof \Traversable) {
             $resources = array($resources);
         }
         foreach ($resources as $resource) {
             $routes->addResource(new AsseticResource($resource));
         }
     }
     // routes
     foreach ($this->am->getNames() as $name) {
         $asset = $this->am->get($name);
         $formula = $this->am->getFormula($name);
         $this->loadRouteForAsset($routes, $asset, $name);
         $debug = isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug();
         $combine = isset($formula[2]['combine']) ? $formula[2]['combine'] : !$debug;
         // add a route for each "leaf" in debug mode
         if (!$combine) {
             $i = 0;
             foreach ($asset as $leaf) {
                 $this->loadRouteForAsset($routes, $leaf, $name, $i++);
             }
         }
     }
     return $routes;
 }
开发者ID:fotomerchant,项目名称:AsseticBundle,代码行数:29,代码来源:AsseticLoader.php

示例14: load

 /**
  * Loads an XML file.
  *
  * @param string $file An XML file path
  * @param string $type The resource type
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When a tag can't be parsed
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     $xml = $this->loadFile($path);
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($path));
     // process routes and imports
     foreach ($xml->documentElement->childNodes as $node) {
         if (!$node instanceof \DOMElement) {
             continue;
         }
         switch ($node->tagName) {
             case 'route':
                 $this->parseRoute($collection, $node, $path);
                 break;
             case 'import':
                 $resource = (string) $node->getAttribute('resource');
                 $type = (string) $node->getAttribute('type');
                 $prefix = (string) $node->getAttribute('prefix');
                 $this->currentDir = dirname($path);
                 $collection->addCollection($this->import($resource, '' !== $type ? $type : null), $prefix);
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
         }
     }
     return $collection;
 }
开发者ID:noelg,项目名称:symfony-demo,代码行数:38,代码来源:XmlFileLoader.php

示例15: load

 /**
  * Loads a Yaml file.
  *
  * @param string $file A Yaml file path
  * @param string $type The resource type
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When route can't be parsed
  *
  * @api
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     $config = Yaml::parse($path);
     $collection = new RouteCollection();
     $collection->addResource(new FileResource($path));
     // empty file
     if (null === $config) {
         $config = array();
     }
     // not an array
     if (!is_array($config)) {
         throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file));
     }
     foreach ($config as $name => $config) {
         $config = $this->normalizeRouteConfig($config);
         if (isset($config['resource'])) {
             $type = isset($config['type']) ? $config['type'] : null;
             $prefix = isset($config['prefix']) ? $config['prefix'] : null;
             $defaults = isset($config['defaults']) ? $config['defaults'] : array();
             $requirements = isset($config['requirements']) ? $config['requirements'] : array();
             $options = isset($config['options']) ? $config['options'] : array();
             $this->setCurrentDir(dirname($path));
             $collection->addCollection($this->import($config['resource'], $type, false, $file), $prefix, $defaults, $requirements, $options);
         } else {
             $this->parseRoute($collection, $name, $config, $path);
         }
     }
     return $collection;
 }
开发者ID:laubosslink,项目名称:lab,代码行数:42,代码来源:YamlFileLoader.php


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