Skip to content

Commit

Permalink
Merge branch 'master' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaxs committed Aug 29, 2016
2 parents 0ece399 + 91f988a commit 0e371ca
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/EventListener/LocaleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ protected function getExcludeRoutesReg()

if (isset($exclude_routes_reg)) return $exclude_routes_reg;

$exclude_routes_reg = implode('|', $this->exclude_routes);
$exclude_routes_reg = str_replace('~', '\\~', $exclude_routes_reg);
$exclude_routes_reg = '~' . $exclude_routes_reg . '~';
if (!empty($this->exclude_routes)) {
$exclude_routes_reg = implode('|', $this->exclude_routes);
$exclude_routes_reg = str_replace('~', '\\~', $exclude_routes_reg);
$exclude_routes_reg = '~' . $exclude_routes_reg . '~';
} else {
$exclude_routes_reg = false;
}


return $exclude_routes_reg;
}
Expand Down
13 changes: 12 additions & 1 deletion src/Twig/LocaleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public function __construct(UrlGenerator $generator, $locales)
public function getFunctions()
{
return [
new \Twig_SimpleFunction('generate', [$this, 'generate']),
new \Twig_SimpleFunction('locale_generate', [$this, 'generate']),
new \Twig_SimpleFunction('locale_get_url', [$this, 'getUrl']),
new \Twig_SimpleFunction('locale_get_url_for_locale', [$this, 'getUrlForLocale']),
new \Twig_SimpleFunction('locale_get_index_url', [$this, 'getIndexUrl']),
new \Twig_SimpleFunction('locale_get_index_url_for_locale', [$this, 'getIndexUrlForLocale']),
new \Twig_SimpleFunction('locale_clear_path_from_locale', [$this, 'clearPathFromLocale']),
];
}

Expand Down Expand Up @@ -102,6 +103,16 @@ public function getIndexUrlForLocale($locale, $absolute = false)
return $this->generator->getIndexUrlForLocale($locale, $absolute);
}

/**
* Clear path from locale
* @param $path
* @return string
*/
public function clearPathFromLocale($path)
{
return $this->generator->clearPathFromLocale($path);
}

/**
* @inheritdoc
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Utils/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ public function getIndexUrlForLocale($locale, $absolute = false)
}
}

/**
* Clear path from locale
* @param $path
* @return string
*/
public function clearPathFromLocale($path)
{
if ($this->resolve_by_host) {
return $path;
}

$path = preg_replace('~^/?(' . $this->getLocalesReg() . ')(/|$)~', '', $path);

return $path;
}

/**
* Return scheme
* @return string
Expand Down

0 comments on commit 0e371ca

Please sign in to comment.