From a239b1988ade5ba820b66bef07b2921e15a5c2a2 Mon Sep 17 00:00:00 2001 From: Luke Watts Date: Fri, 8 Mar 2024 13:09:51 +0000 Subject: [PATCH] Adding Dumpable trait --- README.md | 24 +++++++++++++++++++++++ composer.json | 3 ++- tests/Support/Traits/Dumpable.php | 32 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/Support/Traits/Dumpable.php diff --git a/README.md b/README.md index a4cc5b9..17e676c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/composer.json b/composer.json index 4d51c4b..f32fb86 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/tests/Support/Traits/Dumpable.php b/tests/Support/Traits/Dumpable.php new file mode 100644 index 0000000..9d08def --- /dev/null +++ b/tests/Support/Traits/Dumpable.php @@ -0,0 +1,32 @@ +dump(...$args); + + dd(); + } + + /** + * Dump the given arguments. + * + * @param mixed ...$args + * @return $this + */ + public function dump(...$args) + { + dump($this, ...$args); + + return $this; + } +}