本文整理汇总了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;
}
示例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());
}
示例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);
}
}
}
}
示例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);
}
}
示例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);
}
}
示例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]);
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
}
示例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);
}
示例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;
}
}
}
}
}
示例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));
}
示例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?");
}
}
}
}