1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-09 06:36:52 +02:00

feat(core): Hide access for all core properties #467

This commit is contained in:
Awilum
2020-09-10 22:34:42 +03:00
parent 1a2a1e254f
commit 92b5975b05
11 changed files with 60 additions and 42 deletions

View File

@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace Flextype\Foundation\Entries;
use Flextype\Component\Filesystem\Filesystem;
use Flextype\Component\Arrays\Arrays;
use function array_merge;
use function collect_filter;
@@ -34,6 +35,16 @@ class Entries
*/
public $storage = [];
public function getStorage(string $key)
{
return Arrays::get($this->storage, $key);
}
public function setStorage(string $key, $value)
{
Arrays::set($this->storage, $key, $value);
}
/**
* Fetch entry(entries)
*

View File

@@ -8,19 +8,20 @@ declare(strict_types=1);
*/
use Flextype\Component\Filesystem\Filesystem;
use Flextype\Component\Strings\Strings;
if (flextype('registry')->get('flextype.settings.entries.fields.created_at.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
flextype('entries')->storage['fetch_single']['data']['created_at'] = isset(flextype('entries')->storage['fetch_single']['data']['created_at']) ?
(int) strtotime(flextype('entries')->storage['fetch_single']['data']['created_at']) :
(int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->storage['fetch_single']['id']));
if (flextype('entries')->getStorage('fetch_single.data.created_at') == null) {
flextype('entries')->setStorage('fetch_single.data.created_at', (int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->getStorage('fetch_single.id'))));
} else {
flextype('entries')->setStorage('fetch_single.data.created_at', (int) strtotime(flextype('entries')->getStorage('fetch_single.data.created_at')));
}
});
flextype('emitter')->addListener('onEntryCreate', static function (): void {
if (isset(flextype('entries')->storage['create']['data']['created_at'])) {
flextype('entries')->storage['create']['data']['created_at'] = flextype('entries')->storage['create']['data']['created_at'];
} else {
flextype('entries')->storage['create']['data']['created_at'] = date(flextype('registry')->get('flextype.settings.date_format'), time());
if (flextype('entries')->getStorage('create.data.created_at') == null) {
flextype('entries')->setStorage('create.data.created_at', date(flextype('registry')->get('flextype.settings.date_format'), time()));
}
});
}

View File

@@ -9,10 +9,8 @@ declare(strict_types=1);
if (flextype('registry')->get('flextype.settings.entries.fields.created_by.enabled')) {
flextype('emitter')->addListener('onEntryCreate', static function (): void {
if (isset(flextype('entries')->storage['create']['data']['created_by'])) {
flextype('entries')->storage['create']['data']['created_by'] = flextype('entries')->storage['create']['data']['created_by'];
} else {
flextype('entries')->storage['create']['data']['created_by'] = '';
if (flextype('entries')->getStorage('create.data.created_by') == null) {
flextype('entries')->setStorage('create.data.created_by', '');
}
});
}

View File

@@ -7,8 +7,12 @@ declare(strict_types=1);
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
use Flextype\Component\Strings\Strings;
if (flextype('registry')->get('flextype.settings.entries.fields.id.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
flextype('entries')->storage['fetch_single']['data']['id'] = isset(flextype('entries')->storage['fetch_single']['data']['id']) ? (string) flextype('entries')->storage['fetch_single']['data']['id'] : (string) ltrim(rtrim(flextype('entries')->storage['fetch_single']['id'], '/'), '/');
if (flextype('entries')->getStorage('fetch_single.data.id') == null) {
flextype('entries')->setStorage('fetch_single.data.id', (string) Strings::trimSlashes(flextype('entries')->getStorage('fetch_single.id')));
}
});
}

View File

@@ -11,6 +11,8 @@ use Flextype\Component\Filesystem\Filesystem;
if (flextype('registry')->get('flextype.settings.entries.fields.modified_at.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
flextype('entries')->storage['fetch_single']['data']['modified_at'] = (int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->storage['fetch_single']['id']));
if (flextype('entries')->getStorage('fetch_single.data.modified_at') == null) {
flextype('entries')->setStorage('fetch_single.data.modified_at', (int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->getStorage('fetch_single.id'))));
}
});
}

View File

@@ -11,16 +11,16 @@ use Flextype\Component\Filesystem\Filesystem;
if (flextype('registry')->get('flextype.settings.entries.fields.published_at.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
flextype('entries')->storage['fetch_single']['data']['published_at'] = isset(flextype('entries')->storage['fetch_single']['data']['published_at']) ?
(int) strtotime(flextype('entries')->storage['fetch_single']['data']['published_at']) :
(int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->storage['fetch_single']['id']));
if (flextype('entries')->getStorage('fetch_single.data.published_at') == null) {
flextype('entries')->setStorage('fetch_single.data.published_at', (int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->getStorage('fetch_single.id'))));
} else {
flextype('entries')->setStorage('fetch_single.data.published_at', (int) strtotime(flextype('entries')->getStorage('fetch_single.data.published_at')));
}
});
flextype('emitter')->addListener('onEntryCreate', static function (): void {
if (isset(flextype('entries')->storage['create']['data']['published_at'])) {
flextype('entries')->storage['create']['data']['published_at'] = flextype('entries')->storage['create']['data']['published_at'];
} else {
flextype('entries')->storage['create']['data']['published_at'] = date(flextype('registry')->get('flextype.settings.date_format'), time());
if (flextype('entries')->getStorage('create.data.published_at') == null) {
flextype('entries')->setStorage('create.data.published_at', date(flextype('registry')->get('flextype.settings.date_format'), time()));
}
});
}

View File

@@ -9,10 +9,8 @@ declare(strict_types=1);
if (flextype('registry')->get('flextype.settings.entries.fields.published_by.enabled')) {
flextype('emitter')->addListener('onEntryCreate', static function (): void {
if (isset(flextype('entries')->storage['create']['data']['published_by'])) {
flextype('entries')->storage['create']['data']['published_by'] = flextype('entries')->storage['create']['data']['published_by'];
} else {
flextype('entries')->storage['create']['data']['published_by'] = '';
if (flextype('entries')->getStorage('create.data.published_by') == null) {
flextype('entries')->setStorage('create.data.published_by', '');
}
});
}

View File

@@ -10,16 +10,18 @@ declare(strict_types=1);
if (flextype('registry')->get('flextype.settings.entries.fields.routable.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
flextype('entries')->storage['fetch_single']['data']['routable'] = isset(flextype('entries')->storage['fetch_single']['data']['routable']) ?
(bool) flextype('entries')->storage['fetch_single']['data']['routable'] :
true;
if (flextype('entries')->getStorage('fetch_single.data.routable') == null) {
flextype('entries')->setStorage('fetch_single.data.routable', true);
} else {
flextype('entries')->setStorage('fetch_single.data.routable', (bool) flextype('entries')->getStorage('create.data.routable'));
}
});
flextype('emitter')->addListener('onEntryCreate', static function (): void {
if (isset(flextype('entries')->storage['create']['data']['routable']) && is_bool(flextype('entries')->storage['create']['data']['routable'])) {
flextype('entries')->storage['create']['data']['routable'] = flextype('entries')->storage['create']['data']['routable'];
if (flextype('entries')->getStorage('create.data.routable') != null && is_bool(flextype('entries')->getStorage('create.data.routable'))) {
flextype('entries')->setStorage('create.data.routable', (bool) flextype('entries')->getStorage('create.data.routable'));
} else {
flextype('entries')->storage['create']['data']['routable'] = true;
flextype('entries')->setStorage('create.data.routable', true);
}
});
}

View File

@@ -7,9 +7,13 @@ declare(strict_types=1);
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
use Flextype\Component\Strings\Strings;
if (flextype('registry')->get('flextype.settings.entries.fields.slug.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
$parts = explode('/', ltrim(rtrim(flextype('entries')->storage['fetch_single']['id'], '/'), '/'));
flextype('entries')->storage['fetch_single']['data']['slug'] = isset(flextype('entries')->storage['fetch_single']['data']['slug']) ? (string) flextype('entries')->storage['fetch_single']['data']['slug'] : (string) end($parts);
if (flextype('entries')->getStorage('fetch_single.data.slug') == null) {
$parts = Strings::segments(Strings::trimSlashes(flextype('entries')->getStorage('fetch_single.id')), '/');
flextype('entries')->setStorage('fetch_single.data.slug', (string) end($parts));
}
});
}

View File

@@ -11,10 +11,8 @@ use Ramsey\Uuid\Uuid;
if (flextype('registry')->get('flextype.settings.entries.fields.uuid.enabled')) {
flextype('emitter')->addListener('onEntryCreate', static function (): void {
if (isset(flextype('entries')->storage['create']['data']['uuid'])) {
flextype('entries')->storage['create']['data']['uuid'] = flextype('entries')->storage['create']['data']['uuid'];
} else {
flextype('entries')->storage['create']['data']['uuid'] = Uuid::uuid4()->toString();
if (flextype('entries')->getStorage('create.data.uuid') == null) {
flextype('entries')->setStorage('create.data.uuid', Uuid::uuid4()->toString());
}
});
}

View File

@@ -15,18 +15,18 @@ if (flextype('registry')->get('flextype.settings.entries.fields.visibility.enabl
];
flextype('emitter')->addListener('onEntryAfterInitialized', static function () use ($visibility): void {
if (isset(flextype('entries')->storage['fetch_single']['data']['visibility']) && in_array(flextype('entries')->storage['fetch_single']['data']['visibility'], $visibility)) {
flextype('entries')->storage['fetch_single']['data']['visibility'] = (string) $visibility[flextype('entries')->storage['fetch_single']['data']['visibility']];
if (flextype('entries')->getStorage('fetch_single.data.visibility') != null && in_array(flextype('entries')->getStorage('fetch_single.data.visibility'), $visibility)) {
flextype('entries')->setStorage('fetch_single.data.visibility', (string) $visibility[flextype('entries')->getStorage('fetch_single.data.visibility')]);
} else {
flextype('entries')->storage['fetch_single']['data']['visibility'] = (string) $visibility['visible'];
flextype('entries')->setStorage('fetch_single.data.visibility', (string) $visibility['visible']);
}
});
flextype('emitter')->addListener('onEntryCreate', static function () use ($visibility): void {
if (isset(flextype('entries')->storage['create']['data']['visibility']) && in_array(flextype('entries')->storage['create']['data']['visibility'], $visibility)) {
flextype('entries')->storage['create']['data']['visibility'] = flextype('entries')->storage['create']['data']['visibility'];
if (flextype('entries')->getStorage('create.data.visibility') != null && in_array(flextype('entries')->getStorage('create.data.visibility'), $visibility)) {
flextype('entries')->setStorage('create.data.visibility', (string) $visibility[flextype('entries')->getStorage('create.data.visibility')]);
} else {
flextype('entries')->storage['create']['data']['visibility'] = 'visible';
flextype('entries')->setStorage('create.data.visibility', (string) $visibility['visible']);
}
});
}