Skip to content

Commit

Permalink
Merge pull request #2 from eborges78/optim
Browse files Browse the repository at this point in the history
Optim
  • Loading branch information
eborges1978 committed May 16, 2018
2 parents 0af9fe2 + 3a658b3 commit a88dbbd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Services/CustomRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public function __construct(
*/
public function generate($route, $params = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
if ($this->request === null) {
if (null === $this->request) {
$this->request = $this->container->get('request_stack')->getMasterRequest();
}
if ($this->request !== null) {
if (null !== $this->request) {
$locale = $this->request->attributes->get('market');
if (\in_array($route, $this->routes, true)) {
return parent::generate($route, $params, $referenceType);
Expand All @@ -85,6 +85,10 @@ public function generate($route, $params = array(), $referenceType = UrlGenerato
*/
public function getRouteCollection()
{
if (null !== $this->collection) {
return $this->collection;
}

$this->collection = new RouteCollection();
$defaultLocaleCollection = new RouteCollection();

Expand Down Expand Up @@ -176,7 +180,7 @@ private function filterRoutes(array $availableLocales = []): RouteCollection
{
$tmpCollection = new RouteCollection();
foreach ($this->defaultCollection as $key => $route) {
if ($key[0] === '_' || stripos($key, 'pages_exceptions') === 0) {
if ('_' === $key[0] || false !== stripos($key, 'pages_exceptions')) {
foreach ($availableLocales as $config) {
// find route into config
$configuredLocale = $config['locale'];
Expand Down Expand Up @@ -255,9 +259,17 @@ private function resolveParameters(RouteCollection $collection)
*/
private function resolve($value)
{
if (\is_string($value) && (empty($value) || false === \strpos($value, '%'))) {
return $value;
}

if (\is_array($value)) {
foreach ($value as $key => $val) {
$value[$key] = $this->resolve($val);
if (empty($val) || !\is_string($value) || false === \strpos($val, '%')) {
$value[$key] = $val;
} else {
$value[$key] = $this->resolve($val);
}
}

return $value;
Expand Down

0 comments on commit a88dbbd

Please sign in to comment.