From 48dae3810e8a954d42e566bc178bc202ffd7700f Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 22 May 2019 11:47:04 +0300 Subject: [PATCH] Flextype Core: Themes - fixes. --- flextype/Themes.php | 34 +++++++++++++++++++++++----------- flextype/bootstrap.php | 7 +++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/flextype/Themes.php b/flextype/Themes.php index f27c487d..63f082d6 100644 --- a/flextype/Themes.php +++ b/flextype/Themes.php @@ -16,34 +16,46 @@ use Flextype\Component\Filesystem\Filesystem; class Themes { + /** + * Flextype Dependency Container + */ + private $flextype; + /** * Private construct method to enforce singleton behavior. * * @access private */ - public function __construct() + public function __construct($flextype) { + $this->flextype = $flextype; + $this->init($flextype, $app); + } + + public function init($flextype, $app) + { + // Get current theme - $theme = Registry::get('settings.theme'); + $theme = $this->flextype['registry']->get('settings.theme'); // Set empty themes items - Registry::set('themes', []); + $this->flextype['registry']->set('themes', []); // Create Unique Cache ID for Theme $theme_cache_id = md5('theme' . filemtime(PATH['themes'] . '/' . $theme . '/' . 'settings.json') . filemtime(PATH['themes'] . '/' . $theme . '/' . $theme . '.json')); // Get Theme mafifest file and write to settings.themes array - if (Cache::contains($theme_cache_id)) { - Registry::set('themes.' . Registry::get('settings.theme'), Cache::fetch($theme_cache_id)); + if ($this->flextype['cache']->contains($theme_cache_id)) { + $this->flextype['registry']->set('themes.' . $this->flextype['registry']->get('settings.theme'), $this->flextype['cache']->fetch($theme_cache_id)); } else { if (Filesystem::has($theme_settings = PATH['themes'] . '/' . $theme . '/' . 'settings.json') and Filesystem::has($theme_config = PATH['themes'] . '/' . $theme . '/' . $theme . '.json')) { $theme_settings = JsonParser::decode(Filesystem::read($theme_settings)); $theme_config = JsonParser::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); + $this->flextype['registry']->set('themes.' . $this->flextype['registry']->get('settings.theme'), $_theme); + $this->flextype['cache']->save($theme_cache_id, $_theme); } } } @@ -60,12 +72,12 @@ class Themes $partials = []; // Get partials files - $_partials = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/partials/'); + $_partials = Filesystem::listContents(PATH['themes'] . '/' . $this->flextype['registry']->get('settings.theme') . '/views/partials/'); // If there is any partials file then go... if (count($_partials) > 0) { foreach ($_partials as $partial) { - if ($partial['type'] == 'file' && $partial['extension'] == 'php') { + if ($partial['type'] == 'file' && $partial['extension'] == 'html') { $partials[$partial['basename']] = $partial['basename']; } } @@ -86,12 +98,12 @@ class Themes $templates = []; // Get templates files - $_templates = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/'); + $_templates = Filesystem::listContents(PATH['themes'] . '/' . $this->flextype['registry']->get('settings.theme') . '/views/templates/'); // If there is any template file then go... if (count($_templates) > 0) { foreach ($_templates as $template) { - if ($template['type'] == 'file' && $template['extension'] == 'php') { + if ($template['type'] == 'file' && $template['extension'] == 'html') { $templates[$template['basename']] = $template['basename']; } } diff --git a/flextype/bootstrap.php b/flextype/bootstrap.php index a9bc7548..742635f2 100755 --- a/flextype/bootstrap.php +++ b/flextype/bootstrap.php @@ -320,6 +320,13 @@ $app->get('/image/{path:.+}', function (Request $request, Response $response, ar return $flextype['images']->getImageResponse($args['path'], $_GET); }); +/** + * Add themes service to Flextype container + */ + $flextype['themes'] = function($container) use ($flextype, $app) { + return new Themes($flextype, $app); + }; + /** * Add plugins service to Flextype container */