Wie zu verwenden global.php/local.php configs im getConfig() von einem Modul in einer Zend Framework 2 Anwendung?

In einem ZF2-Anwendung ich habe einige cofigs, dass: 1. anders sein muss dependening auf die Umwelt; 2. sind spezifisch für ein konkretes Modul. Ich bin curently es hier beschrieben:

global.php & local.php

return array(
    ...
    'modules' => array(
        'Cache' => array(
            'ttl' => 1, //1 second
        )
    )
    ...
);

Modul-Klassen -

Module {
    ...
    public function getServiceConfig() {
        try {
            return array (
                'factories' => array(
                    'Zend\Cache\Adapter\MemcachedOptions' => function ($serviceManager) {
                        return new MemcachedOptions(array(
                            'ttl'           => $this->getConfig()['modules']['Cache']['ttl'],
                            ...
                        ));
                    },
                    ...
                )
            );
        }
        ...
    }
    ...
}

Es funktioniert gut, aber ich glaube, dass die Modul-spezifischen Einstellungen zugegriffen werden soll, über eine zentrale Stelle im Modul -- die getConfig() Methode der Module Klasse. Wie diese:

class Module {

    public function getConfig() {
        $moduleConfig = include __DIR__ . '/config/module.config.php';
        $application = $this->getApplicationSomehow(); //<-- how?
        $applicationModuleConfig = $application->getConfig()['modules'][__NAMESPACE__];
        $config = array_merge($moduleConfig, $applicationModuleConfig);
        return $config;
    }
    ...
    public function getServiceConfig() {
        try {
            return array (
                'factories' => array(
                    'Zend\Cache\Adapter\MemcachedOptions' => function ($serviceManager) {
                        return new MemcachedOptions(array(
                            'ttl'            => $serviceManager->get('Config')['modules']['Cache']['ttl'],
                            ...
                        ));
                    },
                    ...
                )
            );
        }
        ...
    }
    ...
}

Das problem ist, dass ich nicht bekommen, wie Sie auf die global.php/local.php configs in der getConfig() eines Moduls. Wie kann ich es tun?

InformationsquelleAutor automatix | 2013-04-05

Schreibe einen Kommentar