From 0323472f117e3d6a6bf58f28dbd022d8d2c95661 Mon Sep 17 00:00:00 2001 From: edalzell <erin@thedalzells.org> Date: Wed, 20 Jan 2021 16:11:18 -0800 Subject: [PATCH 1/4] add `ray` modifier --- src/Modifiers/CoreModifiers.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index 8c88173181..37b840a3e2 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -1496,6 +1496,17 @@ public function rawurlencode($value) return implode('/', array_map('rawurlencode', explode('/', $value))); } + /** + * Send data to Laravel Ray. + * + * @param $value + * @return void + */ + public function ray($value) + { + ray($value); + } + /** * Estimate the read time based on a given number of words per minute. * From 902d69a812a5a47b105226119af10d42c90be681 Mon Sep 17 00:00:00 2001 From: edalzell <erin@thedalzells.org> Date: Wed, 20 Jan 2021 18:26:01 -0800 Subject: [PATCH 2/4] return `$value` so we can keep chaining --- src/Modifiers/CoreModifiers.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index 37b840a3e2..9394ab5890 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -1504,7 +1504,9 @@ public function rawurlencode($value) */ public function ray($value) { - ray($value); + return tap($value, function ($value) { + ray($value); + }); } /** From 3b3ceab3eaa2537e485520611a4559e3397f599e Mon Sep 17 00:00:00 2001 From: edalzell <erin@thedalzells.org> Date: Wed, 20 Jan 2021 18:40:12 -0800 Subject: [PATCH 3/4] =?UTF-8?q?use=20the=20Laravel=20class=20to=20get=20a?= =?UTF-8?q?=20better=20error=20message=20if=20Ray=20isn=E2=80=99t=20instal?= =?UTF-8?q?led?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Modifiers/CoreModifiers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index 9394ab5890..e5638f9529 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -1505,7 +1505,7 @@ public function rawurlencode($value) public function ray($value) { return tap($value, function ($value) { - ray($value); + app(\Spatie\LaravelRay\Ray::class)->send($value); }); } From 1e3a533ec0ba6f58d42dc510ee8a57989c2679e3 Mon Sep 17 00:00:00 2001 From: Jason Varga <jason@pixelfear.com> Date: Mon, 25 Jan 2021 10:02:47 -0500 Subject: [PATCH 4/4] Simplify and add exception --- src/Modifiers/CoreModifiers.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index e5638f9529..99fc417f5e 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -1504,9 +1504,11 @@ public function rawurlencode($value) */ public function ray($value) { - return tap($value, function ($value) { - app(\Spatie\LaravelRay\Ray::class)->send($value); - }); + throw_unless(function_exists('ray'), new \Exception('Ray is not installed. Run `composer require spatie/laravel-ray --dev`')); + + ray($value); + + return $value; } /**