本文整理汇总了PHP中Symfony\Component\Routing\Route::setPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::setPath方法的具体用法?PHP Route::setPath怎么用?PHP Route::setPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::setPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$requirements = $current_route->getRequirements();
// Setting _method and _schema is deprecated since 2.7. Using
// setMethods() and setSchemes() are now the recommended ways.
unset($requirements['_method']);
unset($requirements['_schema']);
$route->setRequirements($requirements);
$route->setPath($current_route->getPath());
$route->setSchemes($current_route->getSchemes());
$route->setMethods($current_route->getMethods());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheContexts(['route']);
}
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例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: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例4: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>' && ($current_route = $this->routeMatch->getRouteObject())) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
}
}
示例5: testGenerateByRoute
/**
* Tests the generate method with passing in a route object into generate().
*
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
*/
public function testGenerateByRoute()
{
$this->generator = new ProviderBasedGenerator($this->provider);
// Setup a route with a numeric parameter, but pass in a string, so it
// fails and getRouteDebugMessage should be triggered.
$route = new Route('/test');
$route->setPath('/test/{number}');
$route->setRequirement('number', '\\+d');
$this->generator->setStrictRequirements(true);
$context = new RequestContext();
$this->generator->setContext($context);
$this->assertSame(null, $this->generator->generate($route, array('number' => 'string')));
}
示例6: parseRoute
/**
* @param RouteCollection $collection
* @param string $name
* @param array $config
* @param string $path
*/
protected function parseRoute(RouteCollection $collection, $name, array $config, $path)
{
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
$options = isset($config['options']) ? $config['options'] : array();
$host = isset($config['host']) ? $config['host'] : '';
$schemes = isset($config['schemes']) ? $config['schemes'] : array();
$methods = isset($config['methods']) ? $config['methods'] : array();
$i18n = isset($config['i18n']) ? $config['i18n'] : true;
foreach ($this->registry->getRegisteredLocales() as $locale) {
$route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods);
if ($i18n) {
$route->setPath('/' . $locale . '/' . ltrim($this->helper->alterPath($config['path'], $locale), '/'));
$route->setDefaults($this->helper->alterDefaults($defaults, $locale));
}
$i18nName = $i18n ? $this->helper->alterName($name, $locale) : $name;
$collection->add($i18nName, $route);
}
}
示例7: compile
/**
* {@inheritDoc}
*
* Overwritten to make sure the route is recompiled if the pattern was changed
*/
public function compile()
{
if ($this->needRecompile) {
// calling parent::setPath just to let it set compiled=null. the parent $path field is never used
parent::setPath($this->getPath());
}
return parent::compile();
}
示例8: compile
/**
* {@inheritDoc}
*
* Overwritten to make sure the route is recompiled if the pattern was changed
*/
public function compile()
{
if ($this->needRecompile) {
// calling parent::setPath just to let it set compiled=null. the parent $path field is never used
// TODO: drop setPattern when we drop symfony 2.1 support
// TODO: for now we need to check the method as setPattern on 2.2. triggers our setPath instead of parent setPath
if (method_exists('Symfony\\Component\\Routing\\Route', 'setPath')) {
parent::setPath($this->getPath());
} else {
parent::setPattern($this->getPath());
}
}
return parent::compile();
}
示例9: refreshEntity
/**
* Refresh the entity
*
* @ORM\PostLoad
*/
public function refreshEntity()
{
parent::setPath($this->path);
parent::setDefaults($this->defaults);
parent::setRequirements($this->requirements);
parent::setOptions($this->options);
parent::setHost($this->host);
parent::setMethods($this->methods);
parent::setSchemes($this->schemes);
}
示例10: compile
/**
* {@inheritDoc}
*/
public function compile()
{
if ($this->recompile) {
parent::setPath($this->getPath());
}
return parent::compile();
}
示例11: prependBundlePrefix
/**
* Prepends the bundle prefix to the route.
*
* @param Route $route
* @param AbstractBundle $bundle
*
* We have to prepend the bundle prefix if
* - routes are _not_ currently extracted via the command line and
* - the route has i18n set to false.
* This is because when extracting the routes, a bundle author only wants to translate the bare route
* patterns, without a redundant and potentially customized bundle prefix in front of them.
* If i18n is set to true, Zikula's customized pattern generation strategy will take care of it.
* See Zikula\RoutesModule\Translation\ZikulaPatternGenerationStrategy
*/
private function prependBundlePrefix(Route $route, AbstractBundle $bundle)
{
$prefix = '';
$options = $route->getOptions();
$prependBundle = !isset($GLOBALS['translation_extract_routes']) && isset($options['i18n']) && !$options['i18n'];
if ($prependBundle && (!isset($options['zkNoBundlePrefix']) || !$options['zkNoBundlePrefix'])) {
// get url from MetaData first. May be empty.
$untranslatedPrefix = $bundle->getMetaData()->getUrl(false);
if (empty($untranslatedPrefix)) {
try {
// MetaData will be empty for extensions not Spec-2.0. Try to get from modinfo.
// this calls the DB which is not available during install.
$modinfo = \ModUtil::getInfoFromName($bundle->getName());
$prefix = $modinfo['url'];
} catch (\Exception $e) {
}
} else {
$locale = $this->container->getParameter('locale');
if ($this->translator->getCatalogue($locale)->has($untranslatedPrefix, strtolower($bundle->getName()))) {
$prefix = $this->translator->trans($untranslatedPrefix, [], strtolower($bundle->getName()), $locale);
} else {
$prefix = $untranslatedPrefix;
}
}
$path = "/" . $prefix . $route->getPath();
$route->setPath($path);
}
}
示例12: applyRoute
/**
* Apply the parameter map to a Drupal 8 route, modifying it as needed.
*
* @param \Symfony\Component\Routing\Route $route
* The route to process.
*/
public function applyRoute(Drupal8Route $route)
{
$this->applyPath($this->path);
foreach ($this as $key => $binding) {
$parameter = $binding->getParameter();
/** @var ParameterBinding $binding */
if (is_integer($key)) {
if ($parameter->isOptional()) {
// @todo Don't use eval().
$value = eval('return ' . $parameter->getValue() . ';');
$route->setDefault($parameter->getName(), $value);
}
} elseif ($binding->hasArgument()) {
$route->setDefault($parameter->getName(), $binding->getValue());
}
}
$route->setPath($this->path->__toString());
}
示例13: addLocaleToRoute
/**
* Adds the locale to the route if prepend_locale is enabled.
*
* @param Route $route The route
*/
private function addLocaleToRoute(Route $route)
{
if ($this->prependLocale) {
$route->setPath('/{_locale}' . $route->getPath());
$route->addRequirements(['_locale' => '[a-z]{2}(\\-[A-Z]{2})?']);
} else {
$route->addDefaults(['_locale' => null]);
}
}
示例14: setPath
public function setPath($pattern)
{
// Remove trailing slash from route
return parent::setPath(rtrim($pattern, '/'));
}
示例15: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<none>') {
$route->setPath('');
}
}