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

Flextype Core: Entries - new method fetch() and fetchAll() - added.

This commit is contained in:
Awilum
2019-02-08 19:55:05 +03:00
parent 6299b311bb
commit 50b7aa4478

View File

@@ -282,6 +282,40 @@ class Entries
}
}
/**
* Fetch entry
*
* @param string $entry Entry
* @return string|false The entry contents or false on failure.
*/
public static function fetch(string $entry)
{
$entry_file = PATH['entries'] . '/' . $entry . '/entry.html';
if (Filesystem::has($entry_file)) {
return YamlParser::decode(Filesystem::read($entry_file));
} else {
return false;
}
}
/**
* Fetch entry
*
* @param string $entry Entry
* @return string|false The entry contents or false on failure.
*/
public static function fetchAll(string $entry)
{
$entry_file = PATH['entries'] . '/' . $entry . '/entry.html';
if (Filesystem::has($entry_file)) {
return YamlParser::decode(Filesystem::read($entry_file));
} else {
return false;
}
}
/**
* Rename entry.
*
@@ -298,15 +332,15 @@ class Entries
* Update entry
*
* @param string $entry Entry
* @param string $data Data
* @param array $data Data
* @return bool
*/
public static function update(string $entry, string $data) : bool
public static function update(string $entry, array $data) : bool
{
$entry_file = PATH['entries'] . '/' . $entry . '/entry.html';
if (Filesystem::has($entry_file)) {
return Filesystem::write($entry_file, $data);
return Filesystem::write($entry_file, YamlParser::encode($data));
} else {
return false;
}
@@ -316,10 +350,10 @@ class Entries
* Create entry
*
* @param string $entry Entry
* @param string $data Data
* @param array $data Data
* @return bool
*/
public static function create(string $entry, string $data) : bool
public static function create(string $entry, array $data) : bool
{
$entry_dir = PATH['entries'] . '/' . $entry;
@@ -333,7 +367,7 @@ class Entries
// Check if new entry file exists
if (!Filesystem::has($entry_file)) {
return Filesystem::write($entry_file, $data);
return Filesystem::write($entry_file, YamlParser::encode($data));
}
} else {