Config in global.php or local.php not working but works from module.config.php in laminas api

一个人想着一个人 提交于 2020-05-17 08:49:39

问题


Config in global.php or local.php not working but works from module.config.php in laminas API.

So when developer mode is enabled it works with local.php but as soon as I deploy it doesn't. But when I add the database details in module.config.php then it works.

public function __invoke($services)
{
    $db    = 'Db\StatusLib';
    $table = 'status';
    if ($services->has('config')) {
        $config = $services->get('config');
        switch (isset($config['statuslib'])) {
            case true:
                $config = $config['statuslib'];
                $db     = isset($config['db']) ? $config['db'] : $db;
                $table  = isset($config['table']) ? $config['table'] : $table;
                break;
            case false:
            default:
                break;
        }
    }

    if (! $services->has($db)) {
        throw new DomainException(sprintf(
            'Unable to create %s due to missing "%s" service',
            TableGateway::class,
            $db
        ));
    }

    return new TableGateway($table, $services->get($db));
}

https://github.com/laminas-api-tools/statuslib-example/blob/master/src/TableGatewayFactory.php#L26

https://github.com/laminas-api-tools/statuslib-example/blob/master/config/module.config.php#L12

return [
    'statuslib' => [
        // 'array_mapper_path' => 'path/to/PHP/file/returning/array.php',
    ],
    'service_manager' => [
        'aliases' => [
            Mapper::class => ArrayMapper::class,

            // Legacy Zend Framework aliases
        ],
        'factories' => [
            ArrayMapper::class        => ArrayMapperFactory::class,
            TableGatewayMapper::class => TableGatewayMapperFactory::class,
            TableGateway::class       => TableGatewayFactory::class,
        ],
    ],
];

As soon as I move these configs to local.php or global.php then it throws this error:

Service with name "StatusLib\TableGateway" could not be created. Reason: Unable to create StatusLib\TableGateway due to missing "Db\StatusLib" service

What am I missing?

UPDATE

And the cache is disabled.

来源:https://stackoverflow.com/questions/61679035/config-in-global-php-or-local-php-not-working-but-works-from-module-config-php-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!