zend-config is designed to simplify access to configuration data within applications

Overview

zend-config

Repository abandoned 2019-12-31

This repository has moved to laminas/laminas-config.

Build Status Coverage Status

zend-config is designed to simplify access to configuration data within applications. It provides a nested object property-based user interface for accessing this configuration data within application code. The configuration data may come from a variety of media supporting hierarchical data storage.

Comments
  • Implemented option to process INI sections or not

    Implemented option to process INI sections or not

    By default the INI reader is processing sections. It is not possible to merge sections, which is the default behavior of parse_ini_file().

    This PR introduces the protected property $processSections with a public getter and setter. It enables users to tell the reader not to process sections by setting $processSections to false. The default behavior of the reader does not change.

    • [x] Are you creating a new feature? Yes
      • [x] Why is the new feature needed? What purpose does it serve? See description above
      • [x] How will users use the new feature? See docs/book/reader.md in the INI section
      • [x] Base your feature on the develop branch, and submit against that branch. Check
      • [x] Add only one feature per pull request; split multiple features over multiple pull requests Check
      • [x] Add tests for the new feature. Check
      • [x] Add documentation for the new feature. Check
      • [x] Add a CHANGELOG.md entry for the new feature.
    enhancement 
    opened by arueckauer 7
  • Subnodes has the same type as the parent node

    Subnodes has the same type as the parent node

    In case we extend the Config class we would like to have the same type of the subnodes as the parent node.

    Relates to #55 / #56

    • [x] Is this related to quality assurance?
    opened by michalbundyra 6
  • add composer.lock & update travis config

    add composer.lock & update travis config

    as per zendframework/zendframework#7660

    also entails these changes:

    • bump minimum php version to 5.6
    • bump minimum phpunit version to 4.8
    • add composer scripts entries
    • fix coveralls configuration
    • fix travis.yml env variables to not be affected by travis-ci/travis-ci#1444
    • remove obsolete phpunit bootstrap
    opened by stefanotorresi 5
  • add support to modify by reference

    add support to modify by reference

    This adds resolution to typical notice seen:

    Indirect modification of overloaded element of Zend\Config\Config has no effect

    Example:

    
            $config = new Config($this->all, true);
    
            $closure = function (&$property, $value) {
                if ($property === null) {
                    return;
                }
    
                $property = $value;
            };
    
            // updates $config['db']['pass'] value to 'secret'
            $closure($config['db']['pass'], 'secret');
            // $config['db']['pass2'] is not present and will not be created
            $closure($config['db']['pass2'], 'secret');
    

    This requires PHP 5.3.4 :

    Update: This problem was fixed in PHP 5.3.4 and ArrayAccess now works as expected:

    Starting with PHP 5.3.4, the prototype checks were relaxed and it's possible for implementations of this method to return by reference. This makes indirect modifications to the overloaded array dimensions of ArrayAccess objects possible.

    • https://stackoverflow.com/a/2881533/2314626
    wontfix 
    opened by glensc 4
  • Allow processing class constants

    Allow processing class constants

    This patch updates the Constant processor to allow processing class constants, including the ::class pseudo-constant; additionally, it ensures that both the Token and Constant processors can apply to Config keys as well as the values by calling their enableKeyProcessing() methods.

    To allow this to work, I've changed the visibility of Token::doProcess() from private to protected, to allow overriding the method within the Constant class. I've also added the new test case ZendTest\Config\Processor\Constant to cover the behavior.

    Essentially, this allows the following to work (assuming the provided classes and constants exist):

    {
        "Acme\\Component::CONFIG_KEY": {
            "host": "Acme\\Component::CONFIG_HOST",
            "dependencies": {
    	    "Acme\\Foo::class": "Acme\\FooFactory::class",
            }
        }
    }
    

    Via:

    $config = new Config(Factory::fromFile('config.json'), true);
    $processor = new Processor\Constant();
    $processor->enableKeyProcessing();
    $processor->process($config);
    
    enhancement 
    opened by weierophinney 4
  • Updated to zend-servicemanager v3

    Updated to zend-servicemanager v3

    • composer.json entry for zend-servicemanager using dev-develop as 2.7.0.
    • Updated AbstractConfigFactory to follow new interface definition.
    • Updated ReaderPluginManager and WriterPluginManager to follow changes in AbstractPluginManager; they aggregate invokables and merge them with incoming configuration before passing on to the parent constructor.
    • Updated Factory to pass an empty service manager instance to plugin managers when lazy loading them.
    enhancement BC Break 
    opened by weierophinney 4
  • Infinite loop if class is extended (specific circumstances)

    Infinite loop if class is extended (specific circumstances)

    • [x] I was not able to find an open or closed issue matching what I'm seeing.
    • [x] This is not a question.

    I'm trying to extend Zend\Config\Config and supply default config. I also add some extra methods.

    Code to reproduce the issue

    
    <?php
    
    namespace Zend\Config\Issue;
    
    use Zend\Config\Config;
    
    /**
     * Class Simple
     * @package Zend\Config\Issue
     */
    class Simple extends Config
    {
        /** @var int */
        private static $callsCount = 0;
    
        /**
         * Simple constructor.
         */
        public function __construct()
        {
            self::$callsCount++;
            echo __METHOD__ . " - Number of calls: " . self::$callsCount . PHP_EOL;
    
            $default = [
    
                'something' => [
                    0 => 'I am an array',
                    1 => '\Zend\Config\Config::__construct() will try to create new instance of itself',
                    2 => 'And that\'s fine',
                    3 => 'As long as it does "new self" instead of "new static"',
                    4 => 'because static means this extending class'
                ],
                'something_else' => 'this is fine'
            ];
    
            // Call parent constructor \Zend\Config\Config::__construct()
            parent::__construct($default);
        }
    
    
    }
    
    

    Expected results

    Definitely not infinite loop.

    Actual results

    Infinite loop - class Simple is calling Zend\Config\Config::__construct() and Zend\Config\Config will try to create new instance of itself using "new static()", which will in turn call extending class Simple ..... If you run code I provided, you will get following output:

    Zend\Config\Issue\Simple::__construct - Number of calls: 1
    Zend\Config\Issue\Simple::__construct - Number of calls: 2
    Zend\Config\Issue\Simple::__construct - Number of calls: 3
    Zend\Config\Issue\Simple::__construct - Number of calls: 4
    Zend\Config\Issue\Simple::__construct - Number of calls: 5
    Zend\Config\Issue\Simple::__construct - Number of calls: 6
    Zend\Config\Issue\Simple::__construct - Number of calls: 7
    Zend\Config\Issue\Simple::__construct - Number of calls: 8
    (...)
    
    opened by xZero707 3
  • Option to render class name scalars using PHP 5.5+ class-keyword.

    Option to render class name scalars using PHP 5.5+ class-keyword.

    As proposed in #5.

    I thought about adding an option to toggle the autoload usage, but I could not find any reason why you would want to set it. If you want it to be added, let me know.

    I did not add a trailing slash to resolved ::class-literals, because:

    • The rendered output does not include any namespacing.
    • Even if the rendered output is included in another namespace, PHP does not transfer the context to the included file.

    Close #4 Close #5

    enhancement 
    opened by akomm 3
  • PR: Writer\PhpArray option to use ::class literals

    PR: Writer\PhpArray option to use ::class literals

    Similar to the use_bracket_array_syntax-option, I would propose to add a use_class_contant-option.

    If enabled, string keys and values should be checked for being a known full qualified class- or-interface name, using class_exists and interface_exists.

    Additional option use_class_constant_autoload might be added, to set whether autoload should be used.

    It only works if the names are defined in the main file, were included/required from another script or a registered autoloader can resolve them.

    I'v tried it on some packages, which use this writer and it worked well without breaking anything.

    Possible issues:

    Writing config in a different context than reading it (e. G. different autoloader configs). But since it is an option you don't have to use it. Depending on usage context you can localy enable this option for development and disable for deployment.

    enhancement 
    opened by akomm 3
  • Java properties configuration file reader (separator) / Writer

    Java properties configuration file reader (separator) / Writer

    @weierophinney

    Good morning,

    Could it be possible to make us able to setup the separator to use for the Java propertie configuration file reader? Right now, the colon sign is hardcoded, making us unable to change it by equal sign which should be also supported. You should also maybe considere a new option allowing to remove leading and trailing whitespaces from resulting key/value pairs.

    For now, we have not other choice than doing https://github.com/i-MSCP/imscp/commit/69df56265aea1a95d947ed708a8839c0dc7c13aa and then:

    namespace iMSCP;
    
    use iMSCP\Config\Reader\JavaProperties;
    use iMSCP\Config\StandaloneReaderPluginManager;
    use Zend\Config\Config;
    use Zend\Config\Factory;
    
    // Load default settings, that is, those that are overridable by administrator through GUI
    $config = new Config(include_once 'default_settings.php', true);
    
    // Load and merge settings from master i-MSCP configuration file.
    // We need set our own JavaProperties configuration file reader as
    // the one provided by ZF doesn't handle equal sign as separator
    Factory::setReaderPluginManager(new StandaloneReaderPluginManager());
    Factory::registerReader('conf', JavaProperties::class);
    $config->merge(new Config(Factory::fromFile(CONFIG_FILE_PATH)));
    

    Regarding the above code, maybe that the standalone reader plugin manager should also accept custom definitions because right now, we need provide our own.

    Finally, could you provide a writer implementation for that configuration file type?

    Thank you.

    opened by nuxwin 2
  • Fix issue #55 - Infinite loop if class is extended and array has another array

    Fix issue #55 - Infinite loop if class is extended and array has another array

    Provide a narrative description of what you are trying to accomplish:

    • [x] Are you fixing a bug?
      • [ ] Details in the issue #55
      • [ ] Infinite loop
      • [ ] Using self will not cause extending class to be called

    No tests are supplied because existing tests cover this change.

    opened by xZero707 1
  • Added Env processor to allows users to read the value of the getenv() function in static configuration files.

    Added Env processor to allows users to read the value of the getenv() function in static configuration files.

    This feature will allow getenv function to be run from static files like yaml.

    Using Zend\Config\Processor\Env

    This example illustrates the basic usage of Zend\Config\Processor\Env:

    putenv('AMQP_PASSWORD=guest');
    
    use Zend\Config\Config;
    use Zend\Config\Factory;
    use Zend\Config\Processor\Env as EnvProcessor;
    
    $config = new Config([
                'host' => '127.0.0.1',
                'port' => 5672,
                'username' => 'guest',
                'password' => 'env(AMQP_PASSWORD)',
                'vhost' => '/',
            ], true);
    
    $processor = new EnvProcessor;
    $processor->process($config);
    $config->setReadOnly();
    
    echo $config->amqp->password;
    

    This example returns the output: guest.

    awaiting author updates 
    opened by eguvenc 4
  • What do you think about adding env processor for static files ?

    What do you think about adding env processor for static files ?

    • [x] I was not able to find an open or closed issue matching what I'm seeing.
    • [x] This is not a question. (Questions should be asked on chat (Signup here) or our forums.)

    Code to reproduce the issue

    # amqp.yaml
    # 
    amqp:
        host: 127.0.0.1
        port: 5672
        username: 'env(AMQP_USERNAME)'
        password: 'env(AMQP_PASSWORD)'
        vhost: /
    
    namespace Zend\Config\Processor;
    
    use Zend\Config\Config;
    use Zend\Config\Exception;
    use Zend\Config\Processor\Token;
    use Zend\Config\Processor\ProcessorInterface;
    
    class Env extends Token implements ProcessorInterface
    {
        protected function doProcess($value, array $replacements)
        {
            if (! is_string($value)) {
                return parent::doProcess($value, $replacements);
            }
    
            if (false === strpos($value, 'env(')) {
                return parent::doProcess($value, $replacements);
            }
    
            $value = $this->parseEnvRecursive($value);
    
            return $value;
        }
    
        /**
         * Parse env variables
         * 
         * @param mixed $input input
         * @return string
         */
        protected function parseEnvRecursive($input)
        {
            $regex = '/env\((.*?)\)/';
            if (is_array($input)) {
                $input = getenv($input[1]);
            }
            return preg_replace_callback($regex, array($this, 'parseEnvRecursive'), $input);
        }
    }
    
    require 'vendor/autoload.php';
    
    use Symfony\Component\Yaml\Yaml as SymfonyYaml;
    use Zend\Config\Config;
    use Zend\Config\Factory;
    use Zend\Config\Processor;
    use Zend\Config\Reader\Yaml as YamlConfig;
    
    Factory::registerReader('yaml', new YamlConfig([SymfonyYaml::class, 'parse']));
    
    putenv('AMQP_USERNAME=guest');
    
    $config = Factory::fromFile(dirname(__FILE__).'/config/amqp.yaml');
    
    $config = new Config($config, true);
    $processor = new Processor\Env();
    $processor->process($config);
    $config->setReadOnly();
    
    echo $config->amqp->username; // guest
    

    Expected results

    // guest

    opened by eguvenc 1
  • Questions/thoughts regarding WriterInterface

    Questions/thoughts regarding WriterInterface

    I came to the following question/thoughts by chance, when I'v started implement a writer capable to write array configuration into multiple files. It splits configuration by criteria, currently hard-coded by key, later by strategy defined, into different files and join them in a stub-file, which includes the config from separate files.

    I use it for example in zfcampus/zf-configuration, to reduce the configuration file size and split top level keys into separate files. This way I can find things much quicker, if further module-separation is not possible/logical.

    Now everything works fine, but I'v noticed, that the API defined by WriterInterface does not make much sense in my new writer, because toString() would only return the stub-file contents.

    This made me think about two possibilities: Either my implementation of WriterInterface is misusing this interface and it is actually something else, that should internally use Writers, but is itself not a writer or the current spec for Writer in zend-config is to concrete.

    My conclusion so far is:

    • The job of my WriterInterface implementation is really to write the configuration, not something do something else. How it writers, in a single or multiple files, or even maybe not in a file, does not make it something else, than a writer.
    • Actually the current WriterInterface is rather something like a FileWriterInterface. A configuration should actually be writable to indefinite type of targets.

    Example how it seem logical to me, but if I'm wrong with my thought somewhere, correct me:

    interface WriterInterface
    {
        /**
         * Write configuration
         * 
         * @param mixed $config
         */
        public function write($config);
    }
    
    interface FileWriterInterface extends WriterInterface
    {
        /**
         * Write a config object to a file.
         *
         * @param  string  $filename
         * @param  mixed   $config
         * @param  bool $exclusiveLock
         * @return void
         */
        public function toFile($filename, $config, $exclusiveLock = true);
    
        /**
         * Write a config object to a string.
         *
         * @param  mixed $config
         * @return string
         */
        public function toString($config);
    }
    

    Whether Interfaces like the FileWriterInterface are actually needed then is another question. What do you think about it?

    opened by akomm 1
Releases(release-3.3.0)
  • release-3.3.0(Jun 8, 2019)

    Added

    • #54 adds support for PHP 7.3.
    • #58 adds $processSections to INI reader, allowing control over whether sections should be parsed or not
    • #63 adds .yml to Zend\Config\Factory as an alternative extension for yaml

    Changed

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • release-3.2.0(Apr 24, 2018)

    Added

    • #47 adds Zend\Config\Writer\JavaProperties, a complement to Zend\Config\Reader\JavaProperties, for writing JavaProperties files from configuration. The writer supports specifying an alternate key/value delimiter (the default is ":") via the constructor.

    • #46 adds a constructor option to the JavaProperties reader to allow users to indicate keys and values from the configuration should be trimmed of whitespace:

      $reader = new JavaProperties(
        JavaProperties::DELIMITER_DEFAULT, // or ":"
        JavaProperties::WHITESPACE_TRIM,   // or true; default is false
      );
      
    • #45 adds the ability to specify an alternate key/value delimiter to the JavaProperties config reader via the constructor: $reader = new JavaProperties("=");.

    • #42 adds support for PHP 7.1 and 7.2.

    Changed

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • #42 removes support for HHVM.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • release-3.1.0(Feb 22, 2017)

    Added

    • #37 adds a new method, enableKeyProcessing(), and constructor argument, $enableKeyProcessing = false, to each of the Token and Constant processors. These allow enabling processing of tokens and/or constants encountered in configuration key values.
    • #37 adds the ability for the Constant processor to process class constants, including the ::class pseudo-constant.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • release-3.0.0(Feb 16, 2017)

    Added

    • #36 adds support for PSR-11.
    • #36 adds the class Zend\Config\StandaloneReaderPluginManager for managing config reader plugins. This implementation implements the PSR-11 ContainerInterface, and uses a hard-coded list of reader plugins.
    • #36 adds the class Zend\Config\StandaloneWriterPluginManager for managing config writer plugins. This implementation implements the PSR-11 ContainerInterface, and uses a hard-coded list of writer plugins.

    Changes

    • #36 updates the Zend\Config\Factory::getReaderPluginManager() method to lazy-load a StandaloneReaderPluginManager by default, instead of a ReaderPluginManager, allowing usage out-of-the-box without requiring zend-servicemanager.
    • #36 updates the Zend\Config\Factory::setReaderPluginManager() method to typehint against Psr\Container\ContainerInterface instead of ReaderPluginManager. If you were extending and overriding that method, you will need to update your signature.
    • #36 updates the Zend\Config\Factory::getWriterPluginManager() method to lazy-load a StandaloneWriterPluginManager by default, instead of a WriterPluginManager, allowing usage out-of-the-box without requiring zend-servicemanager.
    • #36 updates the Zend\Config\Factory::setWriterPluginManager() method to typehint against Psr\Container\ContainerInterface instead of WriterPluginManager. If you were extending and overriding that method, you will need to update your signature.

    Deprecated

    • Nothing.

    Removed

    • #36 removes usage of zend-json as a JSON de/serializer in the JSON writer and reader; the component now requires ext/json is installed to use these features.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • release-2.6.0(Feb 4, 2016)

    Added

    • #6 adds the ability for the PhpArray writer to optionally translate strings that evaluate to known classes to ClassName::class syntax; the feature works for both keys and values.
    • #21 adds revised documentation, and publishes it to https://zendframework.github.io/zend-config/

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #8, #18, and #20 update the code base to make it forwards-compatible with the v3.0 versions of zend-stdlib and zend-servicemanager. Primarily, this involved:
      • Updating the AbstractConfigFactory to implement the new methods in the v3 AbstractFactoryInterface definition, and updating the v2 methods to proxy to those.
      • Updating ReaderPluginManager and WriterPluginManager to follow the changes to AbstractPluginManager. In particular, instead of defining invokables, they now define a combination of aliases and factories (using the new InvokableFactory); additionally, they each now implement both validatePlugin() from v2 and validate() from v3.
      • Pinning to stable versions of already updated components.
      • Selectively omitting zend-i18n-reliant tests when testing against zend-servicemanager v3.
    Source code(tar.gz)
    Source code(zip)
Owner
Zend Framework
Zend Framework
SurfShark Shadowsocks/Clash Config Generator

Instructions This script was written to build a proxy list of Surfshark service servers. Change Host2Ip for bypass censorship To work with the script,

Alireza Ahmand 18 Sep 26, 2022
Simple yet expressive schema-based configuration library for PHP apps

league/config helps you define nested configuration arrays with strict schemas and access configuration values with dot notation.

The League of Extraordinary Packages 282 Jan 6, 2023
LOAD is a PHP library for configuration loading to APCu

LOAD LOAD is a PHP library for configuration loading to APCu Sources Available sources for configuration loading are: PHP file Consul Environment vari

Beat Labs 4 Jan 18, 2022
A better YAML configuration file management virion for PocketMine-MP 4

BetterConfig WARNING: This virion is under development and haven't been tested. Do not use this virion unless you know what you're doing. Contribution

KygekTeam International 1 Apr 30, 2022
Yaml Configuration support for CakePHP 3

implements most of the YAML 1.2 specification using Symfony Yaml Component to CakePHP 3 for parsing config files

Borhaneddine Guemidi 11 Nov 10, 2020
Map request on your DTO object with zero configuration.

Map request on your DTO object with zero configuration. Install composer require prugala/symfony-request-dto Usage Create a DTO that implements the in

Piotr Rugala 16 Dec 30, 2022
Zend\Text is a component to work on text strings from Zend Framework

zend-text Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-text. Zend\Text is a component to work on text strings. It cont

Zend Framework 31 Jan 24, 2021
provides a nested object property based user interface for accessing this configuration data within application code

laminas-config This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steeri

Laminas Project 43 Dec 26, 2022
The Salla OAuth Client library is designed to provide client applications with secure delegated access to Salla Merchant stores.

Salla Provider for OAuth 2.0 Client This package provides Salla OAuth 2.0 support for the PHP League's OAuth 2.0 Client. To use this package, it will

Salla 14 Nov 27, 2022
A wrapper around symplify/config-transformer used to update recipes and using easy coding standard for generating readable config files.

Symfony Recipes Yaml to PHP Converter This is a wrapper around the symplify/config-transformer used to convert Symfony core recipes which uses .yaml c

Alexander Schranz 3 Nov 24, 2022
A PHP MySQL database client class to simplify database access

This lightweight database class is written with PHP and uses the MySQLi extension, it uses prepared statements to properly secure your queries, no need to worry about SQL injection attacks.

Khader Handal 50 Jul 30, 2022
Login system designed by fragX to validate the user and prevent unauthorized access to confidential data.

Login_System v.0.1 Login system designed by fragX to validate the user and prevent unauthorized access to confidential data. ?? Features Sign In and S

fragX 1 Jan 28, 2022
Config is a file configuration loader that supports PHP, INI, XML, JSON, YML, Properties and serialized files and string

Config Config is a file configuration loader that supports PHP, INI, XML, JSON, YML, Properties and serialized files and strings. Requirements Config

Hassan Khan 946 Jan 1, 2023
Low code , Zero Configuration ORM that creates models, config, database and tables on the fly.

?? ARCA ORM ?? Low code , Zero Configuration ORM that creates models, config, database and tables on the fly. ?? ???? Made in India ???? Complete docu

Scrawler Labs 28 Dec 18, 2022
Icinga Director has been designed to make Icinga 2 configuration handling easy

The Director aims to be your new favourite Icinga config deployment tool. Director is designed for those who want to automate their configuration deployment and those who want to grant their “point & click” users easy access to the configuration.

Icinga 395 Jan 3, 2023
18Laravel ReactJS Package to simplify sending data from Laravel back-end to front-end built to Facebook ReactJS.

Laravel ReactJS This is a package that we wrote to use on our Laravel applications that use React from Facebook. Our goal is deal with the SEO problem

Cohros 28 Feb 10, 2022
This project uses dflydev/dot-access-data to provide simple output filtering for cli applications.

FilterViaDotAccessData This project uses dflydev/dot-access-data to provide simple output filtering for applications built with annotated-command / Ro

Consolidation 44 Jul 19, 2022
zend-memory manages data in an environment with limited memory

Memory objects (memory containers) are generated by the memory manager, and transparently swapped/loaded when required.

Zend Framework 16 Aug 29, 2020
Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:

Latest Salt Documentation Open an issue (bug report, feature request, etc.) Salt is the world’s fastest, most intelligent and scalable automation engi

SaltStack 13k Jan 8, 2023
ATK Data - Data Access Framework for high-latency databases (Cloud SQL/NoSQL).

ATK Data - Data Model Abstraction for Agile Toolkit Agile Toolkit is a Low Code framework written in PHP. Agile UI implement server side rendering eng

Agile Toolkit 257 Dec 29, 2022