Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Adds Dumpable concern #47122

Merged
merged 26 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Illuminate/Collections/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ public function dd(...$args);
/**
* Dump the collection.
*
* @param mixed ...$args
* @return $this
*/
public function dump();
public function dump(...$args);

/**
* Get the items that are not present in the given items.
Expand Down
25 changes: 4 additions & 21 deletions src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Illuminate\Support\Enumerable;
use Illuminate\Support\HigherOrderCollectionProxy;
use JsonSerializable;
use Symfony\Component\VarDumper\VarDumper;
use Traversable;
use UnexpectedValueException;
use UnitEnum;
Expand Down Expand Up @@ -53,7 +52,7 @@
*/
trait EnumeratesValues
{
use Conditionable;
use Conditionable, Dumpable;

/**
* Indicates that the object's string representation should be escaped when __toString is invoked.
Expand Down Expand Up @@ -195,31 +194,15 @@ public function some($key, $operator = null, $value = null)
return $this->contains(...func_get_args());
}

/**
* Dump the items and end the script.
*
* @param mixed ...$args
* @return never
*/
public function dd(...$args)
{
$this->dump(...$args);

exit(1);
}

/**
* Dump the items.
*
* @param mixed ...$args
* @return $this
*/
public function dump()
public function dump(...$args)
{
(new Collection(func_get_args()))
->push($this->all())
->each(function ($item) {
VarDumper::dump($item);
});
dump($this->all(), ...$args);

return $this;
}
Expand Down
22 changes: 9 additions & 13 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Dumpable;
use Illuminate\Support\Traits\ForwardsCalls;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
Expand All @@ -29,7 +30,7 @@

class Builder implements BuilderContract
{
use BuildsQueries, ExplainsQueries, ForwardsCalls, Macroable {
use BuildsQueries, Dumpable, ExplainsQueries, ForwardsCalls, Macroable {
__call as macroCall;
}

Expand Down Expand Up @@ -3871,25 +3872,20 @@ public function cloneWithoutBindings(array $except)
/**
* Dump the current SQL and bindings.
*
* @param mixed ...$args
* @return $this
*/
public function dump()
public function dump(...$args)
{
dump($this->toSql(), $this->getBindings());
dump(
$this->toSql(),
$this->getBindings(),
...$args,
);

return $this;
}

/**
* Die and dump the current SQL and bindings.
*
* @return never
*/
public function dd()
{
dd($this->toSql(), $this->getBindings());
}

/**
* Handle dynamic method calls into the method.
*
Expand Down
19 changes: 4 additions & 15 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Traits\Dumpable;
use SplFileInfo;
use stdClass;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\VarDumper\VarDumper;

trait InteractsWithInput
{
use Dumpable;

/**
* Retrieve a server variable from the request.
*
Expand Down Expand Up @@ -606,19 +608,6 @@ protected function retrieveItem($source, $key, $default)
return $this->$source->get($key, $default);
}

/**
* Dump the request items and end the script.
*
* @param mixed ...$keys
* @return never
*/
public function dd(...$keys)
{
$this->dump(...$keys);

exit(1);
}

/**
* Dump the items.
*
Expand All @@ -629,7 +618,7 @@ public function dump($keys = [])
{
$keys = is_array($keys) ? $keys : func_get_args();

VarDumper::dump(count($keys) > 0 ? $this->only($keys) : $this->all());
dump(count($keys) > 0 ? $this->only($keys) : $this->all());

return $this;
}
Expand Down
26 changes: 2 additions & 24 deletions src/Illuminate/Support/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
use Carbon\Carbon as BaseCarbon;
use Carbon\CarbonImmutable as BaseCarbonImmutable;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Dumpable;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Uid\Ulid;

class Carbon extends BaseCarbon
{
use Conditionable;
use Conditionable, Dumpable;

/**
* {@inheritdoc}
Expand All @@ -33,27 +34,4 @@ public static function createFromId($id)
? static::createFromInterface(Ulid::fromString($id)->getDateTime())
: static::createFromInterface(Uuid::fromString($id)->getDateTime());
}

/**
* Dump the instance and end the script.
*
* @param mixed ...$args
* @return never
*/
public function dd(...$args)
{
dd($this, ...$args);
}

/**
* Dump the instance.
*
* @return $this
*/
public function dump()
{
dump($this);

return $this;
}
}
21 changes: 5 additions & 16 deletions src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
use Closure;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Dumpable;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Traits\Tappable;
use JsonSerializable;
use Symfony\Component\VarDumper\VarDumper;

class Stringable implements JsonSerializable, ArrayAccess
{
use Conditionable, Macroable, Tappable;
use Conditionable, Dumpable, Macroable, Tappable;

/**
* The underlying string value.
Expand Down Expand Up @@ -1128,27 +1128,16 @@ public function toHtmlString()
/**
* Dump the string.
*
* @param mixed ...$args
* @return $this
*/
public function dump()
public function dump(...$args)
{
VarDumper::dump($this->value);
dump($this->value, ...$args);

return $this;
}

/**
* Dump the string and end the script.
*
* @return never
*/
public function dd()
{
$this->dump();

exit(1);
}

/**
* Get the underlying string value.
*
Expand Down
32 changes: 32 additions & 0 deletions src/Illuminate/Support/Traits/Dumpable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Illuminate\Support\Traits;

trait Dumpable
{
/**
* Dump the instance and end the script.
*
* @param mixed ...$args
* @return never
*/
public function dd(...$args)
{
$this->dump(...$args);

dd();
}
Comment on lines +13 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function dd(...$args)
{
$this->dump(...$args);
dd();
}
public function dd(...$args)
{
dd(...$args);
}


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

return $this;
}
}
15 changes: 4 additions & 11 deletions src/Illuminate/Testing/Fluent/Concerns/Debugging.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace Illuminate\Testing\Fluent\Concerns;

use Illuminate\Support\Traits\Dumpable;

trait Debugging
{
use Dumpable;

/**
* Dumps the given props.
*
Expand All @@ -17,17 +21,6 @@ public function dump(string $prop = null): self
return $this;
}

/**
* Dumps the given props and exits.
*
* @param string|null $prop
* @return never
*/
public function dd(string $prop = null): void
{
dd($this->prop($prop));
}

/**
* Retrieve a prop within the current scope using "dot" notation.
*
Expand Down
15 changes: 2 additions & 13 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Dumpable;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Traits\Tappable;
use Illuminate\Support\ViewErrorBag;
Expand All @@ -32,7 +33,7 @@
*/
class TestResponse implements ArrayAccess
{
use Concerns\AssertsStatusCodes, Tappable, Macroable {
use Concerns\AssertsStatusCodes, Dumpable, Tappable, Macroable {
__call as macroCall;
}

Expand Down Expand Up @@ -1423,18 +1424,6 @@ protected function session()
return $session;
}

/**
* Dump the content from the response and end the script.
*
* @return never
*/
public function dd()
{
$this->dump();

exit(1);
}

/**
* Dump the headers from the response and end the script.
*
Expand Down