Created
November 8, 2011 18:13
-
-
Save weierophinney/1348598 to your computer and use it in GitHub Desktop.
Prototype of module initialization listener system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment