dvsa/laminas-config-cloud-parameters

v2.0.0 2024-08-30 08:46 UTC

README

这个Composer库简化了Laminas配置占位符的使用,允许使用Symfony ParameterBag替换云服务提供的变量存储值。

如何使用

在Laminas MVC应用程序中

  1. 在配置中配置云提供商

    <?php
    
    use Dvsa\LaminasConfigCloudParameters\Provider\SecretsManager;
    use Dvsa\LaminasConfigCloudParameters\Cast\Boolean;
    use Dvsa\LaminasConfigCloudParameters\Cast\Integer;
    
    return [
        'config_parameters' => [
            'providers' => [
                SecretsManager::class => [
                    'example-secret',
                    // ...
                ],
                
                // ...
            ],
    
            'casts' => [
                // Uses `symfony/property-access` to access the property. See https://symfony.com.cn/doc/current/components/property_access.html#reading-from-arrays.
                '[foo]' => Boolean::class,
                '[bar][nested]' => Integer::class,
    
                // ...
            ],
        ],
        // ...
    ];
  2. 使用Laminas ModuleManager注册模块

    <?php
    // module.config.php
    
    return [
        'Dvsa\LaminasConfigCloudParameters',
        // ...
    ];
  3. 然后可以将占位符添加到Laminas配置中

    return [
        'foo' => '%bar%',
        'bar' => [
            'nested' => '%baz%',
        ],
    ];

可用的云参数提供者

AWS

密钥管理器

仅支持存储在键/值对中的密钥。

示例配置

<?php

return [
    'config_parameters' => [
        'providers' => [
            SecretsManager::class => [
                'global-secrets',
                sprintf('environment-%s-secrets', $environment),
            ],
            
            // ...
        ],
    ],
];

参数存储

参数将按路径递归加载。键将是不包含路径的参数名称。

示例配置

<?php

use Dvsa\LaminasConfigCloudParameters\Provider\ParameterStore;

return [
    'config_parameters' => [
        'providers' => [
            ParameterStore::class => [
                '/global',
                sprintf('/env-%s', $environment),
            ],
            
            // ...
        ],
    ],
];