diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index e380457ca..ced10c94b 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -25,7 +25,7 @@ class Category extends BaseCategory public function getUrl($locale) { - return URL::getInstance()->retrieve('category', $this->getId(), $locale); + return URL::getInstance()->retrieve('category', $this->getId(), $locale)->toString(); } /** diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 430408521..5bc0ba6b2 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -9,6 +9,6 @@ class Content extends BaseContent { public function getUrl($locale) { - return URL::getInstance()->retrieve('content', $this->getId(), $locale); + return URL::getInstance()->retrieve('content', $this->getId(), $locale)->toString(); } } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index 5aab7c5bf..8151dae0e 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -17,7 +17,7 @@ class Folder extends BaseFolder public function getUrl($locale) { - return URL::getInstance()->retrieve('folder', $this->getId(), $locale); + return URL::getInstance()->retrieve('folder', $this->getId(), $locale)->toString(); } /** diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index f02792285..6c7ffbe44 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -9,6 +9,6 @@ class Product extends BaseProduct { public function getUrl($locale) { - return URL::getInstance()->retrieve('product', $this->getId(), $locale); + return URL::getInstance()->retrieve('product', $this->getId(), $locale)->toString(); } } diff --git a/core/lib/Thelia/Tests/Action/ImageTest.php b/core/lib/Thelia/Tests/Action/ImageTest.php index bde077481..526f7cb86 100755 --- a/core/lib/Thelia/Tests/Action/ImageTest.php +++ b/core/lib/Thelia/Tests/Action/ImageTest.php @@ -30,6 +30,7 @@ use Thelia\Core\HttpFoundation\Session\Session; use Thelia\Action\Image; use Thelia\Core\Event\ImageEvent; use Thelia\Model\ConfigQuery; +use Thelia\Tools\URL; /** * Class ImageTest @@ -48,7 +49,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + $url = new URL($container, 'dev'); + $container->set("event_dispatcher", $dispatcher); + $container->set("thelia.url.manager", $dispatcher); + + $request = new Request(); + $request->setSession($this->session); + + $container->set("request", $request); return $container; } diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 1816f76ec..b1fa6cd03 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -55,8 +55,6 @@ class URL $this->retriever = new RewritingRetriever(); $this->resolver = new RewritingResolver(); - - echo "instanciation ok !"; } /** @@ -79,10 +77,7 @@ class URL */ public function getBaseUrl() { - $lang = $this->container - ->get('request') - ->getSession() - ->getLang(); + $lang = $this->container->get('request')->getSession()->getLang(); // Check if we have a specific URL for each lang. $one_domain_foreach_lang = ConfigQuery::read("one_domain_foreach_lang", false); @@ -197,70 +192,65 @@ class URL return $this->absoluteUrl($path, $parameters); } + /** + * Retrieve a rewritten URL from a view, a view id and a locale + * + * @param $view + * @param $viewId + * @param $viewLocale + * + * @return RewritingRetriever You can access $url and $rewrittenUrl properties + */ + public function retrieve($view, $viewId, $viewLocale) + { + if(ConfigQuery::isRewritingEnable()) { + $this->retriever->loadViewUrl($view, $viewLocale, $viewId); + } - /** - * Retrieve a rewritten URL from a view, a view id and a locale - * - * @param $view - * @param $viewId - * @param $viewLocale - * - * @return RewritingRetriever You can access $url and $rewrittenUrl properties - */ - public function retrieve($view, $viewId, $viewLocale) - { - if(ConfigQuery::isRewritingEnable()) { - $this->retriever->loadViewUrl($view, $viewLocale, $viewId); - } + return $this->retriever; + } - // Bug: $rewrittenUrl n'est pas initialisé - //return $rewrittenUrl === null ? $this->viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; - return $this->viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)); - } + /** + * Retrieve a rewritten URL from the current GET parameters + * + * @param Request $request + * + * @return RewritingRetriever You can access $url and $rewrittenUrl properties or use toString method + */ + public function retrieveCurrent(Request $request) + { + if(ConfigQuery::isRewritingEnable()) { + $view = $request->query->get('view', null); + $viewLocale = $request->query->get('locale', null); + $viewId = $view === null ? null : $request->query->get($view . '_id', null); - /** - * Retrieve a rewritten URL from the current request GET parameters - * - * @return RewritingRetriever You can access $url and $rewrittenUrl properties or use toString method - */ - public function retrieveCurrent() - { - if (ConfigQuery::isRewritingEnable()) { + $allOtherParameters = $request->query->all(); + if($view !== null) { + unset($allOtherParameters['view']); + } + if($viewLocale !== null) { + unset($allOtherParameters['locale']); + } + if($viewId !== null) { + unset($allOtherParameters[$view . '_id']); + } - $query = $this->container->get('request')->query; + $this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters); + } - $view = $query->get('view', null); - $viewLocale = $query->get('locale', null); - $viewId = $view === null ? null : $query->get($view . '_id', null); + return $this->retriever; + } - $allOtherParameters = $query->all(); - if($view !== null) { - unset($allOtherParameters['view']); - } - if($viewLocale !== null) { - unset($allOtherParameters['locale']); - } - if($viewId !== null) { - unset($allOtherParameters[$view . '_id']); - } - - $this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters); - } - - return $this->retriever; - } - - /** - * Retrieve a rewritten URL from the current GET parameters or use toString method - * - * @param $url - * - * @return RewritingResolver - */ - public function resolve($url) - { - $this->resolver->load($url); - - return $this->resolver; - } + /** + * Retrieve a rewritten URL from the current GET parameters or use toString method + * + * @param $url + * + * @return RewritingResolver + */ + public function resolve($url) + { + $this->resolver->load($url); + return $this->resolver; + } } \ No newline at end of file