Skip to content

Commit

Permalink
enabled bootstrapping of MVC Application
Browse files Browse the repository at this point in the history
optional via $appConfig['laminas-cli']['bootstrap_mvc_application']
  • Loading branch information
FalkHe committed Mar 9, 2023
1 parent 97930db commit a74c954
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/ContainerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use InvalidArgumentException;
use Laminas\ModuleManager\ModuleManagerInterface;
use Laminas\Mvc\Application;
use Laminas\Mvc\Service\ServiceManagerConfig;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;
Expand Down Expand Up @@ -98,18 +99,31 @@ private function resolveMvcContainer(string $path): ContainerInterface
Assert::isMap($appConfig);
}

$servicesConfig = $appConfig['service_manager'] ?? [];
Assert::isMap($servicesConfig);
Assert::classExists(Application::class);

$smConfig = new ServiceManagerConfig($servicesConfig);
if ($appConfig['laminas-cli']['bootstrap_mvc_application'] ?? false) {
// initialize & bootstrap MVC Application
$mvcApplication = Application::init($appConfig);
$serviceManager = $mvcApplication->getServiceManager();
} else {
/* @deprecated MVC Application is not bootstrapped */
trigger_error('Running laminas-cli in MVC Environment without bootstrapping ' .
'the MVC Application is deprecated. ' .
'@see https://github.com/laminas/laminas-cli/issues/106', E_USER_DEPRECATED);

$serviceManager = new ServiceManager();
$smConfig->configureServiceManager($serviceManager);
$serviceManager->setService('ApplicationConfig', $appConfig);
$servicesConfig = $appConfig['service_manager'] ?? [];
Assert::isMap($servicesConfig);

$moduleManager = $serviceManager->get('ModuleManager');
Assert::isInstanceOf($moduleManager, ModuleManagerInterface::class);
$moduleManager->loadModules();
$smConfig = new ServiceManagerConfig($servicesConfig);

$serviceManager = new ServiceManager();
$smConfig->configureServiceManager($serviceManager);
$serviceManager->setService('ApplicationConfig', $appConfig);

$moduleManager = $serviceManager->get('ModuleManager');
Assert::isInstanceOf($moduleManager, ModuleManagerInterface::class);
$moduleManager->loadModules();
}

return $serviceManager;
}
Expand Down

0 comments on commit a74c954

Please sign in to comment.