allow using compiler in Thelia modules

This commit is contained in:
Manuel Raynaud
2014-03-05 11:56:48 +01:00
parent 8ecebfdca8
commit 5b341c3009
3 changed files with 53 additions and 2 deletions

View File

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

View File

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

View File

@@ -311,8 +311,8 @@
}
});
},
error: function () {
console.log('Error.');
error: function (e) {
console.log('Error.', e);
}
});