Skip to content

[Validation] Checks if the provided array configuration is cache-able #1

@gabbydgab

Description

@gabbydgab

Ability to check if the array configuration is cache-able or not. Will return false if the configuration is mapped to a closure.

$config = [
    'dependencies' => [
         'factories' => [
             'closure-factory' => function () { return new \stdClass() }
         ]
    ]
];
// backwards compatible
ArrayUtils::isCacheable($config); // returns false

// using validator class
ArrayValidator::isCacheable($config); // returns false

Checking all loaded configuration:

It will reduce the following merge configuration logic in Zend\ConfigAggregator

Practical usage

private function cacheConfig(array $config, $cachedConfigFile)
{
    if (!ArrayValidator::isCacheable($config)) {
          throw new InvalidArgumentException('Cannot cached config from %s; does not return array', $config);
    }

    // cache the config
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions