/** * Build and cache url by requested path and parameters * * @param string|null $routePath * @param array|null $routeParams * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getUrl($routePath = null, $routeParams = null) { if (filter_var($routePath, FILTER_VALIDATE_URL)) { return $routePath; } $routeParams = $this->routeParamsPreprocessor ->execute($this->_scopeResolver->getAreaCode(), $routePath, $routeParams); $isCached = true; $isArray = is_array($routeParams); if ($isArray) { array_walk_recursive( $routeParams, function ($item) use (&$isCached) { if (is_object($item)) { $isCached = false; } } ); } if(!$isCached) { return $this->getUrlModifier()->execute( $this->createUrl($routePath, $routeParams), $routeParams ); } $cashedParams = $routeParams; if ($isArray) { ksort($cashedParams); } $cacheKey = md5($routePath . serialize($cashedParams)); if (!isset($this->cacheUrl[$cacheKey])) { $this->cacheUrl[$cacheKey] = $this->getUrlModifier()->execute( $this->createUrl($routePath, $routeParams), $routeParams ); } return $this->cacheUrl[$cacheKey]; }
/** * Retrieve route front name * * @return string */ protected function _getRouteFrontName() { if (!$this->hasData('route_front_name')) { $frontName = $this->_routeConfig->getRouteFrontName($this->_getRouteName(), $this->_scopeResolver->getAreaCode()); $this->setData('route_front_name', $frontName); } return $this->_getData('route_front_name'); }