mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-18 10:18:41 +00:00
phpstan and phpcs fixes
This commit is contained in:
parent
3593546966
commit
01ba242489
|
|
@ -10,7 +10,7 @@
|
|||
"icon": null,
|
||||
"order": 20,
|
||||
"from": "Media",
|
||||
"permission": { "permission": 2, "type": null, "element": null },
|
||||
"permission": { "permission": 2, "category": null, "element": null },
|
||||
"parent": 1006901001,
|
||||
"children": [
|
||||
]
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
"icon": null,
|
||||
"order": 3,
|
||||
"from": "Media",
|
||||
"permission": { "permission": 2, "type": null, "element": null },
|
||||
"permission": { "permission": 2, "category": null, "element": null },
|
||||
"parent": 1000301001,
|
||||
"children": []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,8 +141,8 @@ final class ApiController extends Controller
|
|||
* @param string $password File password. The password to protect the file (only database)
|
||||
* @param string $encryptionKey Encryption key. Used to encrypt the file on the local file storage.
|
||||
* @param int $pathSettings Settings which describe where the file should be uploaded to (physically)
|
||||
* RANDOM_PATH = random location in the base path
|
||||
* FILE_PATH = combination of base path and virtual path
|
||||
* - RANDOM_PATH = random location in the base path
|
||||
* - FILE_PATH = combination of base path and virtual path
|
||||
* @param bool $hasAccountRelation The uploaded files should be related to an account
|
||||
*
|
||||
* @return Media[]
|
||||
|
|
@ -254,7 +254,8 @@ final class ApiController extends Controller
|
|||
* @param int $account Uploader
|
||||
* @param string $virtualPath Virtual path (not on the hard-drive)
|
||||
* @param null|int $type Media type (internal categorization)
|
||||
* @param ApplicationAbstract $app Should create relation to uploader
|
||||
* @param string $ip Ip of the origin
|
||||
* @param null|ApplicationAbstract $app Should create relation to uploader
|
||||
*
|
||||
* @return Media
|
||||
*
|
||||
|
|
@ -280,8 +281,8 @@ final class ApiController extends Controller
|
|||
$media->size = $status['size'];
|
||||
$media->createdBy = new NullAccount($account);
|
||||
$media->extension = $status['extension'];
|
||||
$media->setVirtualPath($virtualPath);
|
||||
$media->type = $type === null ? null : new NullMediaType($type);
|
||||
$media->setVirtualPath($virtualPath);
|
||||
|
||||
if (\is_file($media->getAbsolutePath())) {
|
||||
$content = self::loadFileContent($media->getAbsolutePath(), $media->extension);
|
||||
|
|
@ -315,12 +316,21 @@ final class ApiController extends Controller
|
|||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the text content of a file
|
||||
*
|
||||
* @param string $path Path of the file
|
||||
* @param string $extension File extension
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function loadFileContent(string $path, string $extension) : string
|
||||
{
|
||||
switch ($extension) {
|
||||
case 'pdf':
|
||||
return PdfParser::pdf2text($path);
|
||||
break;
|
||||
case 'doc':
|
||||
case 'docx':
|
||||
Autoloader::addPath(__DIR__ . '/../../../Resources/');
|
||||
|
|
@ -330,11 +340,10 @@ final class ApiController extends Controller
|
|||
|
||||
$writer = new HTML($doc);
|
||||
return $writer->getContent();
|
||||
break;
|
||||
case 'txt':
|
||||
case 'md':
|
||||
return \file_get_contents($path);
|
||||
break;
|
||||
$contents = \file_get_contents($path);
|
||||
return $contents === false ? '' : $contents;
|
||||
default:
|
||||
return '';
|
||||
};
|
||||
|
|
@ -566,7 +575,20 @@ final class ApiController extends Controller
|
|||
return $mediaCollection;
|
||||
}
|
||||
|
||||
public function createRecursiveMediaCollection(string $basePath, string $path, int $account, string $physicalPath = '') : Collection
|
||||
/**
|
||||
* Create a collection recursively
|
||||
*
|
||||
* The function also creates all parent collections if they don't exist
|
||||
*
|
||||
* @param string $path Virtual path of the collection
|
||||
* @param int $account Account who creates this collection
|
||||
* @param int $physicalPath The physical path where the corresponding directory should be created
|
||||
*
|
||||
* @return Collection
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function createRecursiveMediaCollection(string $path, int $account, string $physicalPath = '') : Collection
|
||||
{
|
||||
$status = false;
|
||||
if (!empty($physicalPath)) {
|
||||
|
|
@ -578,11 +600,10 @@ final class ApiController extends Controller
|
|||
$tempPaths = $paths;
|
||||
$length = \count($paths);
|
||||
|
||||
$temp = '';
|
||||
|
||||
/** @var Collection $parentCollection */
|
||||
$parentCollection = null;
|
||||
|
||||
$temp = '';
|
||||
for ($i = $length; $i > 0; --$i) {
|
||||
$temp = '/' . \implode('/', $tempPaths);
|
||||
|
||||
|
|
@ -713,9 +734,9 @@ final class ApiController extends Controller
|
|||
|
||||
$media->name = $name[0];
|
||||
$media->extension = $name[1] ?? '';
|
||||
$media->isAbsolute = false;
|
||||
$media->setVirtualPath(\dirname($path));
|
||||
$media->setPath('/' . \ltrim($path, '\\/'));
|
||||
$media->isAbsolute = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -913,7 +934,7 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return EditorDoc
|
||||
* @return MediaType
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
@ -991,10 +1012,10 @@ final class ApiController extends Controller
|
|||
{
|
||||
$l11nMediaType = new MediaTypeL11n();
|
||||
$l11nMediaType->type = (int) ($request->getData('type') ?? 0);
|
||||
$l11nMediaType->title = (string) ($request->getData('title') ?? '');
|
||||
$l11nMediaType->setLanguage((string) (
|
||||
$request->getData('language') ?? $request->getLanguage()
|
||||
));
|
||||
$l11nMediaType->title = (string) ($request->getData('title') ?? '');
|
||||
|
||||
return $l11nMediaType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,14 +154,15 @@ final class BackendController extends Controller
|
|||
|
||||
foreach ($glob as $file) {
|
||||
$basename = \basename($file);
|
||||
if ($basename[0] === '_' && \strlen($basename) === 5) {
|
||||
$realpath = \realpath($file);
|
||||
if (($basename[0] === '_' && \strlen($basename) === 5) || $realpath === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($media as $obj) {
|
||||
if ($obj->name === $basename
|
||||
|| $obj->name . '.' . $obj->extension === $basename
|
||||
|| ($obj->getPath() !== '' && StringUtils::endsWith(\realpath($file), $obj->getPath()))
|
||||
|| ($obj->getPath() !== '' && StringUtils::endsWith($realpath, $obj->getPath()))
|
||||
) {
|
||||
continue 2;
|
||||
}
|
||||
|
|
@ -172,11 +173,11 @@ final class BackendController extends Controller
|
|||
$localMedia = new Media();
|
||||
$localMedia->name = $pathinfo['basename'];
|
||||
$localMedia->extension = \is_dir($file) ? 'collection' : $pathinfo['extension'] ?? '';
|
||||
$localMedia->setVirtualPath($path);
|
||||
$localMedia->createdBy = new Account();
|
||||
$localMedia->class = $localMedia->extension === 'collection'
|
||||
? MediaClass::SYSTEM_DIRECTORY
|
||||
: MediaClass::SYSTEM_FILE;
|
||||
$localMedia->setVirtualPath($path);
|
||||
|
||||
$unIndexedFiles[] = $localMedia;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,6 +311,8 @@ class Media implements \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the media path
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -320,6 +322,13 @@ class Media implements \JsonSerializable
|
|||
return $this->isAbsolute ? $this->path : \ltrim($this->path, '\\/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute media path
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getAbsolutePath() : string
|
||||
{
|
||||
return $this->isAbsolute ? $this->path : __DIR__ . '/../../../' . \ltrim($this->path, '\\/');
|
||||
|
|
|
|||
|
|
@ -45,5 +45,4 @@ abstract class MediaClass extends Enum
|
|||
public const SYSTEM_FILE = 3;
|
||||
|
||||
public const SYSTEM_DIRECTORY = 4;
|
||||
|
||||
}
|
||||
|
|
@ -39,5 +39,4 @@ abstract class MediaStatus extends Enum
|
|||
public const HIDDEN = 2;
|
||||
|
||||
public const DELETED = 3;
|
||||
|
||||
}
|
||||
|
|
@ -39,106 +39,4 @@ class Reference extends Media
|
|||
* @since 1.0.0
|
||||
*/
|
||||
public int $class = MediaClass::REFERENCE;
|
||||
|
||||
/**
|
||||
* Set sources.
|
||||
*
|
||||
* @param array $sources Source array
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setSources(array $sources) : void
|
||||
{
|
||||
$this->sources = $sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sources.
|
||||
*
|
||||
* @param Media $source Source
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addSource(Media $source) : void
|
||||
{
|
||||
$this->sources[] = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sources.
|
||||
*
|
||||
* @return Media[]
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getSources() : array
|
||||
{
|
||||
return $this->sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get media element by its name.
|
||||
*
|
||||
* @param string $name Name of the media element
|
||||
*
|
||||
* @return Media
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getSourceByName(string $name) : Media
|
||||
{
|
||||
foreach ($this->sources as $source) {
|
||||
if ($source->name === $name) {
|
||||
return $source;
|
||||
}
|
||||
}
|
||||
|
||||
return new NullMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rewind() : void
|
||||
{
|
||||
\reset($this->sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function current() : Media
|
||||
{
|
||||
$current = \current($this->sources);
|
||||
|
||||
return $current === false ? $this : $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function key() : ?int
|
||||
{
|
||||
return \key($this->sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function next() : void
|
||||
{
|
||||
\next($this->sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function valid() : bool
|
||||
{
|
||||
return \current($this->sources) !== false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user