diff --git a/Controller/ApiController.php b/Controller/ApiController.php index a097f0c..6d03fc9 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -149,7 +149,7 @@ final class ApiController extends Controller $mediaCreated = []; foreach ($status as $uFile) { - if (!is_null($created = self::createDbEntry($uFile, $account))) { + if (($created = self::createDbEntry($uFile, $account)) !== null) { $mediaCreated[] = $created; } } diff --git a/Models/Collection.php b/Models/Collection.php index f23cbfd..d24e426 100644 --- a/Models/Collection.php +++ b/Models/Collection.php @@ -33,19 +33,21 @@ class Collection extends Media implements \Iterator */ private $sources = []; + /** + * Extension name. + * + * @var string + * @since 1.0.0 + */ protected $extension = 'collection'; - protected $versioned = false; - /** - * Constructor. + * Versioned. * - * @since 1.0.0 + * @var bool + * @since 1.0.0 */ - public function __construct() - { - parent::__construct(); - } + protected $versioned = false; /** * Set sources. @@ -87,36 +89,57 @@ class Collection extends Media implements \Iterator return $this->sources; } + /** + * {@inheritdoc} + */ public function setExtension(string $extension) : void { } + /** + * {@inheritdoc} + */ public function setVersioned(bool $versioned) : void { } + /** + * {@inheritdoc} + */ public function rewind() : void { - reset($this->sources); + \reset($this->sources); } + /** + * {@inheritdoc} + */ public function current() { - return current($this->sources); + return \current($this->sources); } + /** + * {@inheritdoc} + */ public function key() { - return key($this->sources); + return \key($this->sources); } + /** + * {@inheritdoc} + */ public function next() : void { - next($this->sources); + \next($this->sources); } + /** + * {@inheritdoc} + */ public function valid() { - return current($this->sources) !== false; + return \current($this->sources) !== false; } } diff --git a/Models/CollectionMapper.php b/Models/CollectionMapper.php index dfe187b..85febac 100644 --- a/Models/CollectionMapper.php +++ b/Models/CollectionMapper.php @@ -16,7 +16,12 @@ namespace Modules\Media\Models; final class CollectionMapper extends MediaMapper -{ +{ /** + * Has many relation. + * + * @var array> + * @since 1.0.0 + */ protected static $hasMany = [ 'sources' => [ 'mapper' => MediaMapper::class, /* mapper of the related object */ diff --git a/Models/Media.php b/Models/Media.php index ba2124c..de8942f 100644 --- a/Models/Media.php +++ b/Models/Media.php @@ -141,13 +141,13 @@ class Media implements \JsonSerializable * * @since 1.0.0 */ - public function setAbsolute(bool $absolute) : void /* void */ + public function setAbsolute(bool $absolute) : void { $this->isAbsolute = $absolute; } /** - * @return mixed + * @return int|\phpOMS\Account\Account * * @since 1.0.0 */ @@ -335,7 +335,7 @@ class Media implements \JsonSerializable /** * {@inheritdoc} */ - public function toArray() + public function toArray() : array { return [ 'id' => $this->id, diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index 61fb37e..7951237 100644 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -4,7 +4,7 @@ * * PHP Version 7.2 * - * @package TBD + * @package Modules\Media\Models * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,6 +17,14 @@ namespace Modules\Media\Models; use Modules\Admin\Models\AccountMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; +/** + * Media mapper class. + * + * @package Modules\Media\Models + * @license OMS License 1.0 + * @link http://website.orange-management.de + * @since 1.0.0 + */ class MediaMapper extends DataMapperAbstract { @@ -41,6 +49,12 @@ class MediaMapper extends DataMapperAbstract 'media_created_at' => ['name' => 'media_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], ]; + /** + * Belongs to. + * + * @var array> + * @since 1.0.0 + */ protected static $belongsTo = [ 'createdBy' => [ 'mapper' => AccountMapper::class, diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 387008e..2f325c5 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -28,7 +28,13 @@ use phpOMS\System\File\Local\Directory; */ class UploadFile { - public const PATH_GENERATION_LIMIT = 1000; + /** + * Limit of iterations to find a possible random path for the file to upload to. + * + * @var int + * @since 1.0.0 + */ + private const PATH_GENERATION_LIMIT = 1000; /** * Image interlaced. diff --git a/Theme/Backend/media-single.tpl.php b/Theme/Backend/media-single.tpl.php index 54a405f..137ce4e 100644 --- a/Theme/Backend/media-single.tpl.php +++ b/Theme/Backend/media-single.tpl.php @@ -61,7 +61,7 @@ echo $this->getData('nav')->render(); getHtml('Created') ?> isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($media->getPath(), '//')) + if (!\is_dir($media->isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($media->getPath(), '//')) || $media->getPath() === '' ) : foreach ($media as $key => $value) : @@ -78,12 +78,12 @@ echo $this->getData('nav')->render(); dirPathFunction($media, $this->request->getData('sub') ?? ''); ?> $value) : - $url = UriFactory::build('/{/lang}/backend/media/single?{?}&id=' . $media->getId() . '&sub=' . substr($value, strlen($media->getPath()))); - $icon = $this->fileIconFunction(FileUtils::getExtensionType(!is_dir($value) ? File::extension($value) : 'collection')); + $url = UriFactory::build('/{/lang}/backend/media/single?{?}&id=' . $media->getId() . '&sub=' . \substr($value, \strlen($media->getPath()))); + $icon = $this->fileIconFunction(FileUtils::getExtensionType(!\is_dir($value) ? File::extension($value) : 'collection')); ?> - getPath())); ?> + getPath())); ?> diff --git a/Views/MediaView.php b/Views/MediaView.php index 6a36ec1..dc80d69 100644 --- a/Views/MediaView.php +++ b/Views/MediaView.php @@ -36,7 +36,7 @@ class MediaView extends View { if (is_file($media->getPath() . $sub) && StringUtils::startsWith( - \str_replace('\\', '/', realpath($media->getPath() . $sub)), + \str_replace('\\', '/', \realpath($media->getPath() . $sub)), $media->getPath() ) ) { @@ -48,9 +48,9 @@ class MediaView extends View protected function dirPathFunction(Media $media, string $sub) : string { - if (is_dir($media->getPath() . $sub) + if (\is_dir($media->getPath() . $sub) && StringUtils::startsWith( - \str_replace('\\', '/', realpath($media->getPath() . $sub)), + \str_replace('\\', '/', \realpath($media->getPath() . $sub)), $media->getPath() ) ) { @@ -63,8 +63,8 @@ class MediaView extends View protected function isCollectionFunction(Media $media, string $sub) : bool { return ($media->getExtension() === 'collection' - && !is_file($media->getPath() . $sub)) - || (is_dir($media->getPath()) + && !\is_file($media->getPath() . $sub)) + || (\is_dir($media->getPath()) && ($sub === null || \is_dir($media->getPath() . $sub)) ); }