From 528372855f83b543953b46259011c21467a1c511 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 7 Nov 2013 15:08:01 +0100 Subject: [PATCH] Refactired Modules classes and interface architecture --- core/lib/Thelia/Model/Module.php | 2 +- core/lib/Thelia/Module/BaseModule.php | 58 +++++++++++++++---- .../lib/Thelia/Module/BaseModuleInterface.php | 14 +++-- templates/admin/default/languages.html | 10 ++-- 4 files changed, 62 insertions(+), 22 deletions(-) diff --git a/core/lib/Thelia/Model/Module.php b/core/lib/Thelia/Model/Module.php index d57df77fa..36ed8778e 100755 --- a/core/lib/Thelia/Model/Module.php +++ b/core/lib/Thelia/Model/Module.php @@ -32,4 +32,4 @@ class Module extends BaseModule { public function getI18nPath() { return $this->getBaseDir() . DS . "I18n"; } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 15853a398..5a6aa103f 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -36,8 +36,9 @@ use Thelia\Exception\ModuleException; use Thelia\Model\Module; use Thelia\Model\ModuleImage; use Thelia\Model\ModuleQuery; +use Thelia\Core\HttpFoundation\Request; -abstract class BaseModule extends ContainerAware +class BaseModule extends ContainerAware implements BaseModuleInterface { const CLASSIC_MODULE_TYPE = 1; const DELIVERY_MODULE_TYPE = 2; @@ -48,10 +49,8 @@ abstract class BaseModule extends ContainerAware protected $reflected; - public function __construct() - { - - } + protected $dispatcher = null; + protected $request = null; public function activate($moduleModel = null) { @@ -102,7 +101,7 @@ abstract class BaseModule extends ContainerAware public function hasContainer() { - return null === $this->container; + return null !== $this->container; } public function getContainer() @@ -114,6 +113,41 @@ abstract class BaseModule extends ContainerAware return $this->container; } + + public function hasRequest() { + return null !== $this->request; + } + + public function setRequest(Request $request) { + $this->request = $request; + } + + public function getRequest() { + if ($this->hasRequest() === false) { + throw new \RuntimeException("Sorry, the request is not available in this context"); + } + + return $this->request; + } + + + public function hasDispatcher() { + return null !== $this->dispatcher; + } + + public function setDispatcher(EventDispatcherInterface $dispatcher) { + $this->dispatcher = $dispatcher; + } + + public function getDispatcher() { + if ($this->hasDispatcher() === false) { + throw new \RuntimeException("Sorry, the dispatcher is not available in this context"); + } + + return $this->dispatcher; + } + + public function setTitle(Module $module, $titles) { if (is_array($titles)) { @@ -226,6 +260,7 @@ abstract class BaseModule extends ContainerAware public function install(ConnectionInterface $con = null) { + // Implement this method to do something useful. } public function preActivation(ConnectionInterface $con = null) @@ -235,7 +270,7 @@ abstract class BaseModule extends ContainerAware public function postActivation(ConnectionInterface $con = null) { - + // Implement this method to do something useful. } public function preDeactivation(ConnectionInterface $con = null) @@ -245,12 +280,11 @@ abstract class BaseModule extends ContainerAware public function postDeactivation(ConnectionInterface $con = null) { - + // Implement this method to do something useful. } - public function destroy(ConnectionInterface $con = null) + public function destroy(ConnectionInterface $con = null, $deleteModuleData = false) { - + // Implement this method to do something useful. } - -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Module/BaseModuleInterface.php b/core/lib/Thelia/Module/BaseModuleInterface.php index 5cfd98409..a8e4d27ec 100644 --- a/core/lib/Thelia/Module/BaseModuleInterface.php +++ b/core/lib/Thelia/Module/BaseModuleInterface.php @@ -28,9 +28,15 @@ use Symfony\Component\HttpFoundation\Request; interface BaseModuleInterface { - public function setRequest(Request $request); - public function getRequest(); + public function install(ConnectionInterface $con = null); - public function setDispatcher(EventDispatcherInterface $dispatcher); - public function getDispatcher(); + public function preActivation(ConnectionInterface $con = null); + + public function postActivation(ConnectionInterface $con = null); + + public function preDeactivation(ConnectionInterface $con = null); + + public function postDeactivation(ConnectionInterface $con = null); + + public function destroy(ConnectionInterface $con = null, $deleteModuleData = false); } diff --git a/templates/admin/default/languages.html b/templates/admin/default/languages.html index 73f2a656c..dc337efe2 100644 --- a/templates/admin/default/languages.html +++ b/templates/admin/default/languages.html @@ -21,9 +21,9 @@
- +
- +
{intl l="Languages management"} @@ -98,13 +98,13 @@
- {foreach $choices as $choice} {/foreach}
- +
@@ -115,7 +115,7 @@
- +
{intl l="Using a domain or subdomain for each language"}
{form name="thelia.lang.url"}