本文整理匯總了PHP中Symfony\Component\Routing\RouteCollection::getResources方法的典型用法代碼示例。如果您正苦於以下問題:PHP RouteCollection::getResources方法的具體用法?PHP RouteCollection::getResources怎麽用?PHP RouteCollection::getResources使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Routing\RouteCollection
的用法示例。
在下文中一共展示了RouteCollection::getResources方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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());
}
示例4: load
public function load(RouteCollection $collection)
{
$i18nCollection = new RouteCollection();
foreach ($collection->getResources() as $resource) {
$i18nCollection->addResource($resource);
}
$this->patternGenerationStrategy->addResources($i18nCollection);
$existedHomepage = [];
foreach ($collection->all() as $name => $route) {
if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
$i18nCollection->add($name, $route);
continue;
}
$patters = $this->patternGenerationStrategy->generateI18nPatterns($name, $route);
foreach ($patters as $pattern => $hostLocales) {
// 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.
foreach ($hostLocales as $host => $locales) {
if (count($locales) > 1) {
$catchMultipleRoute = clone $route;
$catchMultipleRoute->setPath($pattern);
$catchMultipleRoute->setHost($host);
$catchMultipleRoute->setRequirement('_locale', implode('|', $locales));
$catchMultipleRoute->setOption('original_name', $name)->setOption('locales', $locales);
$i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchMultipleRoute);
} elseif (count($locales) == 1) {
$catchRoute = clone $route;
$catchRoute->setPath($pattern);
$catchRoute->setHost($host);
$catchRoute->setDefault('_locale', $locales[0]);
$catchRoute->setRequirement('_locale', $locales[0]);
$catchRoute->setOption('original_name', $name)->setOption('locales', $locales);
$i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchRoute);
}
if ($pattern == '/') {
$existedHomepage[] = $host;
}
}
}
}
$offices = $this->entityManager->getRepository('OctavaMuiBundle:Office')->getRoutingOffices();
foreach ($offices as $locale => $office) {
if ($office->getIncludeLangInUrl() && !in_array($office->getHost(), $existedHomepage)) {
$redirectRoute = new Route('/', ['_controller' => 'FrameworkBundle:Redirect:urlRedirect', 'path' => '/' . $locale . '/', 'permanent' => true]);
$redirectRoute->setHost($office->getHost());
$i18nCollection->add($locale . I18nLoader::ROUTING_PREFIX . 'redirect_to_root', $redirectRoute);
}
}
return $i18nCollection;
}
示例5: setMatcher
/**
* Gets the UrlMatcher instance associated with this Router.
*
* @return UrlMatcherInterface A UrlMatcherInterface instance
*/
public function setMatcher()
{
$class = "app" . $this->environment . $this->options['matcher_cache_class'];
$this->file = $this->options['cache_dir'] . '/' . $class . '.php';
$cache = new ConfigCache($this->file, false);
// //if (!$cache->isFresh($class))
//if (!$cache->isFresh($class)) {
$dumper = new $this->options['matcher_dumper_class']($this->collection);
$options = array('class' => $class, 'base_class' => $this->options['matcher_base_class']);
try {
$cache->write($dumper->dump($options), $this->collection->getResources());
} catch (\Exception $e) {
}
//}
}
示例6: 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;
}
示例7: cloneWithoutHidden
/**
* Copies all routers not marked as hidden from a source to a destination collection.
* If the destination collection is not specifies the new instance of RouteCollection will be used.
*
* @param RouteCollection $src The source route collection
* @param RouteCollection|null $dest The destination route collection
*
* @return RouteCollection The destination route collection
*/
public static function cloneWithoutHidden(RouteCollection $src, RouteCollection $dest = null)
{
if (null === $dest) {
$dest = new RouteCollection();
}
$routes = $src->all();
foreach ($routes as $name => $route) {
if (!$route->getOption('hidden')) {
$dest->add($name, $route);
}
}
$resources = $src->getResources();
foreach ($resources as $resource) {
$dest->addResource($resource);
}
return $dest;
}
示例8: 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());
}
示例9: 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
*/
public function addCollection(RouteCollection $collection)
{
// 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());
}
示例10: testResource
public function testResource()
{
if (!class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$this->markTestSkipped('The "Config" component is not available');
}
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource(__DIR__ . '/Fixtures/foo.xml'));
$this->assertEquals(array($foo), $collection->getResources(), '->addResources() adds a resource');
}
示例11: testResource
public function testResource()
{
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource(__DIR__ . '/Fixtures/foo.xml'));
$collection->addResource($bar = new FileResource(__DIR__ . '/Fixtures/bar.xml'));
$collection->addResource(new FileResource(__DIR__ . '/Fixtures/foo.xml'));
$this->assertEquals(array($foo, $bar), $collection->getResources(), '->addResource() adds a resource and getResources() only returns unique ones by comparing the string representation');
}
示例12: testResource
public function testResource()
{
if (!class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$this->markTestSkipped('The "Config" component is not available');
}
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource(__DIR__ . '/Fixtures/foo.xml'));
$collection->addResource($bar = new FileResource(__DIR__ . '/Fixtures/bar.xml'));
$collection->addResource(new FileResource(__DIR__ . '/Fixtures/foo.xml'));
$this->assertEquals(array($foo, $bar), $collection->getResources(), '->addResource() adds a resource and getResources() only returns unique ones by comparing the string representation');
}
示例13: testResource
public function testResource()
{
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource(__DIR__ . '/Fixtures/foo.xml'));
$this->assertEquals(array($foo), $collection->getResources(), '->addResources() adds a resource');
}