diff --git a/flextype/Entries.php b/flextype/Entries.php index d971fcb3..f1626f34 100755 --- a/flextype/Entries.php +++ b/flextype/Entries.php @@ -20,127 +20,6 @@ use Flextype\Component\Registry\Registry; class Entries { - /** - * An instance of the Entry class - * - * @var object - * @access private - */ - private static $instance = null; - - /** - * Current entry data array - * - * @var array - * @access private - */ - private static $entry = []; - - /** - * Private clone method to enforce singleton behavior. - * - * @access private - */ - private function __clone() - { - } - - /** - * Private wakeup method to enforce singleton behavior. - * - * @access private - */ - private function __wakeup() - { - } - - /** - * Private construct method to enforce singleton behavior. - * - * @access private - */ - private function __construct() - { - Entries::init(); - } - - /** - * Init Entry - * - * @access private - * @return void - */ - private static function init() : void - { - Entries::processCurrentEntry(); - } - - /** - * Process Current Entry - * - * @access private - * @return void - */ - private static function processCurrentEntry() : void - { - // Event: The entry is not processed and not sent to the display. - Event::dispatch('onCurrentEntryBeforeProcessed'); - - // Set current requested entry data to global $entry array - Entries::$entry = Entries::getEntry(Http::getUriString()); - - // Event: The entry has been fully processed and not sent to the display. - Event::dispatch('onCurrentEntryBeforeDisplayed'); - - // Display entry for current requested url - Entries::displayCurrentEntry(); - - // Event: The entry has been fully processed and sent to the display. - Event::dispatch('onCurrentEntryAfterProcessed'); - } - - /** - * Get current entry - * - * $entry = Entries::getCurrentEntry(); - * - * @access public - * @return array - */ - public static function getCurrentEntry() : array - { - return Entries::$entry; - } - - /** - * Update current entry - * - * Entries::updateCurrentEntry(['title' => "New Title"]); - * - * @access public - * @param array $data Data - * @return void - */ - public static function updateCurrentEntry(array $data) : void - { - Entries::$entry = $data; - } - - /** - * Update current entry field - * - * Entries::updateCurrentEntryField('title', "New Title"); - * - * @access public - * @param string $path Array path - * @param mixed $value Value to set - * @return void - */ - public static function updateCurrentEntryField(string $path, $value) : void - { - Arr::set(Entries::$entry, $path, $value); - } - /** * Get entry * @@ -402,33 +281,4 @@ class Entries return $_entry; } } - - /** - * Display current entry - * - * @access private - * @return void - */ - private static function displayCurrentEntry() : void - { - Http::setRequestHeaders('Content-Type: text/html; charset=' . Registry::get('settings.charset')); - Themes::view(empty(Entries::$entry['template']) ? 'templates/default' : 'templates/' . Entries::$entry['template']) - ->assign('entry', Entries::$entry, true) - ->display(); - } - - /** - * Get the Content instance. - * - * @access public - * @return object - */ - public static function getInstance() - { - if (is_null(Entries::$instance)) { - Entries::$instance = new self; - } - - return Entries::$instance; - } } diff --git a/flextype/Flextype.php b/flextype/Flextype.php index eef334fb..7a878fdd 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -105,8 +105,8 @@ class Flextype // Get Plugins Instance Plugins::getInstance(); - // Get Entries Instance - Entries::getInstance(); + // Get Site Instance + Site::getInstance(); // Flush (send) the output buffer and turn off output buffering ob_end_flush(); diff --git a/flextype/Site.php b/flextype/Site.php new file mode 100644 index 00000000..780b59d3 --- /dev/null +++ b/flextype/Site.php @@ -0,0 +1,170 @@ + + * @link http://flextype.org + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flextype; + +use Flextype\Component\Http\Http; +use Flextype\Component\Event\Event; +use Flextype\Component\Registry\Registry; + +class Site +{ + /** + * An instance of the Site class + * + * @var object + * @access private + */ + private static $instance = null; + + /** + * Current site entry data array + * + * @var array + * @access private + */ + private static $entry = []; + + /** + * Private clone method to enforce singleton behavior. + * + * @access private + */ + private function __clone() + { + } + + /** + * Private wakeup method to enforce singleton behavior. + * + * @access private + */ + private function __wakeup() + { + } + + /** + * Private construct method to enforce singleton behavior. + * + * @access private + */ + private function __construct() + { + Site::init(); + } + + /** + * Init Entry + * + * @access private + * @return void + */ + private static function init() : void + { + Site::processCurrentPage(); + } + + /** + * Process Current Page + * + * @access private + * @return void + */ + private static function processCurrentPage() : void + { + // Event: The entry is not processed and not sent to the display. + Event::dispatch('onCurrentEntryBeforeProcessed'); + + // Set current requested entry data to global $entry array + Site::$entry = Entries::getEntry(Http::getUriString()); + + // Event: The entry has been fully processed and not sent to the display. + Event::dispatch('onCurrentEntryBeforeDisplayed'); + + // Display entry for current requested url + Site::displayCurrentPage(); + + // Event: The entry has been fully processed and sent to the display. + Event::dispatch('onCurrentEntryAfterProcessed'); + } + + /** + * Get current entry + * + * $entry = Site::getCurrentEntry(); + * + * @access public + * @return array + */ + public static function getCurrentEntry() : array + { + return Site::$entry; + } + + /** + * Update current entry + * + * Site::updateCurrentEntry(['title' => "New Title"]); + * + * @access public + * @param array $data Data + * @return void + */ + public static function updateCurrentEntry(array $data) : void + { + Site::$entry = $data; + } + + /** + * Update current entry field + * + * Site::updateCurrentEntryField('title', "New Title"); + * + * @access public + * @param string $path Array path + * @param mixed $value Value to set + * @return void + */ + public static function updateCurrentEntryField(string $path, $value) : void + { + Arr::set(Site::$entry, $path, $value); + } + + /** + * Display Current Page + * + * @access private + * @return void + */ + private static function displayCurrentPage() : void + { + Http::setRequestHeaders('Content-Type: text/html; charset=' . Registry::get('settings.charset')); + Themes::view(empty(Site::$entry['template']) ? 'templates/default' : 'templates/' . Site::$entry['template']) + ->assign('entry', Site::$entry, true) + ->display(); + } + + /** + * Get the Content instance. + * + * @access public + * @return object + */ + public static function getInstance() + { + if (is_null(Site::$instance)) { + Site::$instance = new self; + } + + return Site::$instance; + } +}