From 0ac347d211b15ceb79f03ed1fec4c5ae26b8643b Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 11 Dec 2020 14:56:24 +0300 Subject: [PATCH] feat(entries): Entries API fetch improvements. #491 --- src/flextype/Foundation/Entries/Entries.php | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/flextype/Foundation/Entries/Entries.php b/src/flextype/Foundation/Entries/Entries.php index 3c77c14f..a8811f92 100755 --- a/src/flextype/Foundation/Entries/Entries.php +++ b/src/flextype/Foundation/Entries/Entries.php @@ -118,11 +118,9 @@ class Entries // 1. Try to get current requested entry from cache if (flextype('cache')->has($entryCacheID)) { - // Fetch entry from cache - $this->storage['fetch']['data'] = flextype('cache')->get($entryCacheID); - // Apply filter for fetch data - $this->storage['fetch']['data'] = filter($this->storage['fetch']['data'], + // Fetch entry from cache and Apply filter for fetch data + $this->storage['fetch']['data'] = filter(flextype('cache')->get($entryCacheID), $this->storage['fetch']['options']); // Run event: onEntriesFetchSingleCacheHasResult @@ -139,24 +137,24 @@ class Entries // Try to get requested entry from the filesystem $entryFileContent = filesystem()->file($entryFile)->get(); + if ($entryFileContent === false) { - return arrays(); + // Run event: onEntriesFetchSingleNoResult + flextype('emitter')->emit('onEntriesFetchSingleNoResult'); + return arrays($this->storage['fetch']['data']); } - // Decode entry file content - $this->storage['fetch']['data'] = flextype('frontmatter')->decode($entryFileContent); - - // Set cache state - $cache = flextype('entries')->storage['fetch']['data']['cache']['enabled'] ?? - flextype('registry')->get('flextype.settings.cache.enabled'); - - // Apply filter for fetch data - $this->storage['fetch']['data'] = filter($this->storage['fetch']['data'], + // Decode entry file content and Apply filter for fetch data + $this->storage['fetch']['data'] = filter(flextype('frontmatter')->decode($entryFileContent), $this->storage['fetch']['options']); // Run event: onEntriesFetchSingleHasResult flextype('emitter')->emit('onEntriesFetchSingleHasResult'); + // Set cache state + $cache = flextype('entries')->storage['fetch']['data']['cache']['enabled'] ?? + flextype('registry')->get('flextype.settings.cache.enabled'); + // Save entry data to cache if ($cache) { flextype('cache')->set($entryCacheID, $this->storage['fetch']['data']);