From e8b3124a274a8b883c8ef91460993f27e54466a4 Mon Sep 17 00:00:00 2001 From: 3m1n3nc3 Date: Mon, 29 Jul 2024 23:34:52 +0100 Subject: [PATCH] Explicitly pass null to the request helper --- src/Initiator.php | 14 +++++++------- src/Media.php | 4 ++-- src/Traits/Fileable.php | 24 +++++++++++++----------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Initiator.php b/src/Initiator.php index 8cea0ef..54f82c0 100644 --- a/src/Initiator.php +++ b/src/Initiator.php @@ -16,18 +16,18 @@ class Initiator public static function collectionPaths(): array|Collection { $deepPaths = collect(config('toneflix-fileable.collections', []))->map(function ($col, $key) { - $getPath = Arr::get(config('toneflix-fileable.collections', []), $key.'.path'); + $getPath = Arr::get(config('toneflix-fileable.collections', []), $key . '.path'); $prefix = str($key)->contains('private') ? '/' : '/public/'; - if (! isset($col['path'])) { + if (!isset($col['path'])) { return collect($col)->filter(fn ($k) => isset($k['path']))->map(function ($k, $path) use ($key, $prefix) { - $getPath = Arr::get(config('toneflix-fileable.collections', []), $key.'.'.$path.'.path'); + $getPath = Arr::get(config('toneflix-fileable.collections', []), $key . '.' . $path . '.path'); - return Storage::path($prefix.$getPath); + return Storage::path($prefix . $getPath); })->values(); } - return Storage::path($prefix.$getPath); + return Storage::path($prefix . $getPath); }); return $deepPaths->flatten()->unique(); @@ -39,10 +39,10 @@ public static function collectionPaths(): array|Collection public static function asset(string $url, $absolute = false): string { if ($absolute) { - return str($url)->replace('http:', request()->isSecure() ? 'https:' : 'http:')->toString(); + return str($url)->replace('http:', request(null)->isSecure() ? 'https:' : 'http:')->toString(); } - return request()->isSecure() + return request(null)->isSecure() ? secure_asset($url) : asset($url); } diff --git a/src/Media.php b/src/Media.php index bc2cc2e..9cb4c82 100644 --- a/src/Media.php +++ b/src/Media.php @@ -75,7 +75,7 @@ public function getMedia(string $type, ?string $src = null, $returnPath = false, return parse_url($src, PHP_URL_PATH); } - return Initiator::asset($url->replace('localhost', request()->getHttpHost()), true); + return Initiator::asset($url->replace('localhost', request(null)->getHttpHost()), true); } if (!$src || !$this->disk->exists($prefix . $getPath . $src)) { @@ -199,7 +199,7 @@ public function save(string $type, ?string $file_name = null, ?string $old = nul // Get the file path prefix $prefix = !str($type)->contains('private.') ? 'public/' : '/'; - $request = request(); + $request = request(null); $old_path = $prefix . $getPath . $old; // Adds support for saving files from an array index using wildcard request access diff --git a/src/Traits/Fileable.php b/src/Traits/Fileable.php index c3ec9f3..2406680 100644 --- a/src/Traits/Fileable.php +++ b/src/Traits/Fileable.php @@ -211,12 +211,12 @@ public function responsiveImages(): Attribute $images = []; foreach ($this->file_field as $field => $collection) { $images[$field] = collect($this->sizes)->mapWithKeys(function ($size, $key) use ($field, $collection) { - $prefix = ! str($collection)->contains('private.') ? 'public/' : '/'; + $prefix = !str($collection)->contains('private.') ? 'public/' : '/'; - $isImage = str(Storage::mimeType($prefix.$this->retrieveFile($field, $collection, true))) + $isImage = str(Storage::mimeType($prefix . $this->retrieveFile($field, $collection, true))) ->contains('image'); - if (! $isImage) { + if (!$isImage) { return [$key => $this->default_image]; } @@ -229,11 +229,11 @@ public function responsiveImages(): Attribute return $images; } else { return collect($this->sizes)->mapWithKeys(function ($size, $key) { - $prefix = ! str($this->collection)->contains('private.') ? 'public/' : '/'; - $isImage = str(Storage::mimeType($prefix.$this->retrieveFile($this->file_field, $this->collection, true))) + $prefix = !str($this->collection)->contains('private.') ? 'public/' : '/'; + $isImage = str(Storage::mimeType($prefix . $this->retrieveFile($this->file_field, $this->collection, true))) ->contains('image'); - if (! $isImage) { + if (!$isImage) { return [$key => $this->default_image]; } @@ -278,7 +278,9 @@ public function getFiles(): Attribute * * @return void */ - public static function registerEvents() {} + public static function registerEvents() + { + } /** * Register all required dependencies here @@ -313,7 +315,7 @@ public function fileableLoader( $collect = Arr::get((new Media($this->disk))->namespaces, $collection); - if (! in_array($collection, array_keys((new Media($this->disk))->namespaces)) && ! $collect) { + if (!in_array($collection, array_keys((new Media($this->disk))->namespaces)) && !$collect) { throw new \ErrorException("$collection is not a valid collection"); } } @@ -325,7 +327,7 @@ public function fileableLoader( $collect = Arr::get((new Media($this->disk))->namespaces, $collection); - if (! in_array($collection, array_keys((new Media($this->disk))->namespaces)) && ! $collect) { + if (!in_array($collection, array_keys((new Media($this->disk))->namespaces)) && !$collect) { throw new \ErrorException("$collection is not a valid collection"); } $this->applyDefault = $applyDefault; @@ -341,7 +343,7 @@ public function fileableLoader( */ public function saveImage(string|array|null $file_field = null, string $collection = 'default') { - $request = request(); + $request = request(null); $file_field = $file_field ?? $this->file_field; if (is_array($file_field)) { @@ -415,7 +417,7 @@ public function removeFile(string|array|null $file_field = null, string $collect protected function getFieldName(string $file_field): string { - if (! $this->db_field) { + if (!$this->db_field) { return $file_field; }