diff --git a/flextype/Cache.php b/flextype/Cache.php index 04f67dc9..0adfd87e 100755 --- a/flextype/Cache.php +++ b/flextype/Cache.php @@ -62,11 +62,22 @@ class Cache } /** - * Constructor. + * Protected constructor since this is a static class. * * @access protected */ protected function __construct() + { + static::init(); + } + + /** + * Init Cache + * + * @access protected + * @return void + */ + protected static function init() : void { // Set current time static::$now = time(); @@ -269,12 +280,13 @@ class Cache } /** - * Initialize Flextype Cache + * Return the Cache instance. + * Create it if it's not already created. * * @access public * @return object */ - public static function init() + public static function instance() { return !isset(self::$instance) and self::$instance = new Cache(); } diff --git a/flextype/Config.php b/flextype/Config.php index c1cbdef4..75e55ca9 100755 --- a/flextype/Config.php +++ b/flextype/Config.php @@ -45,11 +45,22 @@ class Config } /** - * Constructor. + * Protected constructor since this is a static class. * * @access protected */ protected function __construct() + { + static::init(); + } + + /** + * Init Config + * + * @access protected + * @return void + */ + protected static function init() : void { if (Flextype::filesystem()->exists($site_config = CONFIG_PATH . '/' . 'site.yml')) { static::$config['site'] = Yaml::parse(file_get_contents($site_config)); @@ -95,11 +106,13 @@ class Config } /** - * Initialize Flextype Config + * Return the Config instance. + * Create it if it's not already created. * - * @access public + * @access public + * @return object */ - public static function init() + public static function instance() { return !isset(self::$instance) and self::$instance = new Config(); } diff --git a/flextype/Flextype.php b/flextype/Flextype.php index 761709a7..63e95de6 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -76,14 +76,14 @@ class Flextype */ protected static function app() : void { - // Init Finder + // Create Finder Instance static::$finder = new Finder(); - // Init Filesystem + // Create Filesystem Instance static::$filesystem = new Filesystem(); - // Init Config - Config::init(); + // Create Cache Instance + Config::instance(); // Turn on output buffering ob_start(); @@ -113,23 +113,23 @@ class Flextype // Start the session Session::start(); - // Init Cache - Cache::init(); + // Create Cache Instance + Cache::instance(); - // Init I18n - I18n::init(); + // Create I18n Instance + I18n::instance(); - // Init Shortcodes - Shortcodes::init(); + // Create Shortcodes Instance + Shortcodes::instance(); - // Init Themes - Themes::init(); + // Create Themes Instance + Themes::instance(); - // Init Plugins - Plugins::init(); + // Create Plugins Instance + Plugins::instance(); - // Init Pages - Pages::init(); + // Create Pages Instance + Pages::instance(); // Flush (send) the output buffer and turn off output buffering ob_end_flush(); diff --git a/flextype/I18n.php b/flextype/I18n.php index f804a79a..a7070b96 100644 --- a/flextype/I18n.php +++ b/flextype/I18n.php @@ -81,9 +81,22 @@ class I18n } /** - * Construct + * Protected constructor since this is a static class. + * + * @access protected */ protected function __construct() + { + static::init(); + } + + /** + * Init I18n + * + * @access protected + * @return void + */ + protected static function init() : void { // Get Plugins and Site Locales list @@ -130,12 +143,13 @@ class I18n } /** - * Initialize Flextype I18n + * Return the I18n instance. + * Create it if it's not already created. * * @access public * @return object */ - public static function init() + public static function instance() { return !isset(self::$instance) and self::$instance = new I18n(); } diff --git a/flextype/Pages.php b/flextype/Pages.php index 942a4468..1abf3f76 100755 --- a/flextype/Pages.php +++ b/flextype/Pages.php @@ -34,11 +34,22 @@ class Pages public static $page; /** - * Constructor + * Protected constructor since this is a static class. * * @access protected */ protected function __construct() + { + static::init(); + } + + /** + * Init Pages + * + * @access protected + * @return void + */ + protected static function init() : void { // The page is not processed and not sent to the display. Events::dispatch('onPageBeforeRender'); @@ -230,12 +241,13 @@ class Pages } /** - * Initialize Flextype Pages + * Return the Pages instance. + * Create it if it's not already created. * * @access public * @return object */ - public static function init() + public static function instance() { return !isset(self::$instance) and self::$instance = new Pages(); } diff --git a/flextype/Plugins.php b/flextype/Plugins.php index 66e74c9f..6031b60e 100755 --- a/flextype/Plugins.php +++ b/flextype/Plugins.php @@ -24,11 +24,22 @@ class Plugins protected static $instance = null; /** - * Init Plugins + * Protected constructor since this is a static class. * - * @access public + * @access protected */ protected function __construct() + { + static::init(); + } + + /** + * Init Plugins + * + * @access protected + * @return void + */ + protected static function init() : void { // Plugin manifest $plugin_manifest = []; @@ -89,12 +100,13 @@ class Plugins } /** - * Initialize Flextype Plugins + * Return the Plugins instance. + * Create it if it's not already created. * * @access public * @return object */ - public static function init() + public static function instance() { return !isset(self::$instance) and self::$instance = new Plugins(); } diff --git a/flextype/Shortcodes.php b/flextype/Shortcodes.php index 089b70a6..a945918e 100644 --- a/flextype/Shortcodes.php +++ b/flextype/Shortcodes.php @@ -38,6 +38,17 @@ class Shortcodes * @access protected */ protected function __construct() + { + static::init(); + } + + /** + * Init Shortcodes + * + * @access protected + * @return void + */ + protected static function init() : void { // Set driver static::$driver = new ShortcodeFacade(); @@ -70,12 +81,13 @@ class Shortcodes } /** - * Initialize Flextype Shortcodes + * Return the Shortcodes instance. + * Create it if it's not already created. * * @access public * @return object */ - public static function init() + public static function instance() { return !isset(self::$instance) and self::$instance = new Shortcodes(); } diff --git a/flextype/Themes.php b/flextype/Themes.php index 8a9d648f..e72bf2f7 100644 --- a/flextype/Themes.php +++ b/flextype/Themes.php @@ -24,12 +24,22 @@ class Themes protected static $instance = null; /** - * Init Themes + * Protected constructor since this is a static class. * - * @access public - * @return mixed + * @access protected */ protected function __construct() + { + static::init(); + } + + /** + * Init Themes + * + * @access protected + * @return void + */ + protected static function init() : void { // Theme Manifest $theme_manifest = []; @@ -55,12 +65,13 @@ class Themes } /** - * Initialize Flextype Themes + * Return the Themes instance. + * Create it if it's not already created. * * @access public * @return object */ - public static function init() + public static function instance() { return !isset(self::$instance) and self::$instance = new Themes(); }