From 8f97446cb6f2fed3bd665365a9126df533c68d88 Mon Sep 17 00:00:00 2001 From: Julia Lange <44929138+juliawarnke@users.noreply.github.com> Date: Tue, 27 Feb 2024 10:48:24 +0100 Subject: [PATCH 1/3] Provide getAsset method --- src/Picturesque.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Picturesque.php b/src/Picturesque.php index f9adfd2..963d9c0 100644 --- a/src/Picturesque.php +++ b/src/Picturesque.php @@ -48,6 +48,11 @@ public function __construct(Asset|string $asset, ?Context $tagContext = null) $this->setupGlide($tagContext); } + public function getAsset(): Asset + { + return $this->asset; + } + public function alt(string $text): self { $this->options->put('alt', $text); From 6b7f41c843e0c1854cab9bd2ac85f02d040b006f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schwei=C3=9Finger?= Date: Fri, 1 Mar 2024 17:29:10 +0100 Subject: [PATCH 2/3] chore: move getAsset to alphabetical order --- src/Picturesque.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Picturesque.php b/src/Picturesque.php index 963d9c0..d5726ba 100644 --- a/src/Picturesque.php +++ b/src/Picturesque.php @@ -47,11 +47,6 @@ public function __construct(Asset|string $asset, ?Context $tagContext = null) $this->setupGlide($tagContext); } - - public function getAsset(): Asset - { - return $this->asset; - } public function alt(string $text): self { @@ -140,6 +135,11 @@ public function generate(): self return $this; } + + public function getAsset(): Asset + { + return $this->asset; + } public function html(): string { From 3e7e0baa45b85c2b193dfd414befd1f8e1351891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schwei=C3=9Finger?= Date: Fri, 1 Mar 2024 17:29:58 +0100 Subject: [PATCH 3/3] feat: use getAsset function instead of using class var directly --- src/Picturesque.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Picturesque.php b/src/Picturesque.php index d5726ba..1954897 100644 --- a/src/Picturesque.php +++ b/src/Picturesque.php @@ -181,7 +181,7 @@ public function html(): string public function isGlideSupportedFiletype(): bool|null { - if (! $this->asset) { + if (! $this->getAsset()) { return null; } @@ -245,7 +245,7 @@ private function calcRatio(string $ratio): float|string private function evaluateFiletype(): string { - $meta = $this->asset->meta(); + $meta = $this->getAsset()->meta(); if (! $meta || ! array_key_exists('mime_type', $meta) || @@ -286,7 +286,7 @@ private function filetypes(): array private function makeAlt(): string { if (($alt = $this->options->get('alt')) || - ($alt = $this->asset->data()->get('alt'))) { + ($alt = $this->getAsset()->data()->get('alt'))) { $alt = strip_tags($alt); if (config('picturesque.alt_fullstop')) { @@ -329,7 +329,7 @@ private function makeImg() ]; if (! $this->isGlideSupportedFiletype()) { - $img['src'] = $this->asset->url(); + $img['src'] = $this->getAsset()->url(); } else { $img['src'] = $this->makeGlideUrl(['width' => $this->smallestSrc(), 'fit' => 'crop_focal']); } @@ -346,12 +346,12 @@ private function makeImg() } // width - if ($w = $this->asset->width()) { + if ($w = $this->getAsset()->width()) { $img['width'] = (int) round($w); } // height - if ($h = $this->asset->height()) { + if ($h = $this->getAsset()->height()) { $img['height'] = (int) round($h); } @@ -548,7 +548,7 @@ private function parseSizeData(string $sizeData, float|string $ratio = 'auto'): */ private function setupGlide(?Context $context = null) { - $this->glideSource = ['src' => $this->asset]; + $this->glideSource = ['src' => $this->getAsset()]; $this->evaluateFiletype(); if (! $context) {