public
Last active

Prototype of module initialization listener system

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<?php
interface Installable
{
public function install();
}
interface Upgradable
{
public function upgrade();
}
interface ConfigProvider
{
public function getConfig();
}
interface AutoloaderProvider
{
public function initAutoloader();
}
 
namespace FooBlog
{
class Module implements \Installable, \Upgradable, \ConfigProvider, \AutoloaderProvider
{
public function install()
{
}
 
public function upgrade()
{
}
 
public function getConfig()
{
}
 
public function initAutoloader()
{
}
}
}
 
namespace Zend\Module\Listener
{
class AutoloadTrigger
{
public function __invoke($e)
{
$module = $e->getModule();
if (!$module instanceof \AutoloaderProvider) {
return;
}
$module->initAutoloader();
}
}
}
 
$manager = new Zend\Module\Manager($modules);
$autoloader = new Zend\Module\Listener\AutoloadTrigger();
$config = new Zend\Module\Listener\ConfigListener();
$installer = new Zend\Module\Listener\InstallerListener();
$upgrader = new Zend\Module\Listener\UpgraderListener();
$manager->events()->attach('loadModule', $autoloader);
$manager->events()->attach('loadModule', $config);
$manager->events()->attach('loadModule', $installer);
$manager->events()->attach('loadModule', $upgrader);
 
$bootstrap = new Bootstrap($config->getMergedConfig());
$app = new Application();
$bootstrap->bootstrap($app);
$app->run()->send();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.