Search code examples
phpconfigzend-framework3service-locator

ZF3 correct place to put your api keys


I guess I am doing it right because I can overrule the file by development mode but to be sure I ask. What is the right place to store API keys for services I installed through composer. For now I store the keys in the autoload directory inside local.php and receive them through service locator.

For example

$config  = $this->serviceLocator->get('Config'); 
var_dump($config['service_name_api']); // Returns api key

Is this the right way or should I use another way to access those properties?


Solution

  • Best place would be:

    config/autoload/{config file name you want}.local.php
    

    I suggest structure:

    [
        'keystore' => [
            'api' => [
                // keys array
            ]
        ]
    ]
    

    Repeat I suggest a structure above, you can create your own structure but anyway add

    config/autoload/{config file name you want}.local.php.dist
    

    file that has an example data on it.