本文整理汇总了PHP中Symfony\Component\Routing\Route::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getPath方法的具体用法?PHP Route::getPath怎么用?PHP Route::getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::getPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateI18nPatterns
/**
* {@inheritDoc}
*/
public function generateI18nPatterns($routeName, Route $route)
{
$patterns = array();
foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) {
// Check if translation exists in the translation catalogue to avoid errors being logged by
// the new LoggingTranslator of Symfony 2.6. However, the LoggingTranslator did not implement
// the interface until Symfony 2.6.5, so an extra check is needed.
if ($this->translator instanceof TranslatorBagInterface || $this->translator instanceof LoggingTranslator) {
// Check if route is translated.
if (!$this->translator->getCatalogue($locale)->has($routeName, $this->translationDomain)) {
// No translation found.
$i18nPattern = $route->getPath();
} else {
// Get translation.
$i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale);
}
} else {
// if no translation exists, we use the current pattern
if ($routeName === ($i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale))) {
$i18nPattern = $route->getPath();
}
}
// prefix with locale if requested
if (self::STRATEGY_PREFIX === $this->strategy || self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) {
$i18nPattern = '/' . $locale . $i18nPattern;
if (null !== $route->getOption('i18n_prefix')) {
$i18nPattern = $route->getOption('i18n_prefix') . $i18nPattern;
}
}
$patterns[$i18nPattern][] = $locale;
}
return $patterns;
}
示例2: testPath
public function testPath()
{
$route = new Route('/{foo}');
$route->setPath('/{bar}');
$this->assertEquals('/{bar}', $route->getPath(), '->setPath() sets the path');
$route->setPath('');
$this->assertEquals('/', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed');
$route->setPath('bar');
$this->assertEquals('/bar', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed');
$this->assertEquals($route, $route->setPath(''), '->setPath() implements a fluent interface');
$route->setPath('//path');
$this->assertEquals('/path', $route->getPath(), '->setPath() does not allow two slahes "//" at the beginning of the path as it would be confused with a network path when generating the path from the route');
}
示例3: generateI18nPatterns
/**
* {@inheritDoc}
*/
public function generateI18nPatterns($routeName, Route $route)
{
$patterns = array();
foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) {
// Check if translation exists in the translation catalogue to avoid errors being logged by
// the new LoggingTranslator of Symfony 2.6. However, the LoggingTranslator did not implement
// the interface until Symfony 2.6.5, so an extra check is needed.
if ($this->translator instanceof TranslatorBagInterface || $this->translator instanceof LoggingTranslator) {
// Check if route is translated.
if (!$this->translator->getCatalogue($locale)->has($routeName, $this->translationDomain)) {
// No translation found.
$i18nPattern = $route->getPath();
} else {
// Get translation.
$i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale);
}
} else {
// if no translation exists, we use the current pattern
if ($routeName === ($i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale))) {
$i18nPattern = $route->getPath();
}
}
///////////////////////////////////////
// Begin customizations
// prefix with zikula module url if requested
if ($route->hasDefault('_zkModule')) {
$module = $route->getDefault('_zkModule');
$zkNoBundlePrefix = $route->getOption('zkNoBundlePrefix');
if (!isset($zkNoBundlePrefix) || !$zkNoBundlePrefix) {
$untranslatedPrefix = $this->getModUrlString($module);
if ($this->translator->getCatalogue($locale)->has($untranslatedPrefix, strtolower($module))) {
$prefix = $this->translator->trans($untranslatedPrefix, [], strtolower($module), $locale);
} else {
$prefix = $untranslatedPrefix;
}
$i18nPattern = "/" . $prefix . $i18nPattern;
}
}
// End customizations
///////////////////////////////////////
// prefix with locale if requested
if (self::STRATEGY_PREFIX === $this->strategy || self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) {
$i18nPattern = '/' . $locale . $i18nPattern;
if (null !== $route->getOption('i18n_prefix')) {
$i18nPattern = $route->getOption('i18n_prefix') . $i18nPattern;
}
}
$patterns[$i18nPattern][] = $locale;
}
return $patterns;
}
示例4: __construct
/**
* Constructs a Route object.
*/
public function __construct($name, Route $route, RouteProviderInterface $route_provider)
{
$this->name = $name;
$this->route = $route;
$this->routeProvider = $route_provider ? $route_provider : \Drupal::service('router.route_provider');
$this->path = new PathUtility($route->getPath());
}
示例5: describeRoute
/**
* {@inheritdoc}
*/
protected function describeRoute(Route $route, array $options = array())
{
$requirements = $route->getRequirements();
unset($requirements['_scheme'], $requirements['_method']);
// fixme: values were originally written as raw
$description = array(
'<comment>Path</comment> '.$route->getPath(),
'<comment>Host</comment> '.('' !== $route->getHost() ? $route->getHost() : 'ANY'),
'<comment>Scheme</comment> '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'),
'<comment>Method</comment> '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'),
'<comment>Class</comment> '.get_class($route),
'<comment>Defaults</comment> '.$this->formatRouterConfig($route->getDefaults()),
'<comment>Requirements</comment> '.$this->formatRouterConfig($requirements) ?: 'NO CUSTOM',
'<comment>Options</comment> '.$this->formatRouterConfig($route->getOptions()),
'<comment>Path-Regex</comment> '.$route->compile()->getRegex(),
);
if (isset($options['name'])) {
array_unshift($description, '<comment>Name</comment> '.$options['name']);
array_unshift($description, $this->formatSection('router', sprintf('Route "%s"', $options['name'])));
}
if (null !== $route->compile()->getHostRegex()) {
$description[] = '<comment>Host-Regex</comment> '.$route->compile()->getHostRegex();
}
$this->writeText(implode("\n", $description)."\n", $options);
}
示例6: describeRoute
/**
* {@inheritdoc}
*/
protected function describeRoute(Route $route, array $options = array())
{
$tableHeaders = array('Property', 'Value');
$tableRows = array(array('Route Name', $options['name']), array('Path', $route->getPath()), array('Path Regex', $route->compile()->getRegex()), array('Host', '' !== $route->getHost() ? $route->getHost() : 'ANY'), array('Host Regex', '' !== $route->getHost() ? $route->compile()->getHostRegex() : ''), array('Scheme', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'), array('Method', $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'), array('Requirements', $route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'), array('Class', get_class($route)), array('Defaults', $this->formatRouterConfig($route->getDefaults())), array('Options', $this->formatRouterConfig($route->getOptions())));
$table = new Table($this->getOutput());
$table->setHeaders($tableHeaders)->setRows($tableRows);
$table->render();
}
示例7: describeRoute
/**
* {@inheritdoc}
*/
protected function describeRoute(Route $route, array $options = array())
{
$requirements = $route->getRequirements();
unset($requirements['_scheme'], $requirements['_method']);
$output = '- Path: ' . $route->getPath() . "\n" . '- Host: ' . ('' !== $route->getHost() ? $route->getHost() : 'ANY') . "\n" . '- Scheme: ' . ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY') . "\n" . '- Method: ' . ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY') . "\n" . '- Class: ' . get_class($route) . "\n" . '- Defaults: ' . $this->formatRouterConfig($route->getDefaults()) . "\n" . '- Requirements: ' . $this->formatRouterConfig($requirements) ?: 'NONE' . "\n" . '- Options: ' . $this->formatRouterConfig($route->getOptions()) . "\n" . '- Path-Regex: ' . $route->compile()->getRegex();
$this->write(isset($options['name']) ? $options['name'] . "\n" . str_repeat('-', strlen($options['name'])) . "\n\n" . $output : $output);
$this->write("\n");
}
示例8: getPath
public function getPath()
{
if ($path = parent::getPath()) {
return $path;
}
$defaults = $this->getDefaults();
return $defaults['path'];
}
示例9: getActionForRoute
/**
* @param Route $route
* @return Action
*/
public function getActionForRoute(Route $route)
{
foreach ($this->actions as $action) {
// TODO this should be improved to be more precise (route prefix)
$sameSchema = strpos($route->getPath(), $action->getUrlSchema()) >= 0;
$sameMethods = $action->getMethods() == $route->getMethods();
if ($sameMethods && $sameSchema) {
return $action;
}
}
}
示例10: matchParams
/**
* @param Route $route
* @param array $params
* @return array
*/
public function matchParams(Route $route, $params)
{
$ret = [];
preg_match_all('/{(.*?)}/', $route->getPath(), $routeParams);
foreach ($routeParams[1] as $param) {
if (isset($params[$param])) {
$ret[$param] = $this->entityAccessor->fetchIdentifier($params[$param]);
}
}
return $ret;
}
示例11: getEntryPath
/**
* @param Route $route
*
* @return string
*/
protected function getEntryPath(Route $route)
{
$result = $route->getPath();
if (false !== ($pos = strpos($result, '{version}'))) {
$result = substr($result, $pos + 10);
}
if (false !== ($pos = strpos($result, '.{'))) {
$result = substr($result, 0, $pos);
}
return $result;
}
示例12: generateI18nPatterns
public function generateI18nPatterns($routeName, Route $route)
{
$patterns = array();
$config = $route->getOption('i18n');
foreach ($this->locales as $locale) {
// if no translation exists, we use the current pattern
$i18nPattern = array_key_exists($locale, $config) ? $config[$locale] : $route->getPath();
$i18nPattern = '/' . $locale . $i18nPattern;
$patterns[$i18nPattern][] = $locale;
}
return $patterns;
}
示例13: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound(Route $route, array &$parameters)
{
if ($route->hasRequirement('_csrf_token')) {
$path = ltrim($route->getPath(), '/');
// Replace the path parameters with values from the parameters array.
foreach ($parameters as $param => $value) {
$path = str_replace("{{$param}}", $value, $path);
}
// Adding this to the parameters means it will get merged into the query
// string when the route is compiled.
$parameters['token'] = $this->csrfToken->get($path);
}
}
示例14: generateI18nPatterns
public function generateI18nPatterns($routeName, Route $route)
{
$patterns = array();
foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) {
// if no translation exists, we use the current pattern
if ($routeName === ($i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale))) {
$i18nPattern = $route->getPath();
}
$i18nPattern = '/' . $locale . $i18nPattern;
$patterns[$i18nPattern][] = $locale;
}
return $patterns;
}
示例15: access
/**
* Checks access based on a CSRF token for the request.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, Request $request, RouteMatchInterface $route_match)
{
$parameters = $route_match->getRawParameters();
$path = ltrim($route->getPath(), '/');
// Replace the path parameters with values from the parameters array.
foreach ($parameters as $param => $value) {
$path = str_replace("{{$param}}", $value, $path);
}
if ($this->csrfToken->validate($request->query->get('token'), $path)) {
$result = AccessResult::allowed();
} else {
$result = AccessResult::forbidden();
}
// Not cacheable because the CSRF token is highly dynamic.
return $result->setCacheable(FALSE);
}