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


PHP RouterInterface::getRouteCollection方法代码示例

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


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

示例1: logVisitor

 public function logVisitor(UserEvent $userEvent)
 {
     // call another method?
     dump($this->router->getRouteCollection());
     dump($userEvent->getUserId());
     die;
 }
开发者ID:TomasVotruba,项目名称:erudio-se-skoli,代码行数:7,代码来源:LogVisitorSubscriber.php

示例2: warmUp

 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $processedRoutes = array();
     $routeCollection = $this->router->getRouteCollection();
     foreach ($routeCollection->all() as $name => $route) {
         if (!isset($processedRoutes[$route->getPattern()])) {
             $processedRoutes[$route->getPattern()] = array('methods' => array(), 'names' => array());
         }
         $processedRoutes[$route->getPattern()]['names'][] = $name;
         $requirements = $route->getRequirements();
         if (isset($requirements['_method'])) {
             $methods = explode('|', $requirements['_method']);
             $processedRoutes[$route->getPattern()]['methods'] = array_merge($processedRoutes[$route->getPattern()]['methods'], $methods);
         }
     }
     $allowedMethods = array();
     foreach ($processedRoutes as $processedRoute) {
         if (count($processedRoute['methods']) > 0) {
             foreach ($processedRoute['names'] as $name) {
                 $allowedMethods[$name] = array_unique($processedRoute['methods']);
             }
         }
     }
     $this->cache->write(sprintf('<?php return %s;', var_export($allowedMethods, true)), $routeCollection->getResources());
 }
开发者ID:kasobus,项目名称:EDENS-Mautic,代码行数:28,代码来源:AllowedMethodsRouterLoader.php

示例3: dump

 /**
  * Dumps all translation files.
  *
  * @param string  $targetDir Target directory.
  * @param boolean $symlink   True if generate symlink
  *
  * @return null
  */
 public function dump($targetDir = 'web', $symlink = false, $directory = null)
 {
     $route = $this->router->getRouteCollection()->get('bazinga_exposetranslation_js');
     $directory = null === $directory ? $this->kernel->getRootDir() . '/../' : $directory;
     $requirements = $route->getRequirements();
     $formats = explode('|', $requirements['_format']);
     $routeDefaults = $route->getDefaults();
     $defaultFormat = $routeDefaults['_format'];
     $parts = array_filter(explode('/', $route->getPattern()));
     $this->filesystem->remove($directory . $targetDir . "/" . current($parts));
     foreach ($this->getTranslationMessages() as $locale => $domains) {
         foreach ($domains as $domain => $messageList) {
             foreach ($formats as $format) {
                 $content = $this->engine->render('BazingaExposeTranslationBundle::exposeTranslation.' . $format . '.twig', array('messages' => array($domain => $messageList), 'locale' => $locale, 'defaultDomains' => $domain));
                 $path[$format] = $directory . $targetDir . strtr($route->getPattern(), array('{domain_name}' => $domain, '{_locale}' => $locale, '{_format}' => $format));
                 $this->filesystem->mkdir(dirname($path[$format]), 0777);
                 if (file_exists($path[$format])) {
                     $this->filesystem->remove($path[$format]);
                 }
                 file_put_contents($path[$format], $content);
             }
             $targetFile = $directory . $targetDir;
             $targetFile .= strtr($route->getPattern(), array('{domain_name}' => $domain, '{_locale}' => $locale, '.{_format}' => ''));
             if (true === $symlink) {
                 $this->filesystem->symlink($path[$defaultFormat], $targetFile);
             } else {
                 $this->filesystem->copy($path[$defaultFormat], $targetFile);
             }
         }
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:39,代码来源:TranslationDumper.php

示例4: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $routes = $this->router->getRouteCollection();
     $route = $routes->get($request->attributes->get('_route'));
     if (!$route->getOption('requires_license')) {
         return;
     }
     if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
         // Checking for whitelisted users
         try {
             $user = $this->tokenStorage->getToken()->getUser();
             $today = date('Y-m-d');
             if ($user instanceof UserInterface) {
                 $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
                 foreach ($whitelist as $allowed) {
                     if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
                         return;
                     }
                 }
             }
         } catch (\Exception $e) {
             // Do nothing
         }
         $url = $this->router->generate('atlassian_connect_unlicensed');
         $response = new RedirectResponse($url);
         $event->setResponse($response);
     }
 }
开发者ID:sainthardaway,项目名称:atlassian-connect-bundle,代码行数:32,代码来源:LicenseListener.php

示例5: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $format = null;
     if (is_string($this->forceFormat)) {
         $format = $this->forceFormat;
     } else {
         $request = $event->getRequest();
         if ($this->router instanceof I18nRouter) {
             $collection = $this->router->getOriginalRouteCollection();
         } else {
             $collection = $this->router->getRouteCollection();
         }
         $route = $collection->get($request->get('_route'));
         if (!empty($route)) {
             $defaultFormat = is_null($route->getDefault('_format')) ? 'html' : $route->getDefault('_format');
         } else {
             $defaultFormat = 'html';
         }
         $format = !is_null($request->attributes->get('_format')) ? $request->attributes->get('_format') : $defaultFormat;
     }
     if (!is_null($format)) {
         $serviceName = 'vsymfo_core.service.' . strtolower($format) . '_document';
         if ($this->container->has($serviceName) && $this->container->get($serviceName) instanceof DocumentFactoryInterface) {
             $service = $this->container->get($serviceName);
         } else {
             $service = $this->container->get('vsymfo_core.service.txt_document');
         }
         $doc = $service->createDocument();
         $this->container->get('vsymfo_core.service.document')->setDefaultsToDocument($doc);
         $this->container->set($this->serviceName, $doc);
     }
 }
开发者ID:mikoweb,项目名称:vsymfo-core-bundle,代码行数:35,代码来源:DocumentListener.php

示例6: create

 /**
  * @param array $documentation
  *
  * @return array
  */
 public function create(array $documentation)
 {
     $apiDoc = new ApiDoc($documentation);
     if (array_key_exists('route', $documentation) === true) {
         $apiDoc->setRoute($this->router->getRouteCollection()->get($documentation['route']));
     }
     return array(self::KEY_ANNOTATION => $apiDoc, self::KEY_RESOURCE => $documentation[self::KEY_RESOURCE]);
 }
开发者ID:Waties,项目名称:NelmioApiDocBundle,代码行数:13,代码来源:ApiDocFactory.php

示例7: redirectToResource

 /**
  * {@inheritdoc}
  */
 public function redirectToResource(RequestConfiguration $configuration, ResourceInterface $resource)
 {
     $routes = $this->router->getRouteCollection();
     $redirectRouteName = $configuration->getRedirectRoute(ResourceActions::SHOW);
     if (null === $routes->get($redirectRouteName)) {
         $redirectRouteName = $configuration->getRedirectRoute(ResourceActions::INDEX);
     }
     return $this->redirectToRoute($configuration, $redirectRouteName, $configuration->getRedirectParameters($resource));
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:12,代码来源:RedirectHandler.php

示例8: apply

 /**
  * @param Request                $request
  * @param ParamConverter $configuration
  *
  * @return bool
  *
  * @throws \LogicException
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $classQuery = $configuration->getClass() . 'Query';
     $classPeer = $configuration->getClass() . 'Peer';
     $this->filters = array();
     $this->exclude = array();
     if (!class_exists($classQuery)) {
         throw new \Exception(sprintf('The %s Query class does not exist', $classQuery));
     }
     $tableMap = $classPeer::getTableMap();
     $pkColumns = $tableMap->getPrimaryKeyColumns();
     if (count($pkColumns) == 1) {
         $this->pk = strtolower($pkColumns[0]->getName());
     }
     $options = $configuration->getOptions();
     // Check route options for converter options, if there are non provided.
     if (empty($options) && $request->attributes->has('_route') && $this->router && $configuration instanceof ParamConverter) {
         $converterOption = $this->router->getRouteCollection()->get($request->attributes->get('_route'))->getOption('propel_converter');
         if (!empty($converterOption[$configuration->getName()])) {
             $options = $converterOption[$configuration->getName()];
         }
     }
     if (isset($options['mapping'])) {
         // We use the mapping for calling findPk or filterBy
         foreach ($options['mapping'] as $routeParam => $column) {
             if ($request->attributes->has($routeParam)) {
                 if ($this->pk === $column) {
                     $this->pk = $routeParam;
                 } else {
                     $this->filters[$column] = $request->attributes->get($routeParam);
                 }
             }
         }
     } else {
         $this->exclude = isset($options['exclude']) ? $options['exclude'] : array();
         $this->filters = $request->attributes->all();
     }
     $this->withs = isset($options['with']) ? is_array($options['with']) ? $options['with'] : array($options['with']) : array();
     // find by Pk
     if (false === ($object = $this->findPk($classQuery, $request))) {
         // find by criteria
         if (false === ($object = $this->findOneBy($classQuery, $request))) {
             if ($configuration->isOptional()) {
                 //we find nothing but the object is optional
                 $object = null;
             } else {
                 throw new \LogicException('Unable to guess how to get a Propel object from the request information.');
             }
         }
     }
     if (null === $object && false === $configuration->isOptional()) {
         throw new NotFoundHttpException(sprintf('%s object not found.', $configuration->getClass()));
     }
     $request->attributes->set($configuration->getName(), $object);
     return true;
 }
开发者ID:ChazalFlorian,项目名称:enjoyPangolin,代码行数:66,代码来源:PropelParamConverter.php

示例9: redirectTo

 /**
  * @param object $resource
  *
  * @return RedirectResponse
  */
 public function redirectTo($resource)
 {
     $parameters = $this->config->getRedirectParameters($resource);
     $routes = $this->router->getRouteCollection();
     $route = $this->config->getRedirectRoute('show');
     if (!$routes->get($route)) {
         $route = $this->config->getRedirectRoute('index');
     }
     return $this->redirectToRoute($route, $parameters);
 }
开发者ID:malukenho,项目名称:Sylius,代码行数:15,代码来源:RedirectHandler.php

示例10: getApiViews

 /**
  * @return string
  */
 public function getApiViews()
 {
     $apiViews = [];
     $allRoutes = $this->router->getRouteCollection()->all();
     foreach ($allRoutes as $route) {
         $routeOptions = $route->getOptions();
         if (isset($routeOptions['api_view'])) {
             if (!in_array($routeOptions['api_view'], $apiViews)) {
                 $apiViews[] = $routeOptions['api_view'];
             }
         }
     }
     return $apiViews;
 }
开发者ID:ojs,项目名称:ojs,代码行数:17,代码来源:ApiTwigExtension.php

示例11: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if ($this->router instanceof I18nRouter) {
         $collection = $this->router->getOriginalRouteCollection();
     } else {
         $collection = $this->router->getRouteCollection();
     }
     $route = $collection->get($request->get('_route'));
     if (!empty($route) && $route->hasOption('theme_group')) {
         $group = $route->getOption('theme_group');
         $this->theme->setName($group . '_' . $this->container->getParameter('vsymfo_core.theme_' . $group));
     }
 }
开发者ID:mikoweb,项目名称:vsymfo-core-bundle,代码行数:17,代码来源:ThemeGroupListener.php

示例12: generateObjectUrl

 /**
  * @param mixed $object
  * @param string $routeName #Route
  * @param string $separator
  * @param array $query
  *
  * @return string
  */
 public function generateObjectUrl($object, $routeName, $separator = '_', array $query = array())
 {
     $parameters = array();
     $accessor = PropertyAccess::createPropertyAccessor();
     $pattern = $this->router->getRouteCollection()->get($routeName)->getPath();
     if (preg_match_all('/\\{([a-z]+)\\}/', $pattern, $matches)) {
         foreach ($matches[1] as $holder) {
             $value = $accessor->getValue($object, $holder);
             if (!is_numeric($value)) {
                 $value = $this->slugify->slugify($value, $separator);
             }
             $parameters[$holder] = $value;
         }
     }
     return $this->router->generate($routeName, $parameters, $query);
 }
开发者ID:liverbool,项目名称:dos-resource-bundle,代码行数:24,代码来源:Routing.php

示例13: addRouteParameters

 /**
  * @param string $route
  * @param \SimpleXMLElement $params
  * @param boolean $hidden
  * @param array $options
  */
 protected function addRouteParameters($route, \SimpleXMLElement $params, $hidden, array &$options)
 {
     $options['routeParameters'] = [];
     $parameters = $params->xpath('param');
     if (!empty($parameters)) {
         foreach ($parameters as $param) {
             if (isset($param['name'])) {
                 $options['routeParameters'][(string) $param['name']] = (string) $param;
             }
         }
     }
     if ($hidden) {
         if ($this->router instanceof I18nRouter) {
             $collection = $this->router->getOriginalRouteCollection();
         } else {
             $collection = $this->router->getRouteCollection();
         }
         $route = $collection->get($route);
         $variables = [];
         preg_match_all('#\\{\\w+\\}#', $route->getPath(), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
         foreach ($matches as $match) {
             $variables[] = substr($match[0][0], 1, -1);
         }
         if (!empty($variables)) {
             $defaults = $route->getDefaults();
             foreach ($variables as $variable) {
                 if (!isset($options['routeParameters'][$variable]) && !isset($defaults[$variable])) {
                     $value = $this->request->getCurrentRequest()->attributes->get($variable, '0');
                     $options['routeParameters'][$variable] = empty($value) ? '0' : $value;
                 }
             }
         }
     }
 }
开发者ID:mikoweb,项目名称:vsymfo-core,代码行数:40,代码来源:MenuBuilderAbstract.php

示例14: getExtReference

 /**
  * return the extref from URL
  *
  * @param string $url Extref URL
  * @return ExtReference
  * @throws \InvalidArgumentException
  */
 public function getExtReference($url)
 {
     $path = parse_url($url, PHP_URL_PATH);
     if ($path === false) {
         throw new \InvalidArgumentException(sprintf('URL %s', $url));
     }
     $id = null;
     $collection = null;
     foreach ($this->router->getRouteCollection()->all() as $route) {
         list($collection, $id) = $this->getDataFromRoute($route, $path);
         if ($collection !== null && $id !== null) {
             return ExtReference::create($collection, $id);
         }
     }
     throw new \InvalidArgumentException(sprintf('Could not read URL %s', $url));
 }
开发者ID:alebon,项目名称:graviton,代码行数:23,代码来源:ExtReferenceConverter.php

示例15: buildPageTree

 /**
  * Builds the pagetree
  *
  * @param RouterInterface $router
  *
  * @throws PageTree\InvalidPageTreeException
  */
 private function buildPageTree(RouterInterface $router)
 {
     $this->pageTree = [];
     $this->directAccess = [];
     // collect all routes, which are configured to be in the page tree
     foreach ($router->getRouteCollection() as $routeName => $route) {
         /** @var Route $route */
         $node = $this->transformRouteToNode($routeName, $route);
         if (!is_null($node)) {
             $this->directAccess[$routeName] = $node;
         }
     }
     // apply correct nesting of routes
     foreach ($this->directAccess as $node) {
         if ($node->isRootNode()) {
             $this->pageTree[] = $node;
         } else {
             if (array_key_exists($node->getParent(), $this->directAccess)) {
                 $this->directAccess[$node->getParent()]->addChild($node);
             } else {
                 throw new InvalidPageTreeException("Invalid pagetree at route „{$node->getRoute()}“: parent '{$node->getParent()}' requested, but route was not found. Did you forget to define the route „{$node->getRoute()}“ as root?");
             }
         }
     }
 }
开发者ID:Gemineye,项目名称:BecklynPageTreeBundle,代码行数:32,代码来源:PageTreeModel.php


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