From 7c18cbeaf0095f9a8d4f5f403f5651bc2a4395a8 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 11 Aug 2019 01:26:18 +0300 Subject: [PATCH] Flextype Core: Add ability to work with different types of content #212 #186 - FrontmatterParser implementation --- flextype/core/Entries.php | 19 +++++++++++++++---- flextype/parsers/Parser.php | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/flextype/core/Entries.php b/flextype/core/Entries.php index ed096091..32303364 100755 --- a/flextype/core/Entries.php +++ b/flextype/core/Entries.php @@ -269,12 +269,12 @@ class Entries } else { // Create entries array from entries list and ignore current requested entry foreach ($entries_list as $current_entry) { - if (strpos($current_entry['path'], $bind_id . '/entry.json') !== false) { + if (strpos($current_entry['path'], $bind_id . '/entry') !== false) { // ignore ... } else { // We are checking... // Whether the requested entry is a director and whether the file entry.json is in this directory. - if ($current_entry['type'] === 'dir' && Filesystem::has($current_entry['path'] . '/entry.json')) { + if ($current_entry['type'] === 'dir' && $this->_one_of($id)) { // Get entry uid // 1. Remove entries path // 2. Remove left and right slashes @@ -375,8 +375,8 @@ class Entries { $entry_file = $this->_file_location($id); - if (Filesystem::has($entry_file)) { - return Filesystem::write($entry_file, Parser::encode($data)); + if (Filesystem::has($entry_file['file'])) { + return Filesystem::write($entry_file['file'], Parser::encode($data, $entry_file['driver'])); } return false; @@ -457,6 +457,17 @@ class Entries return Filesystem::has($this->_file_location($id)); } + private function _one_of(string $id) + { + foreach (Parser::$drivers as $driver) { + $driver_file = PATH['entries'] . '/' . $id . '/entry' . '.' . $driver['ext']; + + return true; + } + + return false; + } + /** * Helper method _file_location * diff --git a/flextype/parsers/Parser.php b/flextype/parsers/Parser.php index 1e14f668..de7ea6de 100644 --- a/flextype/parsers/Parser.php +++ b/flextype/parsers/Parser.php @@ -32,7 +32,7 @@ class Parser break; case 'yaml': - return JsonParser::encode($input); + return YamlParser::encode($input); break; case 'frontmatter':