mirror of
https://github.com/flextype/flextype.git
synced 2025-08-09 14:46:53 +02:00
refactor(media): code formating and refactoring
This commit is contained in:
@@ -9,16 +9,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace Flextype\Foundation\Media;
|
||||
|
||||
use ErrorException;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use RuntimeException;
|
||||
use Slim\Http\Environment;
|
||||
use Slim\Http\Uri;
|
||||
|
||||
|
||||
use function basename;
|
||||
use function chmod;
|
||||
use function exif_read_data;
|
||||
use function explode;
|
||||
use function filesystem;
|
||||
use function flextype;
|
||||
use function getimagesize;
|
||||
use function in_array;
|
||||
use function is_dir;
|
||||
@@ -29,7 +31,6 @@ use function mime_content_type;
|
||||
use function move_uploaded_file;
|
||||
use function pathinfo;
|
||||
use function realpath;
|
||||
use function rename;
|
||||
use function str_replace;
|
||||
use function strpos;
|
||||
use function strrpos;
|
||||
@@ -260,7 +261,6 @@ class MediaFiles
|
||||
$result = [];
|
||||
|
||||
foreach (filesystem()->find()->files()->in(flextype('media_folders_meta')->getDirectoryMetaLocation($path)) as $file) {
|
||||
|
||||
$basename = $file->getBasename('.' . $file->getExtension());
|
||||
|
||||
$result[$basename] = flextype('yaml')->decode(filesystem()->file($file->getPathname())->get());
|
||||
@@ -377,7 +377,7 @@ class MediaFiles
|
||||
try {
|
||||
// Get the width and height from the uploaded image
|
||||
[$width, $height] = getimagesize($file['tmp_name']);
|
||||
} catch (\ErrorException $e) {
|
||||
} catch (ErrorException $e) {
|
||||
// Ignore read errors
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Flextype\Foundation\Media;
|
||||
|
||||
use Atomastic\Arrays\Arrays;
|
||||
use function arrays;
|
||||
use function filesystem;
|
||||
use function flextype;
|
||||
|
||||
class MediaFilesMeta
|
||||
{
|
||||
|
@@ -12,7 +12,8 @@ namespace Flextype\Foundation\Media;
|
||||
use Slim\Http\Environment;
|
||||
use Slim\Http\Uri;
|
||||
|
||||
use function rename;
|
||||
use function filesystem;
|
||||
use function flextype;
|
||||
use function str_replace;
|
||||
|
||||
class MediaFolders
|
||||
@@ -91,8 +92,10 @@ class MediaFolders
|
||||
*/
|
||||
public function create(string $id): bool
|
||||
{
|
||||
if (! filesystem()->directory($this->getDirectoryLocation($id))->exists() &&
|
||||
! filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->exists()) {
|
||||
if (
|
||||
! filesystem()->directory($this->getDirectoryLocation($id))->exists() &&
|
||||
! filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->exists()
|
||||
) {
|
||||
return filesystem()->directory($this->getDirectoryLocation($id))->create() &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->create();
|
||||
}
|
||||
@@ -112,8 +115,10 @@ class MediaFolders
|
||||
*/
|
||||
public function move(string $id, string $new_id): bool
|
||||
{
|
||||
if ((filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)) {
|
||||
if (
|
||||
(filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)
|
||||
) {
|
||||
return filesystem()->directory($this->getDirectoryLocation($id))->move($this->getDirectoryLocation($new_id)) &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->move(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id));
|
||||
}
|
||||
@@ -133,14 +138,17 @@ class MediaFolders
|
||||
*/
|
||||
public function copy(string $id, string $new_id): bool
|
||||
{
|
||||
if ((filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)) {
|
||||
if (
|
||||
(filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)
|
||||
) {
|
||||
filesystem()
|
||||
->directory($this->getDirectoryLocation($id))
|
||||
->copy($this->getDirectoryLocation($new_id));
|
||||
filesystem()
|
||||
->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))
|
||||
->copy(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id));
|
||||
|
||||
return filesystem()->directory($this->getDirectoryLocation($new_id))->exists() &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists();
|
||||
}
|
||||
|
Reference in New Issue
Block a user