Skip to content

Commit 8edbda4

Browse files
committed
feat(strings): add new methods dd and dump
1 parent 1cd73b0 commit 8edbda4

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/Strings.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,34 @@ static function (&$value) use ($encoding): void {
27412741
return $array;
27422742
}
27432743

2744+
/**
2745+
* Dumps the strings using the given function (print_r by default).
2746+
*
2747+
* @param callable $callback Function receiving the strings as parameter.
2748+
*
2749+
* @return self Returns instance of The Strings class.
2750+
*/
2751+
public function dump(?callable $callback = null): self
2752+
{
2753+
$callback ? $callback($this->strings) : print_r($this->items);
2754+
2755+
return $this;
2756+
}
2757+
2758+
/**
2759+
* Dumps the string using the given function (print_r by default) and exit(1).
2760+
*
2761+
* @param callable $callback Function receiving the strings as parameter.
2762+
*
2763+
* @return void Return void.
2764+
*/
2765+
public function dd(?callable $callback = null): void
2766+
{
2767+
$this->dump($callback);
2768+
2769+
exit(1);
2770+
}
2771+
27442772
/**
27452773
* Returns a new ArrayIterator, thus implementing the IteratorAggregate
27462774
* interface. The ArrayIterator's constructor is passed an array of chars

0 commit comments

Comments
 (0)