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

feat(entries): improve Entries API flash storage functionality + fields

This commit is contained in:
Awilum
2021-09-29 20:52:52 +03:00
parent a407d304b9
commit 998fdecb74
17 changed files with 302 additions and 262 deletions

View File

@@ -197,62 +197,68 @@ class Entries
*/
public function fetch(string $id, array $options = [])
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('fetch.id', $id)
->set('fetch.options', $options)
->set('fetch.result', null);
// Setup registry.
$this->registry()->set('methods.fetch', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'options' => $options,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesFetch');
// Check if `fetch.result` contains data to return.
if (! is_null($this->registry()->get('fetch.result'))) {
return $this->registry()->get('fetch.result');
// Check if `result` contains data to return.
if (! is_null($this->registry()->get('methods.fetch.result'))) {
return $this->registry()->get('methods.fetch.result');
}
// Single fetch helper
$single = function ($id, $options) {
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('fetch.id', $id)
->set('fetch.options', $options)
->set('fetch.result', null);
// Setup registry.
$this->registry()->set('methods.fetch', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'options' => $options,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesFetchSingle');
// Check if `fetch.result` contains data to return.
if (! is_null($this->registry()->get('fetch.result'))) {
return $this->registry()->get('fetch.result');
// Check if `result` contains data to return.
if (! is_null($this->registry()->get('methods.fetch.result'))) {
return $this->registry()->get('methods.fetch.result');
}
// Get Cache ID for current requested entry
$entryCacheID = $this->getCacheID($this->registry()->get('fetch.id'));
$entryCacheID = $this->getCacheID($this->registry()->get('methods.fetch.params.id'));
// 1. Try to get current requested entry from the cache.
if (cache()->has($entryCacheID)) {
// Fetch entry from cache and apply `filterCollection` filter for fetch result
$this->registry()->set('fetch.result',
$this->registry()->set('methods.fetch.result',
filterCollection(cache()->get($entryCacheID),
$this->registry()->get('fetch.options.filter', [])));
$this->registry()->get('methods.fetch.params.options.filter', [])));
// Run event
emitter()->emit('onEntriesFetchSingleCacheHasResult');
// Return result from the cache.
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methods.fetch.result'));
}
// 2. Try to get requested entry from the filesystem
if ($this->has($this->registry()->get('fetch.id'))) {
if ($this->has($this->registry()->get('methods.fetch.params.id'))) {
// Get entry file location
$entryFile = $this->getFileLocation($this->registry()->get('fetch.id'));
$entryFile = $this->getFileLocation($this->registry()->get('methods.fetch.params.id'));
// Try to get requested entry from the filesystem.
$entryFileContent = filesystem()->file($entryFile)->get(true);
@@ -260,70 +266,73 @@ class Entries
if ($entryFileContent === false) {
// Run event
emitter()->emit('onEntriesFetchSingleNoResult');
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methods.fetch.params.result'));
}
// Decode entry file content
$this->registry()->set('fetch.result', serializers()->{$this->registry()->get('collection.options')['serializer']}()->decode($entryFileContent));
$this->registry()->set('methods.fetch.result', serializers()->{$this->registry()->get('methods.fetch.collection')['serializer']}()->decode($entryFileContent));
// Run event
emitter()->emit('onEntriesFetchSingleHasResult');
// Apply `filterCollection` filter for fetch result
$this->registry()->set('fetch.result', filterCollection($this->registry()->get('fetch.result'), $this->registry()->get('fetch.options.filter', [])));
$this->registry()->set('methods.fetch.result', filterCollection($this->registry()->get('methods.fetch.result'), $this->registry()->get('methods.fetch.params.options.filter', [])));
// Set cache state
$cache = $this->registry()->get('fetch.result.cache.enabled',
$cache = $this->registry()->get('methods.fetch.result.cache.enabled',
registry()->get('flextype.settings.cache.enabled'));
// Save entry data to cache
if ($cache) {
cache()->set($entryCacheID, $this->registry()->get('fetch.result'));
cache()->set($entryCacheID, $this->registry()->get('methods.fetch.result'));
}
// Return entry fetch result
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methods.fetch.result'));
}
// Run event
emitter()->emit('onEntriesFetchSingleNoResult');
// Return entry fetch result
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methodss.fetch.result'));
};
if ($this->registry()->has('fetch.options.collection') &&
strings($this->registry()->get('fetch.options.collection'))->isTrue()) {
if ($this->registry()->has('methods.fetch.params.options.collection') &&
strings($this->registry()->get('methods.fetch.params.options.collection'))->isTrue()) {
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('fetch.id', $id)
->set('fetch.options', $options)
->set('fetch.result', null);
// Setup registry.
$this->registry()->set('methods.fetch', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'options' => $options,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesFetchCollection');
// Check if `fetch.result` contains data to return.
if (! is_null($this->registry()->get('fetch.result'))) {
return $this->registry()->get('fetch.result');
// Check if `result` contains data to return.
if (! is_null($this->registry()->get('methods.fetch.result'))) {
return $this->registry()->get('methods.fetch.result');
}
// Determine if collection exists
if (! $this->has($this->registry()->get('fetch.id'))) {
if (! $this->has($this->registry()->get('methods.fetch.params.id'))) {
// Run event
emitter()->emit('onEntriesFetchCollectionNoResult');
// Return entries array
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methods.fetch.result'));
}
// Find entries in the filesystem.
$entries = find($this->getDirectoryLocation($this->registry()->get('fetch.id')),
$this->registry()->has('fetch.options.find') ?
$this->registry()->get('fetch.options.find') :
$entries = find($this->getDirectoryLocation($this->registry()->get('methods.fetch.params.id')),
$this->registry()->has('methods.fetch.params.options.find') ?
$this->registry()->get('methods.fetch.params.options.find') :
[]);
// Walk through entries results
@@ -340,21 +349,24 @@ class Entries
->toString();
// Set collection options
$this->registry()->set('collection.options', $this->getCollectionOptions($currentEntryID));
$this->registry()->set('methods.fetch.collection', $this->getCollectionOptions($currentEntryID));
if ($currenEntry->getType() !== 'file' || $currenEntry->getFilename() !== $this->registry()->get('collection.options.filename') . '.' . $this->registry()->get('collection.options.extension')) {
if ($currenEntry->getType() !== 'file' || $currenEntry->getFilename() !== $this->registry()->get('methods.fetch.collection.filename') . '.' . $this->registry()->get('methods.fetch.collection.extension')) {
continue;
}
$data[$currentEntryID] = $single($currentEntryID, [])->toArray();
}
// Re-init data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('fetch.id', $id)
->set('fetch.options', $options)
->set('fetch.result', $data);
// Re-init registry.
$this->registry()->set('methods.fetch', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'options' => $options,
],
'result' => $data,
]);
// Run event
emitter()->emit('onEntriesFetchCollectionHasResult');
@@ -362,45 +374,45 @@ class Entries
// Process filter `only` for collection
// after process we need to unset $options['filter']['only']
// to avoid it's running inside filterCollection() helper.
if ($this->registry()->has('fetch.options.filter.only')) {
if ($this->registry()->has('methods.fetch.params.options.filter.only')) {
$data = [];
foreach ($this->registry()->get('fetch.result') as $key => $value) {
$data[$key] = arrays($value)->only($this->registry()->get('fetch.options.filter.only'))->toArray();
foreach ($this->registry()->get('methods.fetch.result') as $key => $value) {
$data[$key] = arrays($value)->only($this->registry()->get('methods.fetch.params.options.filter.only'))->toArray();
}
$this->registry()->delete('fetch.options.filter.only');
$this->registry()->set('fetch.result', $data);
$this->registry()->delete('methods.fetch.params.options.filter.only');
$this->registry()->set('methods.fetch.result', $data);
}
// Process filter `except` for collection
// after process we need to unset $options['filter']['except']
// to avoid it's running inside filterCollection() helper.
if ($this->registry()->has('fetch.options.filter.except')) {
if ($this->registry()->has('methods.fetch.params.options.filter.except')) {
$data = [];
foreach ($this->registry()->get('fetch.result') as $key => $value) {
$data[$key] = arrays($value)->except($this->registry()->get('fetch.options.filter.except'))->toArray();
foreach ($this->registry()->get('methods.fetch.result') as $key => $value) {
$data[$key] = arrays($value)->except($this->registry()->get('methods.fetch.params.options.filter.except'))->toArray();
}
$this->registry()->delete('fetch.options.filter.except');
$this->registry()->set('fetch.result', $data);
$this->registry()->delete('methods.fetch.params.options.filter.except');
$this->registry()->set('methods.fetch.result', $data);
}
// Apply filter `filterCollection` for fetch result data.
$this->registry()->set('fetch.result',
filterCollection($this->registry()->get('fetch.result'),
$this->registry()->has('fetch.options.filter') ?
$this->registry()->get('fetch.options.filter') : []));
$this->registry()->set('methods.fetch.result',
filterCollection($this->registry()->get('methods.fetch.result'),
$this->registry()->has('methods.fetch.params.options.filter') ?
$this->registry()->get('methods.fetch.params.options.filter') : []));
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methods.fetch.result'));
} else {
// Run event
emitter()->emit('onEntriesFetchCollectionNoResult');
// Return entries array
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methods.fetch.result'));
}
// Return entries array
return arrays($this->registry()->get('fetch.result'));
return arrays($this->registry()->get('methods.fetch.result'));
}
// Fetch single entry.
@@ -449,26 +461,29 @@ class Entries
return false;
}
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('move.id', $id)
->set('move.newID', $newID)
->set('move.result', null);
// Setup registry.
$this->registry()->set('methods.move', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'newID' => $newID,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesMove');
// Return result from registy `move.result` if it's value boolean.
if (! is_null($this->registry()->get('move.result')) && is_bool($this->registry()->get('move.result'))) {
return $this->registry()->get('move.result');
// Return result from registy `result` if it's value boolean.
if (! is_null($this->registry()->get('methods.move.result')) && is_bool($this->registry()->get('methods.move.result'))) {
return $this->registry()->get('methods.move.result');
}
// Do move.
if (! $this->has($this->registry()->get('move.newID'))) {
if (! $this->has($this->registry()->get('methods.move.params.newID'))) {
return filesystem()
->directory($this->getDirectoryLocation($this->registry()->get('move.id')))
->move($this->getDirectoryLocation($this->registry()->get('move.newID')));
->directory($this->getDirectoryLocation($this->registry()->get('methods.move.params.id')))
->move($this->getDirectoryLocation($this->registry()->get('methods.move.params.newID')));
}
return false;
@@ -486,28 +501,31 @@ class Entries
*/
public function update(string $id, array $data): bool
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('update.id', $id)
->set('update.data', $data)
->set('update.result', null);
// Setup registry.
$this->registry()->set('methods.update', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'data' => $data,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesUpdate');
// Return result from registy `update.result` if it's value boolean.
if (! is_null($this->registry()->get('update.result')) && is_bool($this->registry()->get('update.result'))) {
return $this->registry()->get('update.result');
// Return result from registy `result` if it's value boolean.
if (! is_null($this->registry()->get('methods.update.result')) && is_bool($this->registry()->get('methods.update.result'))) {
return $this->registry()->get('methods.update.result');
}
$entryFile = $this->getFileLocation($this->registry()->get('update.id'));
$entryFile = $this->getFileLocation($this->registry()->get('methods.update.params.id'));
if (filesystem()->file($entryFile)->exists()) {
$body = filesystem()->file($entryFile)->get(true);
$entry = serializers()->{$this->registry()->get('collection.options')['serializer']}()->decode($body);
$entry = serializers()->{$this->registry()->get('methods.update.collection')['serializer']}()->decode($body);
return (bool) filesystem()->file($entryFile)->put(serializers()->{$this->registry()->get('collection.options')['serializer']}()->encode(array_merge($entry, $this->registry()->get('update.data'))), true);
return (bool) filesystem()->file($entryFile)->put(serializers()->{$this->registry()->get('methods.update.collection')['serializer']}()->encode(array_merge($entry, $this->registry()->get('methods.update.params.data'))), true);
}
return false;
@@ -525,35 +543,39 @@ class Entries
*/
public function create(string $id, array $data = []): bool
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('create.id', $id)
->set('create.data', $data)
->set('create.result', null);
// Setup registry.
$this->registry()->set('methods.create', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'data' => $data,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesCreate');
// Return result from registy `create.result` if it's value boolean.
if (! is_null($this->registry()->get('create.result')) && is_bool($this->registry()->get('create.result'))) {
return $this->registry()->get('create.result');
// Return result from registy `result` if it's value boolean.
if (! is_null($this->registry()->get('methods.create.result')) && is_bool($this->registry()->get('methods.create.result'))) {
return $this->registry()->get('methods.create.result');
}
// Create entry directory first if it is not exists
$entryDirectory = $this->getDirectoryLocation($this->registry()->get('create.id'));
$entryDirectory = $this->getDirectoryLocation($this->registry()->get('methods.create.params.id'));
if (
! filesystem()->directory($entryDirectory)->exists() &&
! filesystem()->directory($entryDirectory)->create()
) {
if (filesystem()->directory($entryDirectory)->exists()) {
return false;
}
if (! filesystem()->directory($entryDirectory)->create()) {
return false;
}
// Create entry file
$entryFile = $entryDirectory . '/' . $this->registry()->get('collection.options.filename') . '.' . $this->registry()->get('collection.options.extension');
$entryFile = $entryDirectory . '/' . $this->registry()->get('methods.create.collection.filename') . '.' . $this->registry()->get('methods.create.collection.extension');
if (! filesystem()->file($entryFile)->exists()) {
return (bool) filesystem()->file($entryFile)->put(serializers()->{$this->registry()->get('collection.options')['serializer']}()->encode($this->registry()->get('create.data')), true);
return (bool) filesystem()->file($entryFile)->put(serializers()->{$this->registry()->get('methods.create.collection')['serializer']}()->encode($this->registry()->get('methods.create.params.data')), true);
}
return false;
@@ -570,22 +592,25 @@ class Entries
*/
public function delete(string $id): bool
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('delete.id', $id)
->set('delete.result', null);
// Setup registry.
$this->registry()->set('methods.delete', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesDelete');
// Return result from registy `delete.result` if it's value boolean.
if (! is_null($this->registry()->get('delete.result')) && is_bool($this->registry()->get('delete.result'))) {
return $this->registry()->get('delete.result');
// Return result from registy `result` if it's value boolean.
if (! is_null($this->registry()->get('methods.delete.result')) && is_bool($this->registry()->get('methods.delete.result'))) {
return $this->registry()->get('methods.delete.result');
}
return filesystem()
->directory($this->getDirectoryLocation($this->registry()->get('delete.id')))
->directory($this->getDirectoryLocation($this->registry()->get('methods.delete.params.id')))
->delete();
}
@@ -631,24 +656,27 @@ class Entries
return false;
}
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('copy.id', $id)
->set('copy.newID', $newID)
->set('copy.result', null);
// Setup registry.
$this->registry()->set('methods.copy', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
'newID' => $newID,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesCopy');
// Return result from registy `move.result` if it's value boolean.
if (! is_null($this->registry()->get('copy.result')) && is_bool($this->registry()->get('copy.result'))) {
return $this->registry()->get('copy.result');
// Return result from registy `result` if it's value boolean.
if (! is_null($this->registry()->get('methods.copy.result')) && is_bool($this->registry()->get('methods.copy.result'))) {
return $this->registry()->get('methods.copy.result');
}
return filesystem()
->directory($this->getDirectoryLocation($this->registry()->get('copy.id')))
->copy($this->getDirectoryLocation($this->registry()->get('copy.newID')));
->directory($this->getDirectoryLocation($this->registry()->get('methods.copy.params.id')))
->copy($this->getDirectoryLocation($this->registry()->get('methods.copy.params.newID')));
}
/**
@@ -662,21 +690,24 @@ class Entries
*/
public function has(string $id): bool
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('has.id', $id)
->set('has.result', null);
// Setup registry.
$this->registry()->set('methods.has', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesHas');
// Return result from registy `has.result` if it's value boolean.
if (! is_null($this->registry()->get('has.result')) && is_bool($this->registry()->get('has.result'))) {
return $this->registry()->get('has.result');
// Return result from registy `result` if it's value boolean.
if (! is_null($this->registry()->get('methods.has.result')) && is_bool($this->registry()->get('methods.has.result'))) {
return $this->registry()->get('methods.has.result');
}
return filesystem()->file($this->getFileLocation($this->registry()->get('has.id')))->exists();
return filesystem()->file($this->getFileLocation($this->registry()->get('methods.has.params.id')))->exists();
}
/**
@@ -690,21 +721,24 @@ class Entries
*/
public function getFileLocation(string $id): string
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('getFileLocation.id', $id)
->set('getFileLocation.result', null);
// Setup registry.
$this->registry()->set('methods.getFileLocation', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesGetFileLocation');
// Return result from registy `getFileLocation.result` if it's not null and it's a string.
if (! is_null($this->registry()->get('getFileLocation.result')) && is_string($this->registry()->get('getFileLocation.result'))) {
return $this->registry()->get('getFileLocation.result');
// Return result from registy `result` if it's not null and it's a string.
if (! is_null($this->registry()->get('methods.getFileLocation.result')) && is_string($this->registry()->get('methods.getFileLocation..result'))) {
return $this->registry()->get('methods.getFileLocation.result');
}
return PATH['project'] . $this->options['directory'] . '/' . $this->registry()->get('getFileLocation.id') . '/' . $this->registry()->get('collection.options.filename') . '.' . $this->registry()->get('collection.options.extension');
return PATH['project'] . $this->options['directory'] . '/' . $this->registry()->get('methods.getFileLocation.params.id') . '/' . $this->registry()->get('methods.getFileLocation.collection.filename') . '.' . $this->registry()->get('methods.getFileLocation.collection.extension');
}
/**
@@ -718,21 +752,24 @@ class Entries
*/
public function getDirectoryLocation(string $id): string
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('getDirectoryLocation.id', $id)
->set('getDirectoryLocation.result', null);
// Setup registry.
$this->registry()->set('methods.getDirectoryLocation', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesGetDirectoryLocation');
// Return result from registy `getDirectoryLocation.result` if it's not null and it's a string.
if (! is_null($this->registry()->get('getDirectoryLocation.result')) && is_string($this->registry()->get('getDirectoryLocation.result'))) {
return $this->registry()->get('getDirectoryLocation.result');
// Return result from registy `result` if it's not null and it's a string.
if (! is_null($this->registry()->get('methods.getDirectoryLocation.result')) && is_string($this->registry()->get('methods.getDirectoryLocation.result'))) {
return $this->registry()->get('methods.getDirectoryLocation.result');
}
return PATH['project'] . $this->options['directory'] . '/' . $this->registry()->get('getDirectoryLocation.id');
return PATH['project'] . $this->options['directory'] . '/' . $this->registry()->get('methods.getDirectoryLocation.params.id');
}
/**
@@ -746,25 +783,28 @@ class Entries
*/
public function getCacheID(string $id): string
{
// Set initial data.
$this->registry()
->set('collection.options', $this->getCollectionOptions($id))
->set('getCacheID.id', $id)
->set('getCacheID.result', null);
// Setup registry.
$this->registry()->set('methods.getCacheID', [
'collection' => $this->getCollectionOptions($id),
'params' => [
'id' => $id,
],
'result' => null,
]);
// Run event
emitter()->emit('onEntriesGetCacheID');
// Return result from registy `getCacheID.result` if it's not null and it's a string.
if (! is_null($this->registry()->get('getCacheID.result')) && is_string($this->registry()->get('getCacheID.result'))) {
return $this->registry()->get('getCacheID.result');
// Return result from registy `result` if it's not null and it's a string.
if (! is_null($this->registry()->get('methods.getCacheID.result')) && is_string($this->registry()->get('methods.getCacheID.result'))) {
return $this->registry()->get('methods.getCacheID.result');
}
if (registry()->get('flextype.settings.cache.enabled') === false) {
return '';
}
$entryFile = $this->getFileLocation($this->registry()->get('getCacheID.id'));
$entryFile = $this->getFileLocation($this->registry()->get('methods.getCacheID.params.id'));
if (filesystem()->file($entryFile)->exists()) {
return strings($this->options['directory'] . $entryFile . (filesystem()->file($entryFile)->lastModified() ?: ''))->hash()->toString();

View File

@@ -9,14 +9,14 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.created_at.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.created_at.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.created_at') === null) {
entries()->registry()->set('fetch.result.created_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('fetch.id')))->lastModified());
if (entries()->registry()->get('methods.fetch.result.created_at') === null) {
entries()->registry()->set('methods.fetch.result.created_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('methods.fetch.params.id')))->lastModified());
} else {
entries()->registry()->set('fetch.result.created_at', (int) strtotime((string) entries()->registry()->get('fetch.result.created_at')));
entries()->registry()->set('methods.fetch.result.created_at', (int) strtotime((string) entries()->registry()->get('methods.fetch.result.created_at')));
}
});
@@ -26,9 +26,9 @@ emitter()->addListener('onEntriesCreate', static function (): void {
return;
}
if (entries()->registry()->get('create.data.created_at') !== null) {
if (entries()->registry()->get('methods.create.params.data.created_at') !== null) {
return;
}
entries()->registry()->set('create.data.created_at', date(registry()->get('flextype.settings.date_format'), time()));
entries()->registry()->set('methods.create.params.data.created_at', date(registry()->get('flextype.settings.date_format'), time()));
});

View File

@@ -9,14 +9,14 @@ declare(strict_types=1);
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.created_by.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.created_by.enabled')) {
return;
}
if (entries()->registry()->get('create.data.created_by') !== null) {
if (entries()->registry()->get('methods.create.params.data.created_by') !== null) {
return;
}
entries()->registry()->set('create.data.created_by', '');
entries()->registry()->set('methods.create.params.data.created_by', '');
});

View File

@@ -11,17 +11,17 @@ use Atomastic\Arrays\Arrays;
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.entries.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.entries.enabled')) {
return;
}
if (entries()->registry()->has('fetch.result.entries.fetch')) {
if (entries()->registry()->has('methods.fetch.result.entries.fetch')) {
// Get fetch.
$original = entries()->registry()->get('fetch');
// Get
$original = entries()->registry()->get('methods.fetch');
$data = [];
switch (entries()->registry()->get('collection.options.fields.entries.fetch.result')) {
switch (entries()->registry()->get('methods.fetch.collection.fields.entries.result')) {
case 'toArray':
$resultTo = 'toArray';
break;
@@ -32,8 +32,8 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
break;
}
// Modify fetch.
foreach (entries()->registry()->get('fetch.result.entries.fetch') as $field => $body) {
// Modify
foreach (entries()->registry()->get('methods.fetch.result.entries.fetch') as $field => $body) {
if (isset($body['options']['method']) &&
strpos($body['options']['method'], 'fetch') !== false &&
@@ -56,14 +56,14 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
$result = arrays($original['result'])->merge($data)->toArray();
if (boolval(entries()->registry()->get('collection.options.fields.entries.dump')) === false) {
if (boolval(entries()->registry()->get('methods.fetch.collection.fields.entries.dump')) === false) {
unset($result['entries']);
}
// Save fetch data.
entries()->registry()->set('fetch.id', $original['id']);
entries()->registry()->set('fetch.options', $original['options']);
entries()->registry()->set('fetch.result', $result);
entries()->registry()->set('methods.fetch.params.id', $original['params']['id']);
entries()->registry()->set('methods.fetch.params.options', $original['params']['options']);
entries()->registry()->set('methods.fetch.result', $result);
}
});

View File

@@ -9,13 +9,13 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.id.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.id.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.id') !== null) {
if (entries()->registry()->get('methods.fetch.result.id') !== null) {
return;
}
entries()->registry()->set('fetch.result.id', strings(entries()->registry()->get('fetch.id'))->trimSlashes()->toString());
entries()->registry()->set('methods.fetch.result.id', strings(entries()->registry()->get('methods.fetch.params.id'))->trimSlashes()->toString());
});

View File

@@ -9,13 +9,13 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.modified_at.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.modified_at.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.modified_at') !== null) {
if (entries()->registry()->get('methods.fetch.result.modified_at') !== null) {
return;
}
entries()->registry()->set('fetch.result.modified_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('fetch.id')))->lastModified());
entries()->registry()->set('methods.fetch.result.modified_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('methods.fetch.params.id')))->lastModified());
});

View File

@@ -9,37 +9,37 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.parsers.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.parsers.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.cache.enabled') == null) {
if (entries()->registry()->get('methods.fetch.result.cache.enabled') == null) {
$cache = false;
} else {
$cache = (bool) entries()->registry()->get('fetch.result.cache.enabled');
$cache = (bool) entries()->registry()->get('methods.fetch.result.cache.enabled');
}
if (entries()->registry()->get('fetch.result.parsers') != null) {
if (entries()->registry()->get('methods.fetch.result.parsers') != null) {
foreach (entries()->registry()->get('fetch.result.parsers') as $parserName => $parserData) {
foreach (entries()->registry()->get('methods.fetch.result.parsers') as $parserName => $parserData) {
if (in_array($parserName, ['shortcodes', 'markdown'])) {
if (entries()->registry()->get('fetch.result.parsers.'.$parserName.'.enabled') === true) {
if (entries()->registry()->get('fetch.result.parsers.'.$parserName.'.fields') != null) {
if (is_array(entries()->registry()->get('fetch.result.parsers.'.$parserName.'.fields'))) {
foreach (entries()->registry()->get('fetch.result.parsers.'.$parserName.'.fields') as $field) {
if (entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.enabled') === true) {
if (entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.fields') != null) {
if (is_array(entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.fields'))) {
foreach (entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.fields') as $field) {
if (! in_array($field, registry()->get('flextype.settings.entries.collections.default.fields'))) {
if ($parserName == 'markdown') {
if (arrays(entries()->registry()->get('fetch.result'))->has($field)) {
entries()->registry()->set('fetch.result.'.$field,
parsers()->markdown()->parse(entries()->registry()->get('fetch.result.'.$field), $cache));
if (arrays(entries()->registry()->get('methods.fetch.result'))->has($field)) {
entries()->registry()->set('methods.fetch.result.'.$field,
parsers()->markdown()->parse(entries()->registry()->get('methods.fetch.result.'.$field), $cache));
}
}
if ($parserName == 'shortcodes') {
if (arrays(entries()->registry()->get('fetch.result'))->has($field)) {
entries()->registry()->set('fetch.result.'.$field,
parsers()->shortcodes()->parse(entries()->registry()->get('fetch.result.'.$field), $cache));
if (arrays(entries()->registry()->get('methods.fetch.result'))->has($field)) {
entries()->registry()->set('methods.fetch.result.'.$field,
parsers()->shortcodes()->parse(entries()->registry()->get('methods.fetch.result.'.$field), $cache));
}
}
}

View File

@@ -9,26 +9,26 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.published_at.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.published_at.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.published_at') === null) {
entries()->registry()->set('fetch.result.published_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('fetch.id')))->lastModified());
if (entries()->registry()->get('methods.fetch.result.published_at') === null) {
entries()->registry()->set('methods.fetch.result.published_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('methods.fetch.params.id')))->lastModified());
} else {
entries()->registry()->set('fetch.result.published_at', (int) strtotime((string) entries()->registry()->get('fetch.result.published_at')));
entries()->registry()->set('methods.fetch.result.published_at', (int) strtotime((string) entries()->registry()->get('methods.fetch.result.published_at')));
}
});
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.published_at.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.published_at.enabled')) {
return;
}
if (entries()->registry()->get('create.data.published_at') !== null) {
if (entries()->registry()->get('methods.create.params.data.published_at') !== null) {
return;
}
entries()->registry()->set('create.data.published_at', date(registry()->get('flextype.settings.date_format'), time()));
entries()->registry()->set('methods.create.params.data.published_at', date(registry()->get('flextype.settings.date_format'), time()));
});

View File

@@ -9,13 +9,13 @@ declare(strict_types=1);
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.published_by.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.published_by.enabled')) {
return;
}
if (entries()->registry()->get('create.data.published_by') !== null) {
if (entries()->registry()->get('methods.create.params.data.published_by') !== null) {
return;
}
entries()->registry()->set('create.data.published_by', '');
entries()->registry()->set('methods.create.params.data.published_by', '');
});

View File

@@ -9,19 +9,19 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.registry.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.registry.enabled')) {
return;
}
if (entries()->registry()->has('fetch.result.registry.get')) {
if (entries()->registry()->has('methods.fetch.result.registry.get')) {
// Get fetch.
$original = entries()->registry()->get('fetch');
$original = entries()->registry()->get('methods.fetch');
$data = [];
// Modify fetch.
foreach (entries()->registry()->get('fetch.result.registry.get') as $field => $body) {
foreach (entries()->registry()->get('methods.fetch.result.registry.get') as $field => $body) {
$data = arrays($data)->merge(arrays($data)->set($field, registry()->get($body['key'],
isset($body['default']) ?
$body['default'] :
@@ -31,11 +31,11 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
$result = arrays($original['result'])->merge($data)->toArray();
if (boolval(entries()->registry()->get('collection.options.fields.entries.dump')) === false) {
if (boolval(entries()->registry()->get('methods.fetch.collection.fields.entries.dump')) === false) {
unset($result['registry']);
}
// Save fetch.
entries()->registry()->set('fetch.result', $result);
entries()->registry()->set('methods.fetch.result', $result);
}
});

View File

@@ -9,27 +9,27 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.routable.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.routable.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.routable') === null) {
entries()->registry()->set('fetch.result.routable', true);
if (entries()->registry()->get('methods.fetch.result.routable') === null) {
entries()->registry()->set('methods.fetch.result.routable', true);
} else {
entries()->registry()->set('fetch.result.routable', (bool) entries()->registry()->get('fetch.result.routable'));
entries()->registry()->set('methods.fetch.result.routable', (bool) entries()->registry()->get('methods.fetch.result.routable'));
}
});
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.routable.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.routable.enabled')) {
return;
}
if (entries()->registry()->get('create.data.routable') === null) {
entries()->registry()->set('create.data.routable', true);
if (entries()->registry()->get('methods.create.params.data.routable') === null) {
entries()->registry()->set('methods.create.params.data.routable', true);
} else {
entries()->registry()->set('create.data.routable', (bool) entries()->registry()->get('create.data.routable'));
entries()->registry()->set('methods.create.params.data.routable', (bool) entries()->registry()->get('methods.create.params.data.routable'));
}
});

View File

@@ -9,14 +9,14 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('collection.options.fields.slug.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.slug.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.slug') !== null) {
if (entries()->registry()->get('methods.fetch.result.slug') !== null) {
return;
}
$parts = explode('/', ltrim(rtrim(entries()->registry()->get('fetch.id'), '/'), '/'));
entries()->registry()->set('fetch.result.slug', (string) end($parts));
$parts = explode('/', ltrim(rtrim(entries()->registry()->get('methods.fetch.params.id'), '/'), '/'));
entries()->registry()->set('methods.fetch.result.slug', (string) end($parts));
});

View File

@@ -11,13 +11,13 @@ use Ramsey\Uuid\Uuid;
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.uuid.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.uuid.enabled')) {
return;
}
if (entries()->registry()->get('create.data.uuid') !== null) {
if (entries()->registry()->get('methods.create.params.data.uuid') !== null) {
return;
}
entries()->registry()->set('create.data.uuid', Uuid::uuid4()->toString());
entries()->registry()->set('methods.create.params.data.uuid', Uuid::uuid4()->toString());
});

View File

@@ -15,14 +15,14 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
'visible' => 'visible',
];
if (! entries()->registry()->get('collection.options.fields.visibility.enabled')) {
if (! entries()->registry()->get('methods.fetch.collection.fields.visibility.enabled')) {
return;
}
if (entries()->registry()->get('fetch.result.visibility') !== null && in_array(entries()->registry()->get('fetch.result.visibility'), $visibility)) {
entries()->registry()->set('fetch.result.visibility', (string) $visibility[entries()->registry()->get('fetch.result.visibility')]);
if (entries()->registry()->get('methods.fetch.result.visibility') !== null && in_array(entries()->registry()->get('methods.fetch.result.visibility'), $visibility)) {
entries()->registry()->set('methods.fetch.result.visibility', (string) $visibility[entries()->registry()->get('methods.fetch.result.visibility')]);
} else {
entries()->registry()->set('fetch.result.visibility', (string) $visibility['visible']);
entries()->registry()->set('methods.fetch.result.visibility', (string) $visibility['visible']);
}
});
@@ -34,13 +34,13 @@ emitter()->addListener('onEntriesCreate', static function (): void {
'visible' => 'visible',
];
if (! entries()->registry()->get('collection.options.fields.visibility.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.visibility.enabled')) {
return;
}
if (entries()->registry()->get('create.data.visibility') !== null && in_array(entries()->registry()->get('create.data.visibility'), $visibility)) {
entries()->registry()->set('create.data.visibility', (string) $visibility[entries()->registry()->get('create.data.visibility')]);
if (entries()->registry()->get('methods.create.params.data.visibility') !== null && in_array(entries()->registry()->get('methods.create.params.data.visibility'), $visibility)) {
entries()->registry()->set('methods.create.params.data.visibility', (string) $visibility[entries()->registry()->get('methods.create.params.data.visibility')]);
} else {
entries()->registry()->set('create.data.visibility', (string) $visibility['visible']);
entries()->registry()->set('methods.create.params.data.visibility', (string) $visibility['visible']);
}
});

View File

@@ -9,13 +9,13 @@ declare(strict_types=1);
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.calls.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.calls.enabled')) {
return;
}
if (entries()->registry()->get('create.data.calls') !== null) {
if (entries()->registry()->get('methods.create.params.data.calls') !== null) {
return;
}
entries()->registry()->set('create.data.calls', 0);
entries()->registry()->set('methods.create.params.data.calls', 0);
});

View File

@@ -9,13 +9,13 @@ declare(strict_types=1);
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.limit_calls.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.limit_calls.enabled')) {
return;
}
if (entries()->registry()->get('create.data.limit_calls') !== null) {
if (entries()->registry()->get('methods.create.params.data.limit_calls') !== null) {
return;
}
entries()->registry()->set('create.data.limit_calls', 0);
entries()->registry()->set('methods.create.params.data.limit_calls', 0);
});

View File

@@ -9,13 +9,13 @@ declare(strict_types=1);
emitter()->addListener('onEntriesCreate', static function (): void {
if (! entries()->registry()->get('collection.options.fields.state.enabled')) {
if (! entries()->registry()->get('methods.create.collection.fields.state.enabled')) {
return;
}
if (entries()->registry()->get('create.data.state') !== null) {
if (entries()->registry()->get('methods.create.params.data.state') !== null) {
return;
}
entries()->registry()->set('create.data.state', 'enabled');
entries()->registry()->set('methods.create.params.data.state', 'enabled');
});