public function testShortParamsGettingReplaced() { $mapping = ['longParam0' => 'shortParam0', 'longParam1' => 'shortParam1']; $mapper = new QueryAliasMapper($mapping); $params = ['shortParam0' => 'someValue', 'shortParam1' => 'someOtherValue', 'someParam' => 'someValue']; $result = $mapper->replaceShortParams($params); $expected = ['longParam0' => 'someValue', 'longParam1' => 'someOtherValue', 'someParam' => 'someValue']; $this->assertEquals($expected, $result); }
/** * {@inheritdoc} */ public function match($pathInfo, Context $context) { if (strpos($pathInfo, '/backend/') === 0 || strpos($pathInfo, '/api/') === 0) { return $pathInfo; } if ($context->getShopId() === null) { // only frontend return $pathInfo; } // Rewrites queries $params = $context->getParams(); $params = $this->queryAliasMapper->replaceShortParams($params); /* templates/_emotion/frontend/_resources/javascript/jquery.shopware.js */ if (isset($params['sAction'])) { $params['action'] = $params['sAction']; } if (isset($params['sViewport'])) { $params['controller'] = $params['sViewport']; } $context->setParams($params); // /widgets and /index supports short request queries if ($pathInfo === '/' || strpos($pathInfo, '/widgets/') === 0) { return $pathInfo; } $pathInfo = ltrim($pathInfo, '/'); $statement = $this->getRouteStatement(); $statement->bindValue(':shopId', $context->getShopId(), \PDO::PARAM_INT); $statement->bindValue(':pathInfo', $pathInfo, \PDO::PARAM_STR); if ($statement->execute() && $statement->rowCount() > 0) { $route = $statement->fetch(\PDO::FETCH_ASSOC); $query = $this->getQueryFormOrgPath($route['orgPath']); if (empty($route['main']) || $route['shopId'] != $context->getShopId()) { $query['rewriteAlias'] = true; } else { $query['rewriteUrl'] = true; } return $query; } return $pathInfo; }