Throw exception when filename cannot be found

This commit is contained in:
philipp lang 2021-10-30 22:17:27 +02:00
parent f70bd6b032
commit 0b5edee585
3 changed files with 21 additions and 1 deletions

View File

@ -6,6 +6,7 @@ use Event;
use Generator;
use Illuminate\Support\Collection;
use Media\Classes\MediaLibrary;
use Zoomyboy\Social\Exceptions\SocialException;
use Zoomyboy\Social\Models\Page;
use Zoomyboy\Social\Models\Setting;
@ -67,6 +68,11 @@ abstract class SocialService {
public function saveUrl(string $source, ?string $filename = null): string
{
$filename = $filename ?: pathinfo(parse_url($source, PHP_URL_PATH), PATHINFO_BASENAME);
if (!pathinfo($filename, PATHINFO_FILENAME)) {
throw new SocialException('No real filename for storage given in "'.$source.'"');
}
$file = $this->page->mediaPath.$filename;
if (!$this->media->exists($file)) {

View File

@ -8,5 +8,10 @@
"name": "Philipp Lang",
"email": "philipp.lang@dpsg-koeln.de"
}
]
],
"autoload": {
"psr-4": {
"Aweos\\Social\\Exceptions\\": "./exceptions"
}
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace Zoomyboy\Social\Exceptions;
use Exception;
class SocialException extends Exception {
}