From 5b341c3009a1f1a75a2005c39fe794388143ae14 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 5 Mar 2014 11:56:48 +0100 Subject: [PATCH] allow using compiler in Thelia modules --- core/lib/Thelia/Core/Thelia.php | 11 +++++ core/lib/Thelia/Module/BaseModule.php | 40 +++++++++++++++++++ .../frontOffice/default/assets/js/script.js | 4 +- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 2513541f0..a6f4102ac 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -196,6 +196,17 @@ class Thelia extends Kernel $definition ); + $compilers = call_user_func(array($module->getFullNamespace(), 'getCompilers')); + + foreach ($compilers as $compiler) { + if (is_array($compiler)) { + $container->addCompilerPass($compiler[0], $compiler[1]); + } else { + $container->addCompilerPass($compiler); + } + + } + $loader = new XmlFileLoader($container, new FileLocator($module->getAbsoluteConfigPath())); $loader->load("config.xml"); diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 7a29c7e6a..6dcf3ff06 100644 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -262,6 +262,46 @@ class BaseModule extends ContainerAware implements BaseModuleInterface return basename(dirname($this->reflected->getFileName())); } + /** + * + * This method allow adding new compilers to Thelia container + * + * You must return an array. This array can contain : + * - arrays + * - one or many instance(s) of \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface + * + * in the first case, your array must contains 2 indexes. The first is the compiler instance and the second the compilerPass type. + * Example : + * return array( + * array( + * new \MyModule\DependencyInjection\Compiler\MySuperCompilerPass(), + * \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION + * ) + * ); + * + * In the seconde case, just an instance of CompilerPassInterface. + * Example : + * return array ( + * new \MyModule\DependencyInjection\Compiler\MySuperCompilerPass() + * ); + * + * But you can combine both behaviors + * Example : + * + * return array( + * new \MyModule\DependencyInjection\Compiler\MySuperCompilerPass(), + * array( + * new \MyModule\DependencyInjection\Compiler\MyOtherSuperCompilerPass(), + * Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION + * ) + * ); + * + */ + public static function getCompilers() + { + return array(); + } + public function install(ConnectionInterface $con = null) { // Implement this method to do something useful. diff --git a/templates/frontOffice/default/assets/js/script.js b/templates/frontOffice/default/assets/js/script.js index ff2ddc2fb..ac94ff14c 100644 --- a/templates/frontOffice/default/assets/js/script.js +++ b/templates/frontOffice/default/assets/js/script.js @@ -311,8 +311,8 @@ } }); }, - error: function () { - console.log('Error.'); + error: function (e) { + console.log('Error.', e); } });