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

Dev #11

Merged
merged 2 commits into from
Jul 29, 2024
Merged

Dev #11

Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions src/Initiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion src/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
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)) {
Expand Down Expand Up @@ -198,8 +198,13 @@
// Get the file path prefix
$prefix = ! str($type)->contains('private.') ? 'public/' : '/';

<<<<<<< HEAD

Check failure on line 201 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_SL on line 201
$request = request(null);
$old_path = $prefix . $getPath . $old;
=======
$request = request();
$old_path = $prefix.$getPath.$old;
>>>>>>> c62b3c0a1678a7c043edd1ae3bec49d02cd0d6d0

// Adds support for saving files from an array index using wildcard request access
$fn = str($file_name);
Expand Down Expand Up @@ -372,7 +377,7 @@
);

// Resize the image
$resized = $this->imageDriver->read($cached['cc'])

Check failure on line 380 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting '-' or T_STRING or T_VARIABLE or T_NUM_STRING on line 380
->cover(Arr::first($res), Arr::last($res))
->encode();

Expand All @@ -380,7 +385,7 @@
$response = Response::make($resized);

// set the headers
return $response->header('Content-Type', $cached['mm'])

Check failure on line 388 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 388
->header('Cross-Origin-Resource-Policy', 'cross-origin')
->header('Access-Control-Allow-Origin', '*');
}
Expand All @@ -403,15 +408,15 @@
}

$prefix = ! str($type)->contains('private.') ? 'public/' : '/';
$file_path = $prefix.$this->getMedia($type, $src, true);

Check failure on line 411 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 411

$mime = str(Storage::exists($file_path) ? Storage::mimeType($file_path) : 'unknown/unknown');
$isImage = $mime->contains('image');

Check failure on line 414 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 414
$mediaType = $mime->beforeLast('/')->exactly('application')

Check failure on line 415 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 415
? $mime->afterLast('/')

Check failure on line 416 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 416
: $mime->beforeLast('/')->toString();

Check failure on line 417 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 417

$file_url = $this->getMedia($type, $src) ?: (new Media)->getDefaultMedia($type);

Check failure on line 419 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 419
$dynamicLink = route('fileable.open.file', Initiator::base64urlEncode($file_path));
$secureLink = route('fileable.secure.file', Initiator::base64urlEncode($file_path));

Expand All @@ -419,7 +424,7 @@
'url' => $file_url,
'ext' => str($src)->afterLast('.')->toString(),
'type' => $mediaType,
'mime' => $mime->toString(),

Check failure on line 427 in src/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 427
'size' => $mime->isNotEmpty() && Storage::exists($file_path) ? Storage::size($file_path) : 0,
'path' => $file_path,
'isImage' => $isImage,
Expand Down
24 changes: 13 additions & 11 deletions src/Traits/Fileable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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];
}

Expand Down Expand Up @@ -278,7 +278,9 @@ public function getFiles(): Attribute
*
* @return void
*/
public static function registerEvents() {}
public static function registerEvents()
{
}

/**
* Register all required dependencies here
Expand Down Expand Up @@ -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");
}
}
Expand All @@ -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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}

Expand Down
Loading