Skip to content

Commit

Permalink
Add option to pass an array to map()
Browse files Browse the repository at this point in the history
  • Loading branch information
rickselby committed May 6, 2017
1 parent efb3ce7 commit fd9665c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ public function register()

This will work exactly how the laravel-auto-presenter works; any `User` models passed to a view will be wrapped in `UserPresenter`.

If you wish to declare a mapping on-the-fly, or override a 'default' mapping in a specific instance,
The `map` function also takes an array:

```php
public function register()
{
\Presenters::map([
User::class => UserPresenter::class,
...
]);
}
```

If you wish to declare a mapping on-the-fly, or override a mapping in a specific instance,
the facade can be called from anywhere:

```php
Expand Down
11 changes: 9 additions & 2 deletions src/AutoPresenterMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ public function __construct()
* @param $class
* @param $presenter
*/
public function map($class, $presenter)
public function map($class, $presenter = null)
{
$this->mappings->put($class, $presenter);
if (is_array($class))
{
foreach($class AS $model => $present) {
$this->mappings->put($model, $present);
}
} else {
$this->mappings->put($class, $presenter);
}
}

/**
Expand Down

0 comments on commit fd9665c

Please sign in to comment.