Use global namespace+minor fixes

This commit is contained in:
Dennis Eichhorn 2019-02-04 22:29:55 +01:00
parent 818acf1a59
commit 22464e86d7
8 changed files with 77 additions and 29 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -16,7 +16,12 @@ namespace Modules\Media\Models;
final class CollectionMapper extends MediaMapper
{
{ /**
* Has many relation.
*
* @var array<string, array<string, string>>
* @since 1.0.0
*/
protected static $hasMany = [
'sources' => [
'mapper' => MediaMapper::class, /* mapper of the related object */

View File

@ -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,

View File

@ -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<string, array<string, string>>
* @since 1.0.0
*/
protected static $belongsTo = [
'createdBy' => [
'mapper' => AccountMapper::class,

View File

@ -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.

View File

@ -61,7 +61,7 @@ echo $this->getData('nav')->render();
<td><?= $this->getHtml('Created') ?>
<tbody>
<?php
if (!is_dir($media->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();
<?php endforeach; else : $path = $this->dirPathFunction($media, $this->request->getData('sub') ?? ''); ?>
<?php $list = \phpOMS\System\File\Local\Directory::list($path);
foreach ($list as $key => $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'));
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><i class="fa fa-<?= $this->printHtml($icon); ?>"></i></a>
<td><a href="<?= $url; ?>"><?= substr($value, strlen($media->getPath())); ?></a>
<td><a href="<?= $url; ?>"><?= \substr($value, \strlen($media->getPath())); ?></a>
<td><a href="<?= $url; ?>"><?= !\is_dir($value) ? File::extension($value) : 'collection'; ?></a>
<td><a href="<?= $url; ?>"><?= !\is_dir($value) ? File::size($value) : ''; ?></a>
<td><a href="<?= $url; ?>"><?= File::owner($value); ?></a>

View File

@ -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))
);
}