illchuk/zend-config-cacheproof

创建跳过缓存并具有自定义加载的 *.cacheproof.php 配置文件。

v0.1.1 2017-10-14 04:35 UTC

This package is auto-updated.

Last update: 2024-09-08 09:17:37 UTC


README

Build Status

目的

缓存配置很方便(例如使用 'module_listener_options' => ['config_cache_enabled' => true]),但这样会将配置锁定。如果需要为测试等调整一些设置怎么办?这就是 ZendConfigCacheproof 的用武之地。

使用 composer require illchuk/zend-config-cacheproof 进行安装。

然后在 modules.config.php 中引用

return [
    ..., 'ZendConfigCacheproof', ...
];

快速开始

在您的 config/autoload 中创建 *.cacheproof.php 配置文件。(与通常的 *.global.php*.local.php 文件不同。)这些文件将每次都加载。

实用开始

您可能希望配置根据环境变量进行更改;安装一个 cacheproof_loaders 工厂——请参阅 config/cacheproof.global.php.dist——如下所示

namespace Application\Cacheproof;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use ZendConfigCacheproof\Loader\EnvironmentVariable as EnvLoader;

class LoaderFactory implements FactoryInterface {

    const GLOB_LIVE = './config/autoload/{{,*.}live}.php';
    const ENV_VAR_LIVE = 'INSTANCE_LIVE';

    public function __invoke(
    ContainerInterface $container, $requestedName, array $options = null
    ) {
        $loader = new EnvLoader(static::ENV_VAR_LIVE);
        $loader->setGlob(static::GLOB_LIVE);
        return $loader;
    }

}

然后,当环境变量 INSTANCE_LIVE 为真时,您的 ./config/autoload/{{,*.}live}.php 配置将被实时加载。

移除冲突配置

您可能还想移除配置。可以按以下方式操作

<?php // in ./config/autoload/cacheproof.php

return [
    'foobar' => new \Zend\Stdlib\ArrayUtils\MergeRemoveKey, // toast it
]