@@ -8,7 +8,7 @@ A container class for settings objects - decouple configuration logic from your
88[ ![ license] [ license-badge ]] [ license ]
99[ ![ Continuous Integration] [ gh-action-badge ]] [ gh-action ]
1010[ ![ Coverage] [ coverage-badge ]] [ coverage ]
11- [ ![ Scrunitizer ] [ scrutinizer -badge]] [ scrutinizer ]
11+ [ ![ Codacy ] [ codacy -badge]] [ codacy ]
1212[ ![ Packagist downloads] [ downloads-badge ]] [ downloads ]
1313
1414[ php-badge ] : https://img.shields.io/packagist/php-v/chillerlan/php-settings-container?logo=php&color=8892BF
@@ -19,12 +19,12 @@ A container class for settings objects - decouple configuration logic from your
1919[ license ] : https://github.com/chillerlan/php-settings-container/blob/main/LICENSE
2020[ coverage-badge ] : https://img.shields.io/codecov/c/github/chillerlan/php-settings-container.svg?logo=codecov
2121[ coverage ] : https://codecov.io/github/chillerlan/php-settings-container
22- [ scrutinizer -badge] : https://img.shields.io/scrutinizer/g/chillerlan/php-settings-container.svg ?logo=scrutinizer
23- [ scrutinizer ] : https://scrutinizer-ci. com/g /chillerlan/php-settings-container
22+ [ codacy -badge] : https://img.shields.io/codacy/grade/612a380f27c54fc1851b380896af2a92/main ?logo=codacy
23+ [ codacy ] : https://www.codacy. com/gh /chillerlan/php-settings-container/dashboard?branch=main
2424[ downloads-badge ] : https://img.shields.io/packagist/dt/chillerlan/php-settings-container.svg?logo=packagist
2525[ downloads ] : https://packagist.org/packages/chillerlan/php-settings-container/stats
26- [ gh-action-badge ] : https://img.shields.io/github/actions/workflow/status/chillerlan/php-settings-container/tests .yml?branch=main&logo=github
27- [ gh-action ] : https://github.com/chillerlan/php-settings-container/actions/workflows/tests .yml?query=branch%3Amain
26+ [ gh-action-badge ] : https://img.shields.io/github/actions/workflow/status/chillerlan/php-settings-container/ci .yml?branch=main&logo=github
27+ [ gh-action ] : https://github.com/chillerlan/php-settings-container/actions/workflows/ci .yml?query=branch%3Amain
2828
2929## Documentation
3030
@@ -45,7 +45,7 @@ Profit!
4545
4646## Usage
4747
48- The ` SettingsContainerInterface ` (wrapped in` SettingsContainerAbstract ` ) provides plug-in functionality for immutable object properties and adds some fancy, like loading/saving JSON, arrays etc.
48+ The ` SettingsContainerInterface ` (wrapped in` SettingsContainerAbstract ` ) provides plug-in functionality for immutable object properties and adds some fancy, like loading/saving JSON, arrays etc.
4949It takes an ` iterable ` as the only constructor argument and calls a method with the trait's name on invocation (` MyTrait::MyTrait() ` ) for each used trait.
5050
5151### Simple usage
@@ -62,7 +62,7 @@ $container = new MyContainer;
6262$container->foo = 'what';
6363$container->bar = 'foo';
6464
65- // which is equivalent to
65+ // which is equivalent to
6666$container = new MyContainer(['bar' => 'foo', 'foo' => 'what']);
6767// ...or try
6868$container->fromJSON('{"foo": "what", "bar": "foo"}');
@@ -87,23 +87,23 @@ var_dump($container->nope); // -> null
8787trait SomeOptions{
8888 protected string $foo;
8989 protected string $what;
90-
90+
9191 // this method will be called in SettingsContainerAbstract::construct()
9292 // after the properties have been set
9393 protected function SomeOptions():void{
9494 // just some constructor stuff...
9595 $this->foo = strtoupper($this->foo);
9696 }
97-
97+
9898 /*
9999 * special prefixed magic setters & getters
100100 */
101-
101+
102102 // this method will be called from __set() when property $what is set
103103 protected function set_what(string $value):void{
104104 $this->what = md5($value);
105105 }
106-
106+
107107 // this method is called on __get() for the property $what
108108 protected function get_what():string{
109109 return 'hash: '.$this->what;
@@ -119,12 +119,12 @@ trait MoreOptions{
119119``` php
120120$commonOptions = [
121121 // SomeOptions
122- 'foo' => 'whatever',
122+ 'foo' => 'whatever',
123123 // MoreOptions
124124 'bar' => 'nothing',
125125];
126126
127- // now plug the several library options together to a single object
127+ // now plug the several library options together to a single object
128128$container = new class ($commonOptions) extends SettingsContainerAbstract{
129129 use SomeOptions, MoreOptions;
130130};
@@ -140,20 +140,20 @@ var_dump($container->what); // -> hash: 5946210c9e93ae37891dfe96c3e39614 (custom
140140
141141#### [ ` SettingsContainerAbstract ` ] ( https://github.com/chillerlan/php-settings-container/blob/main/src/SettingsContainerAbstract.php )
142142
143- method | return | info
144- -------- | ---- | -----------
145- ` __construct(iterable $properties = null) ` | - | calls ` construct() ` internally after the properties have been set
146- (protected) ` construct() ` | void | calls a method with trait name as replacement constructor for each used trait
147- ` __get(string $property) ` | mixed | calls ` $this->{'get_'.$property}() ` if such a method exists
148- ` __set(string $property, $value) ` | void | calls ` $this->{'set_'.$property}($value) ` if such a method exists
149- ` __isset(string $property) ` | bool |
150- ` __unset(string $property) ` | void |
151- ` __toString() ` | string | a JSON string
152- ` toArray() ` | array |
153- ` fromIterable(iterable $properties) ` | ` SettingsContainerInterface ` |
154- ` toJSON(int $jsonOptions = null) ` | string | accepts [ JSON options constants] ( http://php.net/manual/json.constants.php )
155- ` fromJSON(string $json) ` | ` SettingsContainerInterface ` |
156- ` jsonSerialize() ` | mixed | implements the [ ` JsonSerializable ` ] ( https://www.php.net/manual/en/jsonserializable.jsonserialize.php ) interface
143+ | method | return | info |
144+ | -------------------------------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------- |
145+ | ` __construct(iterable $properties = null) ` | - | calls ` construct() ` internally after the properties have been set |
146+ | (protected) ` construct() ` | void | calls a method with trait name as replacement constructor for each used trait |
147+ | ` __get(string $property) ` | mixed | calls ` $this->{'get_'.$property}() ` if such a method exists |
148+ | ` __set(string $property, $value) ` | void | calls ` $this->{'set_'.$property}($value) ` if such a method exists |
149+ | ` __isset(string $property) ` | bool | |
150+ | ` __unset(string $property) ` | void | |
151+ | ` __toString() ` | string | a JSON string |
152+ | ` toArray() ` | array | |
153+ | ` fromIterable(iterable $properties) ` | ` SettingsContainerInterface ` | |
154+ | ` toJSON(int $jsonOptions = null) ` | string | accepts [ JSON options constants] ( http://php.net/manual/json.constants.php ) |
155+ | ` fromJSON(string $json) ` | ` SettingsContainerInterface ` | |
156+ | ` jsonSerialize() ` | mixed | implements the [ ` JsonSerializable ` ] ( https://www.php.net/manual/en/jsonserializable.jsonserialize.php ) interface |
157157
158158## Disclaimer
159159This might be either an utterly genius or completely stupid idea - you decide. However, i like it and it works.
0 commit comments