Refactired Modules classes and interface architecture

This commit is contained in:
Franck Allimant
2013-11-07 15:08:01 +01:00
parent d2a9de682d
commit 528372855f
4 changed files with 62 additions and 22 deletions

View File

@@ -32,4 +32,4 @@ class Module extends BaseModule {
public function getI18nPath() {
return $this->getBaseDir() . DS . "I18n";
}
}
}

View File

@@ -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.
}
}
}

View File

@@ -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);
}

View File

@@ -21,9 +21,9 @@
<div class="row">
<div class="col-md-12">
<div class="general-block-decorator">
<form action="" method="">
<table class="table table-striped table-condensed table-left-aligned">
<caption>
{intl l="Languages management"}
@@ -98,13 +98,13 @@
<div class="form-group {if $error}has-error{/if}" >
<label for="{$label_attr.for}" class="label-control">{intl l="If a translation is missing or incomplete :"}</label>
<div class="input-group">
<select name="{$name}" id="{$label_attr.for}" data-toggle="selectpicker">
<select name="{$name}" id="{$label_attr.for}" data-toggle="selectpicker" class="form-control">
{foreach $choices as $choice}
<option value="{$choice->value}" {if $lang_without_translation == $choice->value}selected="selected"{/if}>{$choice->label}</option>
{/foreach}
</select>
<div class="input-group-btn">
<button type="submit" class="btn btn-default btn-primary"><span class="glyphicon glyphicon-check"></span></button>
<button type="submit" class="btn btn-default btn-primary"><span class="glyphicon glyphicon-check"></span> {intl l='Save'}</button>
</div>
</div>
</div>
@@ -115,7 +115,7 @@
</div>
<div class="col-md-6">
<div class="general-block-decorator clearfix">
<div class="title title-without-tabs">{intl l="Using a domain or subdomain for each language"}</div>
{form name="thelia.lang.url"}
<form action="{url path="/admin/configuration/languages/updateUrl"}" method="post">