1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-12 08:04:05 +02:00

Flextype Core: Using new Flextype Filesystem Component 2.0

This commit is contained in:
Awilum
2019-02-01 14:35:37 +03:00
parent 81855ce775
commit ce2d0eb2e3
7 changed files with 59 additions and 72 deletions

View File

@@ -91,7 +91,7 @@ class Cache
protected static function init() : void
{
// Create Cache Directory
!Filesystem::dirExists(PATH['cache']) and Filesystem::createDir(PATH['cache']);
!Filesystem::has(PATH['cache']) and Filesystem::createDir(PATH['cache']);
// Set current time
Cache::$now = time();
@@ -183,7 +183,7 @@ class Cache
// http://php.net/manual/en/book.sqlite3.php
case 'sqlite3':
// Create doctrine cache directory if its not exists
!Filesystem::fileExists($cache_directory) and Filesystem::createDir($cache_directory);
!Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory);
$db = new \SQLite3($cache_directory . Registry::get('settings.cache.sqlite3.database', 'flextype') . '.db');
$driver = new DoctrineCache\SQLite3Cache($db, Registry::get('settings.cache.sqlite3.table', 'flextype'));
@@ -218,7 +218,7 @@ class Cache
break;
default:
// Create doctrine cache directory if its not exists
!Filesystem::fileExists($cache_directory) and Filesystem::createDir($cache_directory);
!Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory);
$driver = new DoctrineCache\FilesystemCache($cache_directory);
break;
}

View File

@@ -162,7 +162,7 @@ class Entries
}
// If entry exist
if (Filesystem::fileExists($file_path)) {
if (Filesystem::has($file_path)) {
$entry_cache_id = md5('entry' . $file_path . filemtime($file_path) . (($raw === true) ? 'true' : 'false') . (($hidden === true) ? 'true' : 'false'));
// Try to get the entry from cache
@@ -233,19 +233,23 @@ class Entries
if ($url === '') {
// Get entries list
$entries_list = Filesystem::getFilesList($file_path, 'html', true, $multilevel);
$entries_list = Filesystem::listContents($file_path);
// Create entries cached id
foreach ($entries_list as $key => $entry) {
$entry_cache_id .= md5('entries' . $entry . filemtime($entry) . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length);
foreach ($entries_list as $entry) {
if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) {
$entry_cache_id .= md5('entries' . $entry['path'] . $entry['timestamp'] . (($raw === true) ? 'true' : 'false') . (($multilevel === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length);
}
}
if (Cache::contains($entry_cache_id)) {
$entries = Cache::fetch($entry_cache_id);
} else {
// Create entries array from entries list
foreach ($entries_list as $key => $entry) {
$entries[$key] = Entries::processEntry($entry, $raw);
foreach ($entries_list as $entry) {
if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) {
$entries[$entry['dirname']] = Entries::processEntry($entry['path'] . '/entry.html', $raw);
}
}
Cache::save($entry_cache_id, $entries);
@@ -253,14 +257,16 @@ class Entries
} else {
// Get entries list
$entries_list = Filesystem::getFilesList($file_path, 'html', true, $multilevel);
$entries_list = Filesystem::listContents($file_path);
// Create entries cached id
foreach ($entries_list as $key => $entry) {
if (strpos($entry, $url . '/entry.html') !== false) {
foreach ($entries_list as $entry) {
if (strpos($entry['path'], $url . '/entry.html') !== false) {
// ignore ...
} else {
$entry_cache_id .= md5('entries' . $entry . filemtime($entry) . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length);
if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) {
$entry_cache_id .= md5('entries' . $entry['path'] . $entry['timestamp'] . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length);
}
}
}
@@ -268,11 +274,13 @@ class Entries
$entries = Cache::fetch($entry_cache_id);
} else {
// Create entries array from entries list and ignore current requested entry
foreach ($entries_list as $key => $entry) {
if (strpos($entry, $url . '/entry.html') !== false) {
foreach ($entries_list as $entry) {
if (strpos($entry['path'], $url . '/entry.html') !== false) {
// ignore ...
} else {
$entries[$key] = Entries::processEntry($entry, $raw);
if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) {
$entries[$entry['dirname']] = Entries::processEntry($entry['path'] . '/entry.html', $raw);
}
}
}
@@ -326,7 +334,7 @@ class Entries
public static function processEntry(string $file_path, bool $raw = false, bool $ignore_content = false)
{
// Get entry from file
$entry = trim(Filesystem::getFileContent($file_path));
$entry = trim(Filesystem::read($file_path));
// Return raw entry if $raw is true
if ($raw) {

View File

@@ -129,7 +129,7 @@ class Flextype
}
// Create directory for logs
!Filesystem::fileExists(LOGS_PATH) and Filesystem::createDir(LOGS_PATH);
!Filesystem::has(LOGS_PATH) and Filesystem::createDir(LOGS_PATH);
// Set Error handler
set_error_handler('Flextype\Component\ErrorHandler\ErrorHandler::error');
@@ -152,11 +152,11 @@ class Flextype
$site_settings_file_path = PATH['config']['site'] . '/settings.yaml';
// Set settings if Flextype settings and Site settings config files exist
if (Filesystem::fileExists($default_settings_file_path) && Filesystem::fileExists($site_settings_file_path)) {
if (Filesystem::has($default_settings_file_path) && Filesystem::has($site_settings_file_path)) {
// Get Flextype settings and Site settings
$default_settings = YamlParser::decode(Filesystem::getFileContent($default_settings_file_path));
$site_settings = YamlParser::decode(Filesystem::getFileContent($site_settings_file_path));
$default_settings = YamlParser::decode(Filesystem::read($default_settings_file_path));
$site_settings = YamlParser::decode(Filesystem::read($site_settings_file_path));
// Merge settings
$settings = array_replace_recursive($default_settings, $site_settings);

View File

@@ -29,8 +29,8 @@ class Menus
{
$menu_path = PATH['menus'] . '/' . $menu_name . '.yaml';
if (Filesystem::fileExists($menu_path)) {
return YamlParser::decode(Filesystem::getFileContent($menu_path));
if (Filesystem::has($menu_path)) {
return YamlParser::decode(Filesystem::read($menu_path));
} else {
throw new \RuntimeException("Menu {$menu_name} does not exist.");
}

View File

@@ -236,15 +236,15 @@ class Plugins
Registry::set('plugins', []);
// Get Plugins List
$plugins_list = Filesystem::getDirList(PATH['plugins']);
$plugins_list = Filesystem::listContents(PATH['plugins']);
// If Plugins List isnt empty then create plugin cache ID
if (is_array($plugins_list) && count($plugins_list) > 0) {
// Go through...
foreach ($plugins_list as $plugin) {
if (Filesystem::fileExists($_plugin_settings = PATH['plugins'] . '/' . $plugin . '/settings.yaml') and
Filesystem::fileExists($_plugin_config = PATH['plugins'] . '/' . $plugin . '/'. $plugin .'.yaml')) {
if (Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.yaml') and
Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/'. $plugin['dirname'] .'.yaml')) {
$_plugins_cache_id .= filemtime($_plugin_settings) . filemtime($_plugin_config);
}
}
@@ -262,12 +262,12 @@ class Plugins
// Go through...
foreach ($plugins_list as $plugin) {
if (Filesystem::fileExists($_plugin_settings = PATH['plugins'] . '/' . $plugin . '/settings.yaml')) {
$plugin_settings = YamlParser::decode(Filesystem::getFileContent($_plugin_settings));
if (Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.yaml')) {
$plugin_settings = YamlParser::decode(Filesystem::read($_plugin_settings));
}
if (Filesystem::fileExists($_plugin_config = PATH['plugins'] . '/' . $plugin . '/'. $plugin. '.yaml')) {
$plugin_config = YamlParser::decode(Filesystem::getFileContent($_plugin_config));
if (Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/'. $plugin['dirname']. '.yaml')) {
$plugin_config = YamlParser::decode(Filesystem::read($_plugin_config));
}
$_plugins_config[basename($_plugin_config, '.yaml')] = array_merge($plugin_settings, $plugin_config);
@@ -282,9 +282,9 @@ class Plugins
if (is_array($plugins_list) && count($plugins_list) > 0) {
foreach (Plugins::$locales as $locale => $locale_title) {
foreach ($plugins_list as $plugin) {
$language_file = PATH['plugins'] . '/' . $plugin . '/languages/' . $locale . '.yaml';
if (Filesystem::fileExists($language_file)) {
I18n::add(YamlParser::decode(Filesystem::getFileContent($language_file)), $locale);
$language_file = PATH['plugins'] . '/' . $plugin['dirname'] . '/languages/' . $locale . '.yaml';
if (Filesystem::has($language_file)) {
I18n::add(YamlParser::decode(Filesystem::read($language_file)), $locale);
}
}
}

View File

@@ -57,7 +57,7 @@ class Snippets
$snippet_path = PATH['snippets'] . '/' . $name . '.php';
// Process snippet
if (Filesystem::fileExists($snippet_path)) {
if (Filesystem::has($snippet_path)) {
// Turn on output buffering
ob_start();

View File

@@ -81,10 +81,10 @@ class Themes
if (Cache::contains($theme_cache_id)) {
Registry::set('themes.'.Registry::get('settings.theme'), Cache::fetch($theme_cache_id));
} else {
if (Filesystem::fileExists($theme_settings = PATH['themes'] . '/' . $theme . '/' . 'settings.yaml') and
Filesystem::fileExists($theme_config = PATH['themes'] . '/' . $theme . '/' . $theme . '.yaml')) {
$theme_settings = YamlParser::decode(Filesystem::getFileContent($theme_settings));
$theme_config = YamlParser::decode(Filesystem::getFileContent($theme_config));
if (Filesystem::has($theme_settings = PATH['themes'] . '/' . $theme . '/' . 'settings.yaml') and
Filesystem::has($theme_config = PATH['themes'] . '/' . $theme . '/' . $theme . '.yaml')) {
$theme_settings = YamlParser::decode(Filesystem::read($theme_settings));
$theme_config = YamlParser::decode(Filesystem::read($theme_config));
$_theme = array_merge($theme_settings, $theme_config);
Registry::set('themes.'.Registry::get('settings.theme'), $_theme);
Cache::save($theme_cache_id, $_theme);
@@ -104,7 +104,7 @@ class Themes
{
// Set view file
// From current theme folder or from plugin folder
if (Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template . View::$view_ext)) {
if (Filesystem::has(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template . View::$view_ext)) {
$template = PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template;
} else {
$template = PATH['plugins'] . '/' . $template;
@@ -124,15 +124,14 @@ class Themes
{
$partials = [];
// Get templates files
$_partials = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/partials/', 'php');
// Get partials files
$_partials = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/partials/');
// If there is any template file then go...
// If there is any partials file then go...
if (count($_partials) > 0) {
foreach ($_partials as $partial) {
if (!is_bool(Themes::_strrevpos($partial, '/partials' . DIRECTORY_SEPARATOR))) {
$partial_name = str_replace('.php', '', substr($partial, Themes::_strrevpos($partial, '/partials' . DIRECTORY_SEPARATOR)+strlen('/partials' . DIRECTORY_SEPARATOR)));
$partials[$partial_name] = $partial_name;
if ($partial['type'] == 'file' && $partial['extension'] == 'php') {
$partials[$partial['basename']] = $partial['basename'];
}
}
}
@@ -152,14 +151,13 @@ class Themes
$templates = [];
// Get templates files
$_templates = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/', 'php');
$_templates = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/');
// If there is any template file then go...
if (count($_templates) > 0) {
foreach ($_templates as $template) {
if (!is_bool(Themes::_strrevpos($template, '/templates' . DIRECTORY_SEPARATOR))) {
$template_name = str_replace('.php', '', substr($template, Themes::_strrevpos($template, '/templates' . DIRECTORY_SEPARATOR)+strlen('/templates' . DIRECTORY_SEPARATOR)));
$templates[$template_name] = $template_name;
if ($template['type'] == 'file' && $template['extension'] == 'php') {
$templates[$template['basename']] = $template['basename'];
}
}
}
@@ -179,15 +177,14 @@ class Themes
$fieldsets = [];
// Get fieldsets files
$_fieldsets = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/', 'yaml');
$_fieldsets = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/');
// If there is any template file then go...
if (count($_fieldsets) > 0) {
foreach ($_fieldsets as $fieldset) {
if (!is_bool(Themes::_strrevpos($fieldset, '/fieldsets' . DIRECTORY_SEPARATOR))) {
$fieldset_name = str_replace('.yaml', '', substr($fieldset, Themes::_strrevpos($fieldset, '/fieldsets' . DIRECTORY_SEPARATOR)+strlen('/fieldsets' . DIRECTORY_SEPARATOR)));
$fieldset = YamlParser::decode(Filesystem::getFileContent($fieldset));
$fieldsets[$fieldset_name] = $fieldset['title'];
if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') {
$fieldset_content = YamlParser::decode(Filesystem::read($fieldset['path']));
$fieldsets[$fieldset['basename']] = $fieldset_content['title'];
}
}
}
@@ -196,24 +193,6 @@ class Themes
return $fieldsets;
}
/**
* _strrevpos
*
* @param string $instr instr
* @param string $needle needle
*
* @return bool
*/
private static function _strrevpos($instr, $needle)
{
$rev_pos = strpos(strrev($instr), strrev($needle));
if ($rev_pos === false) {
return false;
} else {
return strlen($instr) - $rev_pos - strlen($needle);
}
}
/**
* Get the Themes instance.
*