If you use this init() method, you cannot specify a service with the
name of 'ApplicationConfig' in your service manager config. This name is
reserved to hold the array from application.config.php.
The following services can only be overridden from application.config.php:
- ModuleManager
- SharedEventManager
- EventManager & Zend\EventManager\EventManagerInterface
All other services are configured after module loading, thus can be
overridden by modules.
/** * Gets application commands * * @return array */ protected function getApplicationCommands() { $setupCommands = []; $toolsCommands = []; $modulesCommands = []; $bootstrapParam = new ComplexParameter(self::INPUT_KEY_BOOTSTRAP); $params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER); $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; $bootstrap = Bootstrap::create(BP, $params); $objectManager = $bootstrap->getObjectManager(); if (class_exists('Magento\\Setup\\Console\\CommandList')) { $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')->getServiceManager(); $setupCommandList = new \Magento\Setup\Console\CommandList($serviceManager); $setupCommands = $setupCommandList->getCommands(); } if (class_exists('Magento\\Tools\\Console\\CommandList')) { $toolsCommandList = new \Magento\Tools\Console\CommandList(); $toolsCommands = $toolsCommandList->getCommands(); } if ($objectManager->get('Magento\\Framework\\App\\DeploymentConfig')->isAvailable()) { $commandList = $objectManager->create('Magento\\Framework\\Console\\CommandList'); $modulesCommands = $commandList->getCommands(); } $commandsList = array_merge($setupCommands, $toolsCommands, $modulesCommands); return $commandsList; }
protected function setUp() { $bootstrap = \Zend\Mvc\Application::init(include 'config/application.config.php'); $categoryData = array('id_category' => 1, 'name' => 'Project Manager'); $category = new Category(); $category->exchangeArray($categoryData); $resultSetCategory = new ResultSet(); $resultSetCategory->setArrayObjectPrototype(new Category()); $resultSetCategory->initialize(array($category)); $mockCategoryTableGateway = $this->getMock('Zend\\Db\\TableGateway\\TableGateway', array('select'), array(), '', false); $mockCategoryTableGateway->expects($this->any())->method('select')->with()->will($this->returnValue($resultSetCategory)); $categoryTable = new CategoryTable($mockCategoryTableGateway); $jobData = array('id_job' => 1, 'id_category' => 1, 'type' => 'typeTest', 'company' => 'companyTest', 'logo' => 'logoTest', 'url' => 'urlTest', 'position' => 'positionTest', 'location' => 'locaitonTest', 'description' => 'descriptionTest', 'how_to_play' => 'hotToPlayTest', 'is_public' => 1, 'is_activated' => 1, 'email' => 'emailTest', 'created_at' => '2012-01-01 00:00:00', 'updated_at' => '2012-01-01 00:00:00'); $job = new Job(); $job->exchangeArray($jobData); $resultSetJob = new ResultSet(); $resultSetJob->setArrayObjectPrototype(new Job()); $resultSetJob->initialize(array($job)); $mockJobTableGateway = $this->getMock('Zend\\Db\\TableGateway\\TableGateway', array('select'), array(), '', false); $mockJobTableGateway->expects($this->any())->method('select')->with(array('id_category' => 1))->will($this->returnValue($resultSetJob)); $jobTable = new JobTable($mockJobTableGateway); $this->controller = new IndexController($categoryTable, $jobTable); $this->request = new Request(); $this->routeMatch = new RouteMatch(array('controller' => 'index')); $this->event = $bootstrap->getMvcEvent(); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); $this->controller->setEventManager($bootstrap->getEventManager()); $this->controller->setServiceLocator($bootstrap->getServiceManager()); }
/** * Set up application environment * * This sets up the PHP environment, loads the provided module and returns * the MVC application. * * @param string $module Module to load * @param bool $addTestConfig Add config for test environment (enable all debug options, no config file) * @param array $applicationConfig Extends default application config * @return \Zend\Mvc\Application * @codeCoverageIgnore */ public static function init($module, $addTestConfig = false, $applicationConfig = array()) { // Set up PHP environment. session_cache_limiter('nocache'); // Default headers to prevent caching return \Zend\Mvc\Application::init(array_replace_recursive(static::getApplicationConfig($module, $addTestConfig), $applicationConfig)); }
public static function init() { /** * Load Test Config to include other modules we require */ if (is_readable(__DIR__ . '/TestConfig.php')) { $testConfig = (include __DIR__ . '/TestConfig.php'); } else { $testConfig = (include __DIR__ . '/TestConfig.php.dist'); } $zf2ModulePaths = array(); if (isset($testConfig['module_listener_options']['module_paths'])) { $modulePaths = $testConfig['module_listener_options']['module_paths']; foreach ($modulePaths as $modulePath) { if ($path = static::findParentPath($modulePath)) { $zf2ModulePaths[] = $path; } } } $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR; $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : ''); static::initAutoloader(); // use ModuleManager to load this module and it's dependencies $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths))); $config = ArrayUtils::merge($baseConfig, $testConfig); \Zend\Mvc\Application::init($config); $serviceManager = new ServiceManager(new ServiceManagerConfig()); $serviceManager->setAllowOverride(true); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); static::$serviceManager = $serviceManager; static::$config = $config; }
/** * @param string $name application name * @param string $version application version * @SuppressWarnings(PHPMD.ExitExpression) */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')->getServiceManager(); $generationDirectoryAccess = new GenerationDirectoryAccess($this->serviceManager); if (!$generationDirectoryAccess->check()) { $output = new ConsoleOutput(); $output->writeln('<error>Command line user does not have read and write permissions on var/generation directory. Please' . ' address this issue before using Magento command line.</error>'); exit(0); } /** * Temporary workaround until the compiler is able to clear the generation directory * @todo remove after MAGETWO-44493 resolved */ if (class_exists(CompilerPreparation::class)) { $compilerPreparation = new CompilerPreparation($this->serviceManager, new ArgvInput(), new File()); $compilerPreparation->handleCompilerEnvironment(); } if ($version == 'UNKNOWN') { $directoryList = new DirectoryList(BP); $composerJsonFinder = new ComposerJsonFinder($directoryList); $productMetadata = new ProductMetadata($composerJsonFinder); $version = $productMetadata->getVersion(); } parent::__construct($name, $version); }
public static function getApplication() { self::assertZf(); self::chdirToAppRoot(); $configPath = self::findAppConfigPath(); return Application::init(require $configPath); }
/** * @see \Zend\Mvc\Application#init() * @param array $configuration * @return RealZendApplication */ public static function init($configuration = array()) { Exception\ErrorException::$oldErrorHandler = set_error_handler("\\Netis\\Exception\\ErrorException::errorHandler"); Environment::setEnv(isset($configuration['env']) ? $configuration['env'] : Environment::ENV_PRODUCTION); self::detectLoader($configuration); return parent::init($configuration); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Start up application with supplied config...'); $config = $input->getArgument('applicationConfig'); $path = stream_resolve_include_path($config); if (!is_readable($path)) { throw new \InvalidArgumentException("Invalid loader path: {$config}"); } // Init the application once using given config // This way the late static binding on the AspectKernel // will be on the goaop-zf2-module kernel \Zend\Mvc\Application::init(include $path); if (!class_exists(AspectKernel::class, false)) { $message = "Kernel was not initialized yet. Maybe missing module Go\\ZF2\\GoAopModule in config {$path}"; throw new \InvalidArgumentException($message); } $kernel = AspectKernel::getInstance(); $options = $kernel->getOptions(); if (empty($options['cacheDir'])) { throw new \InvalidArgumentException('Cache warmer require the `cacheDir` options to be configured'); } $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $iterator = $enumerator->enumerate(); $totalFiles = iterator_count($iterator); $output->writeln("Total <info>{$totalFiles}</info> files to process."); $iterator->rewind(); set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); }); $index = 0; $errors = []; foreach ($iterator as $file) { if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Processing file <info>{$file->getRealPath()}</info>"); } $isSuccess = null; try { // This will trigger creation of cache file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . SourceTransformingLoader::FILTER_IDENTIFIER . '/resource=' . $file->getRealPath()); $isSuccess = true; } catch (\Exception $e) { $isSuccess = false; $errors[$file->getRealPath()] = $e; } if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { $output->write($isSuccess ? '.' : '<error>E</error>'); if (++$index % 50 == 0) { $output->writeln("({$index}/{$totalFiles})"); } } } restore_error_handler(); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { foreach ($errors as $file => $error) { $message = "File {$file} is not processed correctly due to exception: {$error->getMessage()}"; $output->writeln($message); } } $output->writeln('<info>Done</info>'); }
/** * {@inheritDoc} * @return self */ public static function init($configuration = array()) { $defaults = array('module_listener_options' => array(), 'modules' => array(), 'service_manager' => array()); $configuration = ArrayUtils::merge($defaults, $configuration); $configuration['modules'][] = 'ZeffMu'; return parent::init($configuration); }
public static function init() { // Load the user-defined test configuration file, if it exists; otherwise, load if (is_readable(__DIR__ . '/TestConfig.php')) { $testConfig = (include __DIR__ . '/TestConfig.php'); } else { $testConfig = (include __DIR__ . '/TestConfig.php.dist'); } $zf2ModulePaths = array(); if (isset($testConfig['module_listener_options']['module_paths'])) { $modulePaths = $testConfig['module_listener_options']['module_paths']; foreach ($modulePaths as $modulePath) { if ($path = static::findParentPath($modulePath)) { $zf2ModulePaths[] = $path; } } } $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR; $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : ''); static::initAutoloader(); // use ModuleManager to load this module and it's dependencies $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths))); $config = ArrayUtils::merge($baseConfig, $testConfig); $application = \Zend\Mvc\Application::init($config); // build test database $entityManager = $application->getServiceManager()->get('doctrine.entitymanager.orm_default'); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata()); static::$application = $application; }
public function testApplicationUsesLoggedPluginManagers() { $sm = Application::init(array('modules' => array('OcraServiceManager'), 'module_listener_options' => array('module_paths' => array(), 'config_glob_paths' => array())))->getServiceManager(); $pluginManagers = array('ServiceManager', 'ControllerLoader', 'ControllerPluginManager', 'FilterManager', 'FormElementManager', 'HydratorManager', 'InputFilterManager', 'PaginatorPluginManager', 'RoutePluginManager', 'SerializerAdapterManager', 'ValidatorManager', 'ViewHelperManager'); foreach ($pluginManagers as $pluginManager) { $this->assertInstanceOf('ProxyManager\\Proxy\\AccessInterceptorInterface', $sm->get($pluginManager)); } }
public function testControllerRegistered() { $app = \Zend\Mvc\Application::init(require __DIR__ . '/_files/config/application.config.php'); $serviceManager = $app->getServiceManager(); $controllerManager = $serviceManager->get('ControllerManager'); $controller = $controllerManager->get(\Autowp\Image\Controller\ConsoleController::class); $this->assertInstanceOf(\Autowp\Image\Controller\ConsoleController::class, $controller); }
/** * Get the application object * @return \Zend\Mvc\ApplicationInterface */ public function getApplication() { if ($this->application) { return $this->application; } $appConfig = $this->applicationConfig; $this->application = Application::init($appConfig); return $this->application; }
public static function run() { chdir(dirname(self::initParentPath('vendor'))); putenv('ZF2_PATH=vendor/zendframework/zendframework/library'); putenv('APPLICATION_ENV=phpunit'); $loader = (include 'vendor/autoload.php'); Application::init(self::getConfig()); self::initDatabase(); }
protected function setup() { $this->application = Application::init(self::$applicationConfig); $this->serviceManager = $this->application->getServiceManager(); $this->couchDBClient = $this->getDocumentManager()->getCouchDBClient(); $couchDBClient = $this->couchDBClient; $couchDBClient->deleteDatabase($couchDBClient->getDatabase()); $couchDBClient->createDatabase($couchDBClient->getDatabase()); }
/** * Migrates the db to latest * * @param Event $event */ public static function migrate(Event $event) { $zfApp = ZfApp::init(require 'config/application.config.php'); $manager = new PhinxManager($zfApp->getServiceManager()->get('console'), $zfApp->getServiceManager()->get('config')); $argv = $_SERVER['argv']; $_SERVER['argv'] = array('cli', 'phinx', 'migrate'); $manager->command(); $_SERVER['argv'] = $argv; return 0; }
/** * @param string $name The name of the application * @param string $version The version of the application */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')->getServiceManager(); /** * Temporary workaround until the compiler is able to clear the generation directory. (MAGETWO-44493) */ if (class_exists('Magento\\Setup\\Console\\CompilerPreparation')) { (new \Magento\Setup\Console\CompilerPreparation($this->serviceManager, new ArgvInput(), new File()))->handleCompilerEnvironment(); } parent::__construct($name, $version); }
protected function setUp() { $bootstrap = \Zend\Mvc\Application::init(include 'config/application.config.php'); $this->controller = new IndexController(); $this->request = new Request(); $this->routeMatch = new RouteMatch(array('controller' => 'index')); $this->event = $bootstrap->getMvcEvent(); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); $this->controller->setEventManager($bootstrap->getEventManager()); $this->controller->setServiceLocator($bootstrap->getServiceManager()); }
public function _before(\Codeception\TestCase $test) { $applicationConfig = (require \Codeception\Configuration::projectDir() . $this->config['config']); if (isset($applicationConfig['module_listener_options']['config_cache_enabled'])) { $applicationConfig['module_listener_options']['config_cache_enabled'] = false; } Console::overrideIsConsole(false); $this->application = Application::init($applicationConfig); $events = $this->application->getEventManager(); $events->detach($this->application->getServiceManager()->get('SendResponseListener')); $this->client->setApplication($this->application); }
/** * Get the application object * @return \Zend\Mvc\ApplicationInterface */ public function getApplication() { if ($this->application) { return $this->application; } $appConfig = $this->applicationConfig; //Console::overrideIsConsole($this->getUseConsoleRequest()); $this->application = Application::init($appConfig); $events = $this->application->getEventManager(); $events->detach($this->application->getServiceManager()->get('SendResponseListener')); return $this->application; }
/** * @BeforeSuite */ public static function setupTests() { copy('config/autoload/db.test.php.dist', 'config/autoload/db.test.php'); if (file_exists('data/db/test.db')) { unlink('data/db/test.db'); } $appConfig = (require 'config/application.config.php'); if (file_exists('config/development.config.php')) { $appConfig = \Zend\Stdlib\ArrayUtils::merge($appConfig, require 'config/development.config.php'); } self::$application = Application::init($appConfig); }
public function testFilterConfigCanBeInitializedByZendInputFilterFactory() { $app = Application::init($this->appConfig); $inputFilter = new InputFilter(); $app->getServiceManager()->get('InputFilterManager')->populateFactory($inputFilter, null); $config = ['HTML.AllowedElements' => 'a']; $inputFilter->add(['name' => 'test', 'filters' => [['name' => 'htmlpurifier', 'options' => ['purifier_config' => $config]]]]); /** @var Purifier\PurifierFilter $filter */ $filter = $inputFilter->get('test')->getFilterChain()->getFilters()->top(); $this->assertInstanceOf(Purifier\PurifierFilter::class, $filter); $this->assertEquals($config, $filter->getPurifierConfig()); }
/** * Get the test application. * * @return Application */ public static function getApplication() { // Return the application immediately if already set. if (self::$application instanceof Application) { return self::$application; } $config = (require OMEKA_PATH . '/config/application.config.php'); $reader = new \Zend\Config\Reader\Ini(); $testConfig = ['connection' => $reader->fromFile(OMEKA_PATH . '/application/test/config/database.ini')]; $config = array_merge($config, $testConfig); self::$application = Application::init($config); return self::$application; }
protected function bootApp() { if (!$this->booted) { $config = ['modules' => ['Zend\\Router', 'Zend\\Validator'], 'module_listener_options' => []]; if ($this->isServiceLocatorSet) { $config['listeners'] = ['facade-listener']; $config['service_manager'] = ['invokables' => $this->services, 'factories' => ['facade-listener' => function () { return $this->getFacadeListener($this->aliases); }]]; } $this->app = Zend\Mvc\Application::init($config); $this->booted = true; } }
static function go() { // Make everything relative to the root //chdir(dirname(__DIR__)); // Setup autoloading require_once __DIR__ . '/../../../init_autoloader.php'; // Run application $config = (require __DIR__ . '/../../../config/application.config.php'); \Zend\Mvc\Application::init($config); $serviceManager = new ServiceManager(new ServiceManagerConfig()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); self::$serviceManager = $serviceManager; }
protected function setUp() { $bootstrap = \Zend\Mvc\Application::init(include 'config/application.config.php'); $serviceManager = $bootstrap->getServiceManager(); $service = $serviceManager->get('Cobalt\\EntityService\\DepartmentService'); $this->controller = new DepartmentController($service); $this->request = new Request(); $this->routeMatch = new RouteMatch(array('controller' => 'department')); $this->event = $bootstrap->getMvcEvent(); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); $this->controller->setEventManager($bootstrap->getEventManager()); $this->controller->setServiceLocator($bootstrap->getServiceManager()); }
public static function go() { $zf2Path = realpath(defined('ZF2_PATH') ? ZF2_PATH : (getenv('ZF2_PATH') ?: '/zf2/library')); // parent directory of this module $zf2ModulesPaths = dirname(dirname(__DIR__)) . PATH_SEPARATOR; // other paths to find modules one $zf2ModulesPaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: realpath(__DIR__ . '/../../../vendor'); // autoload ZF2 include $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array('autoregister_zf' => true))); // use ModuleManager to load this module and it's dependencies $config = array('modules' => array('SpeckPI', 'SpeckCart', 'ZfcBase'), 'module_listener_options' => array('config_glob_paths' => array(__DIR__ . '/config/autoload/{,*.}{global,local}.php'), 'config_cache_enabled' => false, 'module_paths' => explode(PATH_SEPARATOR, $zf2ModulesPaths))); $app = Application::init($config); self::$serviceManager = $app->getServiceManager(); }
/** * Initialize test. */ public function bootstrap() { if ($this->application) { return; } error_reporting(E_ALL | E_STRICT); if (is_readable('./application.config.php')) { $config = (include './application.config.php'); } else { $config = (include '/Users/svenanders/zend/robbis4/current/config/test/application.config.php'); } if (is_readable('./module.config.php')) { $config['module_listener_options']['config_glob_paths'][] = './module.config.php'; } $this->application = Application::init($config); }
public static function init() { $zf2ModulePaths = array(dirname(dirname(__DIR__))); if ($path = static::findParentPath('vendor')) { $zf2ModulePaths[] = $path; } if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0] && $path) { $zf2ModulePaths[] = $path; } static::initAutoloader(); // use ModuleManager to load this module and it's dependencies $config = array('module_listener_options' => array('module_paths' => $zf2ModulePaths, 'config_glob_paths' => array(__DIR__ . '/application.config.php')), 'modules' => array('MaglLegacyApplication')); $app = Application::init($config); \MaglLegacyApplication\Application\MaglLegacy::getInstance()->setApplication($app); static::$serviceManager = $app->getServiceManager(); }
/** * @BeforeSuite */ public static function iniializeZendFramework() { if (self::$zendApp === null) { $config = (require __DIR__ . '/../../config/application.config.php'); self::$zendApp = Application::init($config); } }