Skip to content

Commit

Permalink
Adding Dumpable trait
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewatts committed Mar 8, 2024
1 parent f19a944 commit 1b4c26e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,30 @@ $container
->unless(fn($container) => $container->has('Logger'), LoggerServiceFactory($container));
```

### Dumpable

Adds `dump` and `dd` methods to any class

```php
class Collection
{
use Dumpable;

public function __constructor(
protected array $collection = []
) {}
}

$collection = new Collection([
// data...
]);

// Debug the collection...
$collection->dump();
// Or
$collection->dd();
```

## Pipeline Support class

Pipelines allow for a middleware-like interface to chain processing of tasks.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"require": {
"php": "^8.1",
"psr/http-factory": "^1.0"
"psr/http-factory": "^1.0",
"symfony/var-dumper": "^6.4"
},
"require-dev": {
"slim/slim": "^4.0",
Expand Down
32 changes: 32 additions & 0 deletions src/Support/Traits/Dumpable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace SlimFacades\Support\Traits;

trait Dumpable
{
/**
* Dump the given arguments and terminate execution.
*
* @param mixed ...$args
* @return never
*/
public function dd(...$args)
{
$this->dump(...$args);

dd();
}

/**
* Dump the given arguments.
*
* @param mixed ...$args
* @return $this
*/
public function dump(...$args)
{
dump($this, ...$args);

return $this;
}
}

0 comments on commit 1b4c26e

Please sign in to comment.