From 6263aeeee16ff70550d571af48a6953dcf399cd3 Mon Sep 17 00:00:00 2001 From: eborges78 Date: Sun, 13 May 2018 22:59:56 +0200 Subject: [PATCH 1/2] add optimisation --- Services/CustomRouter.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Services/CustomRouter.php b/Services/CustomRouter.php index bc7d995..bee2a71 100644 --- a/Services/CustomRouter.php +++ b/Services/CustomRouter.php @@ -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(); @@ -255,9 +259,17 @@ private function resolveParameters(RouteCollection $collection) */ private function resolve($value) { + if (\is_string($value) && (empty($value) || \strpos($value, '%') === false)) { + return $value; + } + if (\is_array($value)) { foreach ($value as $key => $val) { - $value[$key] = $this->resolve($val); + if (empty($val) || !\is_string($value) || \strpos($val, '%') === false) { + $value[$key] = $val; + } else { + $value[$key] = $this->resolve($val); + } } return $value; From 3a658b38042e0c1630e38a5b96c7bed83c1ebc24 Mon Sep 17 00:00:00 2001 From: eborges78 Date: Wed, 16 May 2018 12:23:24 +0200 Subject: [PATCH 2/2] refacto --- Services/CustomRouter.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Services/CustomRouter.php b/Services/CustomRouter.php index bee2a71..ef6807e 100644 --- a/Services/CustomRouter.php +++ b/Services/CustomRouter.php @@ -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); @@ -180,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']; @@ -259,13 +259,13 @@ private function resolveParameters(RouteCollection $collection) */ private function resolve($value) { - if (\is_string($value) && (empty($value) || \strpos($value, '%') === false)) { + if (\is_string($value) && (empty($value) || false === \strpos($value, '%'))) { return $value; } if (\is_array($value)) { foreach ($value as $key => $val) { - if (empty($val) || !\is_string($value) || \strpos($val, '%') === false) { + if (empty($val) || !\is_string($value) || false === \strpos($val, '%')) { $value[$key] = $val; } else { $value[$key] = $this->resolve($val);