I would like to use Zend Service Manager in my custom codebase. It is not built on Zend MVC and instead I am only using a few Zend Packages like Zend Console and Zend Config.
I would like to use Zend Service Manager with a functionality, as soon as the code enters my Core class, I would like to initialize DB and Config objects and save them as a service in Zend Service Manager. Now I would like to use this service throughout my codebase.
Is there a way to use it without passing the service manager in constructor of each class? Also, my other classes will not be extending from this Core class and instead this Core class will create objects based on my requirements.
This is how I am creating a service:
$config = \Zend\Config\Factory::fromFiles([
APPLICATION_PATH . '/config/config.ini',
APPLICATION_PATH . '/config/' . $route->getMatchedParam('brand') . '/' . $route->getMatchedParam('department') . '/config.ini',
]);
$serviceManager = new ServiceManager([
'factories' => [
stdClass::class => InvokableFactory::class,
],
]);
$serviceManager->setService('config', $config);