Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional include of config/laminas-cli.php or something similar #78

Open
rarog opened this issue Jun 5, 2021 · 4 comments
Open

Optional include of config/laminas-cli.php or something similar #78

rarog opened this issue Jun 5, 2021 · 4 comments

Comments

@rarog
Copy link

rarog commented Jun 5, 2021

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

For some of the logic of console commands it would be good and safe to be able to include an additional config file to override module options.
In my specific case I use console command to clean caches and in case some of the module listener caches are horribly invalid, my command would break. By including additional config file, I could implement a safety net by including following lines, which would prevent those caches to be loaded even if they are enabled globally.

return [
    'module_listener_options' => [
        'config_cache_enabled' => false,
        'module_map_cache_enabled' => false,
    ],
];
@weierophinney
Copy link
Member

There's a way to do this as of 1.1.0.

As of 1.1.0, you can specify the --container global option and point it at an alternate file that will return your PSR-11 container. So, as an example, you could do something like this:

<?php // in config/clear-cache-container.php

use Laminas\Mvc\Service\ServiceManagerConfig;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;

$config        = require __DIR__ . '/application.config.php';
$devConfig = __DIR__ . '/development.config.php';
if (file_exists($devConfig)) {
    $devConfig = include $devConfig;
    $config        = ArrayUtils::merge($config, $devConfig);
}

$config['modules_listener_options'] => [
    'config_cache_enabled' => false,
    'module_map_cache_enabled' => false,
];

$container = new ServiceManager();
(new ServiceManagerConfig($config['service_manager'] ?? []))->configureServiceManager($container);
$container->setService('ApplicationConfig', $config);
$container->get('ModuleManager')->loadModules();

return $container;

Then, when calling laminas-cli for such operations, pass the location of this file:

$ ./vendor/bin/laminas-cli --container ./config/clear-cache-container.php {command...}

@froschdesign froschdesign added the Documentation Improvements or additions to documentation label Jun 7, 2021
@froschdesign
Copy link
Member

The example must be added to the documentation.

@froschdesign froschdesign added this to To do in Documentation: improvements via automation Jun 7, 2021
@froschdesign froschdesign self-assigned this Jun 7, 2021
@rarog
Copy link
Author

rarog commented Jun 8, 2021

A small correction to above code, that I successfully implemented in my project. Thx for the help!

<?php // in config/clear-cache-container.php

use Laminas\Mvc\Service\ServiceManagerConfig;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;

$config = require __DIR__ . '/application.config.php';
$devConfig = __DIR__ . '/development.config.php';
if (file_exists($devConfig)) {
    $devConfig = include $devConfig;
    $config = ArrayUtils::merge($config, $devConfig);
}

$configDisableCaches = [
    'modules_listener_options' => [
        'config_cache_enabled' => false,
        'module_map_cache_enabled' => false,
    ]
];
$config = ArrayUtils::merge($config, $configDisableCaches);

$container = new ServiceManager();
(new ServiceManagerConfig($config['service_manager'] ?? []))->configureServiceManager($container);
$container->setService('ApplicationConfig', $config);
$container->get('ModuleManager')->loadModules();

return $container;
`

@froschdesign froschdesign removed the Documentation Improvements or additions to documentation label Aug 24, 2021
@froschdesign
Copy link
Member

This feature should be added to laminas-cli, the current solution is only a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants