Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
:octocat:
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Aug 8, 2018
1 parent 9c7454d commit 40d38a7
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions README.md
Expand Up @@ -27,7 +27,7 @@ A collection of (more or less) useful traits for PHP7+

## Features
- `ClassLoader` - invokes objects of a given class and interface/type with an arbitrary count of constructor arguments
- `Container` - provides immutable properties with magic getter & setter and some fancy, implements `ContainerInterface`
- `ImmutableSettingsContainer` - provides immutable properties with magic getter & setter and some fancy, implements `ImmutableSettingsInterface`
- `Magic` - turns methods into magic properties
- `Enumerable` - provides some of [prototype's enumerable methods](http://api.prototypejs.org/language/Enumerable/), implements `EnumerableInterface`
- `Env` - loads contents from a `.env` file into the environment (similar to [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv))
Expand Down Expand Up @@ -124,13 +124,18 @@ class MyClass{
```


#### `Container`
#### `ImmutableSettingsContainer`

The `ImmutableSettingsContainer` trait (wrapped in`ImmutableSettingsAbstract` ) provides plug-in functionality for immutable object variables and adds some fancy, like loading/saving JSON, arrays etc.
It takes an array (planned: iterable) as the only constructor argument and calls a method (`MyTrait::MyTrait()`) for each trait on invocation.

##### Simple usage
```php
class MyContainer implements ContainerInterface{
use Container;
class MyContainer extends ImmutableSettingsAbstract{

protected $foo;
protected $bar;

}
```

Expand All @@ -157,6 +162,35 @@ $container->nope = 'what';
var_dump($container->nope); // -> null
```

##### Advanced usage
```php
trait SomeOptions{
protected $foo;

// this method will be called in ImmutableSettingsAbstract::__construct() after the properties have been set
protected function SomeOptions(){
// just some constructor stuff...
$this->foo = strtoupper($this->foo);
}
}

trait MoreOptions{
protected $bar;
}
```

```php
$commonOptions = [
// SomeOptions
'foo' => 'whatever',
// MoreOptions
'bar' => 'nothing',
];

$container = new class ($commonOptions) extends ImmutableSettingsAbstract{
use SomeOptions, MoreOptions;
};
```

#### `Magic`
`Magic` allows to access internal methods like as properties.
Expand Down

0 comments on commit 40d38a7

Please sign in to comment.