-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Wilson
committed
Aug 22, 2016
1 parent
59f25fc
commit f3f4424
Showing
3 changed files
with
61 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Composing Your Own Data Manager | ||
If you have your own container objects and want to add Manager functionality to them, you may import traits into your class. | ||
This is also a great way to mix and match exactly which feature you want. | ||
|
||
The basic trait you always need to start with is `Michaels\Manager\ManagesItemsTrait`. | ||
There is an accompanying interface. | ||
|
||
After that, you may add any of the feature traits you like. | ||
It's important to note, however, that all of these feature traits depend on `ManagesItemsTrait`, | ||
so you must include that one FIRST: | ||
|
||
```php | ||
use ManagesItemsTrait, ArrayableTrait, CollectionTrait; | ||
``` | ||
|
||
None of the traits include a constructor. If you want to have your class be initializable with data: | ||
|
||
```php | ||
class MyClass | ||
{ | ||
use ManagesItemsTrait; | ||
|
||
public function __construct($beginningItems) | ||
{ | ||
$this->initManager($beginningItems); | ||
} | ||
} | ||
``` | ||
initManager() is used so it doesn't conflict with user-defined init() methods. | ||
|
||
|
||
## Available Traits | ||
1. [`ManagesItemsTrait`](#getting-started) fulfills `ManagesItemsInterface` and adds most functionality. Look at the interface for full list. | ||
2. [`ArrayableTrait`](arrayable.md) makes the class usable as an array (`$manager['some']['data']`) or in loops and such | ||
3. [`ChainsNestedItemsTrait`](chains.md) allows you to use fluent properties to manage data (`$manager->one()->two()->three = 'three`) | ||
4. [`CollectionTrait`](collections.md) returns collections with all sorts of [array helpers](https://github.com/bocharsky-bw/Arrayzy) | ||
5. [`ManagesIocTrait`](ioc.md) turns Manager into a simple, but complete IoC or Dependency Injection manager | ||
6. [`LoadsFilesTrait`](load-files.md) allows Manager to load data from config files. | ||
|
||
```php | ||
/* An example for UberManager */ | ||
class MyContainer { | ||
use Michaels\Manager\Traits\ManagesItemsTrait; | ||
use Michaels\Manager\Traits\ChainsNestedItemsTrait; | ||
use Michaels\Manager\Traits\ArrayableTrait; | ||
use Michaels\Manager\Traits\CollectionTrait; | ||
use Michaels\Manager\Traits\LoadsFilesTrait; | ||
use Michaels\Manager\Traits\ManagesIocTrait; | ||
|
||
// Your stuff here. And you may override anything you like. | ||
// Remember to add a constructor if you want :) | ||
} | ||
``` | ||
|
||
You may also use the **tests** under `tests/traits` to test your integrated functionality. You may have to grab these through cloning the repo. composer usually won't include tests in your `require` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters