From 78104e0530c930a5585bbc5250d63502b115e207 Mon Sep 17 00:00:00 2001 From: Ahrim Fakhriy Date: Mon, 31 Oct 2022 21:13:31 +0800 Subject: [PATCH 1/5] add source file to Collection's dd function output --- .../Foundation/Concerns/ResolvesDumpSource.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php index 4d60dbad8730..d0a3f4a8b722 100644 --- a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php +++ b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php @@ -56,12 +56,17 @@ public function resolveDumpSource() $sourceKey = null; foreach ($trace as $traceKey => $traceFile) { - if (isset($traceFile['file']) && str_ends_with( - $traceFile['file'], - 'dump.php' - )) { + if (! isset($traceFile['file'])) { + continue; + } + + if (str_ends_with($traceFile['file'], 'dump.php')) { $sourceKey = $traceKey + 1; + break; + } + if (str_ends_with($traceFile['file'], 'EnumeratesValues.php')) { + $sourceKey = $traceKey + 4; break; } } From 8514d02c4a29070032652ca86f099add6f6395ea Mon Sep 17 00:00:00 2001 From: Ahrim Fakhriy Date: Mon, 31 Oct 2022 22:15:48 +0800 Subject: [PATCH 2/5] turned trace name and keys into class property. --- .../Concerns/ResolvesDumpSource.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php index d0a3f4a8b722..8a0c8fecfb63 100644 --- a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php +++ b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php @@ -29,6 +29,16 @@ trait ResolvesDumpSource 'xdebug' => 'xdebug://{file}@{line}', ]; + /** + * All of the trace names and its keys.. + * + * @var array + */ + protected static $traceNames = [ + 'dump.php' => 1, + 'EnumeratesValues.php' => 4, + ]; + /** * The source resolver. * @@ -60,13 +70,14 @@ public function resolveDumpSource() continue; } - if (str_ends_with($traceFile['file'], 'dump.php')) { - $sourceKey = $traceKey + 1; - break; + foreach($this->traceNames as $name => $key) { + if (str_ends_with($traceFile['file'], $name)) { + $sourceKey = $traceKey + $key; + break; + } } - if (str_ends_with($traceFile['file'], 'EnumeratesValues.php')) { - $sourceKey = $traceKey + 4; + if (! is_null($sourceKey)) { break; } } From 0ca658b7736809fa78285728fb98b4351da6a3db Mon Sep 17 00:00:00 2001 From: Ahrim Fakhriy Date: Mon, 31 Oct 2022 22:19:06 +0800 Subject: [PATCH 3/5] styling & remove extra dot in comment --- src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php index 8a0c8fecfb63..750007a4a64c 100644 --- a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php +++ b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php @@ -30,7 +30,7 @@ trait ResolvesDumpSource ]; /** - * All of the trace names and its keys.. + * All of the trace names and its keys. * * @var array */ @@ -70,7 +70,7 @@ public function resolveDumpSource() continue; } - foreach($this->traceNames as $name => $key) { + foreach ($this->traceNames as $name => $key) { if (str_ends_with($traceFile['file'], $name)) { $sourceKey = $traceKey + $key; break; From a545d777afcae39adb5d45ec29d0079ccd3983cc Mon Sep 17 00:00:00 2001 From: Ahrim Fakhriy Date: Mon, 31 Oct 2022 22:56:02 +0800 Subject: [PATCH 4/5] made trace path strict, fixed calling static property. --- .../Foundation/Concerns/ResolvesDumpSource.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php index 750007a4a64c..53065103ba69 100644 --- a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php +++ b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php @@ -35,8 +35,8 @@ trait ResolvesDumpSource * @var array */ protected static $traceNames = [ - 'dump.php' => 1, - 'EnumeratesValues.php' => 4, + 'symfony/var-dumper/Resources/functions/dump.php' => 1, + 'Illuminate/Collection/Traits/EnumeratesValues.php' => 4, ]; /** @@ -70,8 +70,11 @@ public function resolveDumpSource() continue; } - foreach ($this->traceNames as $name => $key) { - if (str_ends_with($traceFile['file'], $name)) { + foreach (self::$traceNames as $name => $key) { + if (str_ends_with( + $traceFile['file'], + str_replace('/', DIRECTORY_SEPARATOR, $name) + )) { $sourceKey = $traceKey + $key; break; } From 5b517e850feeff4a9b43a107c0200a50c5bafabd Mon Sep 17 00:00:00 2001 From: Ahrim Date: Mon, 31 Oct 2022 15:18:41 +0800 Subject: [PATCH 5/5] typo in path --- src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php index 53065103ba69..59a1eebfbbdd 100644 --- a/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php +++ b/src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php @@ -36,7 +36,7 @@ trait ResolvesDumpSource */ protected static $traceNames = [ 'symfony/var-dumper/Resources/functions/dump.php' => 1, - 'Illuminate/Collection/Traits/EnumeratesValues.php' => 4, + 'Illuminate/Collections/Traits/EnumeratesValues.php' => 4, ]; /**