public function setUp() { // Store original autoloaders $this->loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } // Store original include_path $this->includePath = get_include_path(); $autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset')); $autoloader->register(); $this->sharedEvents = new SharedEventManager(); $this->moduleManager = new ModuleManager(array('ListenerTestModule')); $this->moduleManager->getEventManager()->setSharedManager($this->sharedEvents); $this->moduleManager->getEventManager()->attach('loadModule.resolve', new ModuleResolverListener(), 1000); $this->application = new MockApplication(); $events = new EventManager(array('Zend\\Mvc\\Application', 'ZendTest\\Module\\TestAsset\\MockApplication', 'application')); $events->setSharedManager($this->sharedEvents); $this->application->setEventManager($events); $this->serviceManager = new ServiceManager(); $this->serviceManager->setService('ModuleManager', $this->moduleManager); $this->application->setServiceManager($this->serviceManager); }
public function setUp() { $this->loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } // Store original include_path $this->includePath = get_include_path(); $autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset')); $autoloader->register(); }
public function setUp() { $this->loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } // Store original include_path $this->includePath = get_include_path(); $autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset')); $autoloader->register(); $this->moduleManager = new ModuleManager(array()); $this->moduleManager->getEventManager()->attach('loadModule.resolve', new ModuleResolverListener(), 1000); $this->moduleManager->getEventManager()->attach('loadModule', new InitTrigger(), 2000); }
public function setUp() { $this->tmpdir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'zend_module_cache_dir'; @mkdir($this->tmpdir); $this->configCache = $this->tmpdir . DIRECTORY_SEPARATOR . 'config.cache.php'; // Store original autoloaders $this->loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } // Store original include_path $this->includePath = get_include_path(); $autoloader = new ModuleAutoloader(array(__DIR__ . '/TestAsset')); $autoloader->register(); }
public function setUp() { $this->tmpdir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'zend_module_cache_dir'; @mkdir($this->tmpdir); $this->configCache = $this->tmpdir . DIRECTORY_SEPARATOR . 'config.cache.php'; // Store original autoloaders $this->loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } // Store original include_path $this->includePath = get_include_path(); $autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset')); $autoloader->register(); $this->moduleManager = new ModuleManager(array()); $this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener(), 1000); }
public function setUp() { $this->loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } // Store original include_path $this->includePath = get_include_path(); $autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset')); $autoloader->register(); $sharedEvents = new SharedEventManager(); $this->bootstrap = new Bootstrap(new Config(array('di' => array()))); $this->bootstrap->events()->setSharedManager($sharedEvents); $this->moduleManager = new Manager(array()); $this->moduleManager->events()->setSharedManager($sharedEvents); $this->moduleManager->events()->attach('loadModule.resolve', new ModuleResolverListener(), 1000); $this->moduleManager->events()->attach('loadModule', new OnBootstrapListener(), 1000); }
public function setUp() { $this->loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } // Store original include_path $this->includePath = get_include_path(); $autoloader = new ModuleAutoloader(array(dirname(__DIR__) . '/TestAsset')); $autoloader->register(); $sharedEvents = new SharedEventManager(); $this->moduleManager = new ModuleManager(array()); $this->moduleManager->getEventManager()->setSharedManager($sharedEvents); $this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener(), 1000); $this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE, new OnBootstrapListener(), 1000); $this->application = new MockApplication(); $events = new EventManager(array('Zend\\Mvc\\Application', 'ZendTest\\Module\\TestAsset\\MockApplication', 'application')); $events->setSharedManager($sharedEvents); $this->application->setEventManager($events); }
/** * Autoload a module class * * @param $class * @return mixed * False [if unable to load $class] * get_class($class) [if $class is successfully loaded] */ public function autoload($class) { if (false !== ($classLoaded = parent::autoload($class))) { return $classLoaded; } // Limit scope of this autoloader if (substr($class, -7) !== '\\Module') { return false; } $moduleName = substr($class, 0, -7); // transform CamelCase namespace to spinal-case, and try to load it // PHP does not execute autoloading for invalid namespaces $namespace = substr($moduleName, 0, $pos = strpos($moduleName, '\\')); $namespace = strtolower(preg_replace('/([^A-Z])([A-Z])/', '$1-$2', $namespace)); $class = $namespace . substr($moduleName, $pos) . '\\Module'; return parent::autoload($class); }
public function testCanLoadModulesFromExplicitLocation() { $loader = new ModuleAutoloader(array('My\\NonmatchingModule' => __DIR__ . '/_files/NonmatchingModule', 'PharModuleExplicit' => __DIR__ . '/_files/PharModuleExplicit.phar')); $loader->register(); $this->assertTrue(class_exists('My\\NonmatchingModule\\Module')); $this->assertTrue(class_exists('PharModuleExplicit\\Module')); }
public function testCanLoadModulesFromNamespace() { $loader = new ModuleAutoloader(array('FooModule\\*' => __DIR__ . '/_files/FooModule', 'FooModule' => __DIR__ . '/_files/FooModule')); $loader->register(); $this->assertTrue(class_exists('FooModule\\BarModule\\Module')); $this->assertTrue(class_exists('FooModule\\SubModule\\Module')); $this->assertTrue(class_exists('FooModule\\Module')); }
public function testInvalidPathsThrowsException() { $loader = new ModuleAutoloader; $this->setExpectedException('InvalidArgumentException'); $loader->registerPaths(123); }
<?php use Zend\Loader\AutoloaderFactory, Zend\Config\Config, Zend\Loader\ModuleAutoloader, Zend\Module\Manager as ModuleManager, Zend\Module\ManagerOptions, Zend\Mvc\Bootstrap, Zend\Mvc\Application, Doctrine\ORM\Tools\Console\ConsoleRunner, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; ini_set('display_errors', true); error_reporting(-1); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array(realpath(__DIR__ . '/../library'), realpath(__DIR__ . '/../library/ZendFramework/library'), get_include_path()))); require_once 'Zend/Loader/AutoloaderFactory.php'; AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array())); $appConfig = new Config(include __DIR__ . '/../configs/application.config.php'); $moduleLoader = new ModuleAutoloader($appConfig['module_paths']); $moduleLoader->register(); $moduleManager = new ModuleManager($appConfig['modules'], new ManagerOptions($appConfig['module_manager_options'])); $bootstrap = new Bootstrap($moduleManager); $application = new Application(); $bootstrap->bootstrap($application); $locator = $application->getLocator(); ConsoleRunner::run(new HelperSet(array('em' => new EntityManagerHelper($locator->get('doctrine')->getEntityManager()))));