{"id":14985711,"url":"https://github.com/mordilion/configurable","last_synced_at":"2025-04-11T22:05:59.075Z","repository":{"id":57019795,"uuid":"84345201","full_name":"mordilion/Configurable","owner":"mordilion","description":"A small library to make each class configurable and to use stored configs to configure your objects.","archived":false,"fork":false,"pushed_at":"2018-11-19T13:48:40.000Z","size":105,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T22:05:54.522Z","etag":null,"topics":["configurable","configuration","configurator","ini","json","php","yaml"],"latest_commit_sha":null,"homepage":"http://www.devjunkie.de","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mordilion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-08T16:59:03.000Z","updated_at":"2020-11-10T02:10:26.000Z","dependencies_parsed_at":"2022-08-22T11:30:51.914Z","dependency_job_id":null,"html_url":"https://github.com/mordilion/Configurable","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mordilion%2FConfigurable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mordilion%2FConfigurable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mordilion%2FConfigurable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mordilion%2FConfigurable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mordilion","download_url":"https://codeload.github.com/mordilion/Configurable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487715,"owners_count":21112191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configurable","configuration","configurator","ini","json","php","yaml"],"created_at":"2024-09-24T14:11:31.557Z","updated_at":"2025-04-11T22:05:59.034Z","avatar_url":"https://github.com/mordilion.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Travis](https://img.shields.io/travis/mordilion/Configurable.svg?branch=master)](https://travis-ci.org/mordilion/Configurable)\n[![Packagist](https://img.shields.io/packagist/dt/mordilion/configurable.svg)](https://packagist.org/packages/mordilion/configurable)\n\n# Configurable\n\n## Description\n\nConfigurable is a small library to make each class configurable with different kinds of configuration objects. Internaly does it create an own type of configuration object to make it more reusable.\n\n## Requirements for YAML support\n\nTo use that package with YAML you have to have at least one of the following libraries in your installation.\n\nSymfony YAML-Component https://github.com/symfony/yaml\n\nSpyc (Simple-PHP-YAML-Class) https://github.com/mustangostang/spyc\n\nPECL YAML http://php.net/manual/en/book.yaml.php\n\n## Basic Example\n\n```php\n\u003c?php\n\nuse Mordilion\\Configurable\\Configurable;\nuse Mordilion\\Configurable\\Configuration\\Configuration;\n\nclass Something\n{\n    /**\n     * Use the following traits.\n     */\n    use Configurable;\n    \n    \n    /**\n     * Default configuration settings.\n     *\n     * @var array\n     */\n    private $defaults = array(\n        'setting1' =\u003e 'http://www.devjunkie.de',\n        'setting2' =\u003e null,\n        'setting3' =\u003e 12345\n    );\n    \n    /**\n     * A public property.\n     *\n     * @var integer\n     */\n    public $setting3;\n    \n    /**\n     * Constructor.\n     *\n     * The provided $configuration will configure the object.\n     *\n     * @param mixed $configuration\n     *\n     * @return void\n     */\n    public function __construct($configuration = null)\n    {\n        $this-\u003edefaults['setting2'] = new \\DateTime('now', new \\DateTimeZone('America/Chicago'));\n        \n        $this-\u003esetConfiguration(new Configuration($this-\u003edefaults));\n        \n        if ($configuration != null) {\n            $this-\u003eaddConfiguration(new Configuration($configuration));\n        }\n    }\n    \n    /**\n     * Sets the value for setting1.\n     *\n     * @param string $value\n     *\n     * @return Something\n     */\n    public function setSetting1($value)\n    {\n        $this-\u003econfiguration-\u003eset('setting1', $value);\n        \n        return $this;\n    }\n    \n    /**\n     * Sets the value for setting2.\n     *\n     * @param \\DateTime $value\n     *\n     * @return Something\n     */\n    public function setSetting2(\\DateTime $value)\n    {\n        $this-\u003econfiguration-\u003eset('setting2', $value); // or $this-\u003econfiguration-\u003esetting2 = $value;\n        \n        return $this;\n    }\n}\n```\n\n## Routing Example\n\nUse __get and __set to route through the object directly to the configuration.\n\n```php\n\u003c?php\n\nuse Mordilion\\Configurable\\Configurable;\n\nclass Something\n{\n    /**\n     * Use the following traits.\n     */\n    use Configurable;\n\n    /**\n     * A public property.\n     *\n     * @var mixed\n     */\n    public $property1;\n\n\n    /**\n     * Routing requests directly to the configuration if needed.\n     *\n     * @param string $name\n     *\n     * @return mixed\n     */\n    public function __get($name)\n    {\n        if (property_exists($this, $name) || isset($this-\u003e$name)) {\n            return $this-\u003e$name;\n        } else if (isset($this-\u003econfiguration-\u003e$name)) {\n            return $this-\u003econfiguration-\u003e$name;\n        }\n\n        return null;\n    }\n\n    /**\n     * Routing requests directly to the configuration if needed.\n     * \n     * @param string $name\n     * @param mixed $value\n     *\n     * @return void\n     */\n    public function __set($name, $value)\n    {\n        if (property_exists($this, $name) || isset($this-\u003e$name)) {\n            $this-\u003e$name = $value;\n        } else if (isset($this-\u003econfiguration-\u003e$name)) {\n            $this-\u003econfiguration-\u003e$name = $value;\n        }\n    }\n}\n\n// { ... }\n\n$object = new Something();\n$obejct-\u003esetConfiguration(array('property1' =\u003e 'some text', 'property2' =\u003e 'some other text')); // simple use\necho $object-\u003eproperty1 . ' -- ' . $object-\u003eproperty2; // =\u003e \"some text -- some other text\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmordilion%2Fconfigurable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmordilion%2Fconfigurable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmordilion%2Fconfigurable/lists"}