From f5d202c02a3d0bad61f0aa245096df243946000b Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 10 Aug 2019 21:57:33 +0300 Subject: [PATCH] Flextype Core: Add ability to work with different types of content #212 #186 --- flextype/core/Entries.php | 16 ++++++++-------- flextype/parsers/Parser.php | 10 ++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/flextype/core/Entries.php b/flextype/core/Entries.php index e19c2be4..741cf380 100755 --- a/flextype/core/Entries.php +++ b/flextype/core/Entries.php @@ -466,15 +466,15 @@ class Entries */ private function _file_location(string $id) { - $json_file = PATH['entries'] . '/' . $id . '/entry.json'; - $yaml_file = PATH['entries'] . '/' . $id . '/entry.yaml'; + foreach (Parser::$drivers as $driver) { + $driver_file = PATH['entries'] . '/' . $id . '/entry' . '.' . $driver['ext']; - if (Filesystem::has($json_file)) { - return ['file' => $json_file, 'driver' => 'json']; - } - - if (Filesystem::has($yaml_file)) { - return ['file' => $yaml_file, 'driver' => 'yaml']; + if (Filesystem::has($driver_file)) { + return [ + 'file' => $driver_file, + 'driver' => $driver['name'], + ]; + } } return false; diff --git a/flextype/parsers/Parser.php b/flextype/parsers/Parser.php index 09a4ffcb..824d7a81 100644 --- a/flextype/parsers/Parser.php +++ b/flextype/parsers/Parser.php @@ -11,6 +11,16 @@ namespace Flextype; class Parser { + public static $drivers = [ + 'json' => [ + 'name' => 'json', + 'ext' => 'json', + ], 'yaml' => [ + 'name' => 'yaml', + 'ext' => 'yaml', + ], + ]; + public static function encode($input, string $driver) : string { switch ($driver) {