How to get RobotLoader from DI\Container?

7 years ago

juzna.cz
Member | 249
+
0
-

Since RobotLoader is now created by Configurator prior to creating the context, it's not available as a service anymore. However, I need it as a service, because other services need it (as their dependency).

Now I get error:
No service of type Nette\Loaders\RobotLoader

Can the Configurator pass created instance of RobotLoader into cotext being created? Thanks

7 years ago

HosipLan
Moderator | 4693
+
0
-
function getRobot()
{
    foreach (Nette\Loaders\AutoLoader::getLoaders() as $loader) {
        if ($loader instanceof Nette\Loaders\RobotLoader) {
            return $loader;
        }
    }
}

7 years ago

juzna.cz
Member | 249
+
+2
-

But I need it to be available in the SystemContainer.

I added robot loader service into config.neon:

robotLoader:
    class: Nette\Loaders\RobotLoader
    setup:
        - setCacheStorage

And then I attach existing instance in bootstrap.php:

$robotLoader = $configurator->createRobotLoader() ....;
...
$context = $configurator->createContainer();
$context->addService('robotLoader', $robotLoader);

This seems to work fine