diff --git a/administrator/components/com_content/ContentDispatcher.php b/administrator/components/com_content/ContentDispatcher.php new file mode 100644 index 0000000000000..f2e55da18d113 --- /dev/null +++ b/administrator/components/com_content/ContentDispatcher.php @@ -0,0 +1,33 @@ +authorise('core.manage', 'com_content')) + { + throw new RuntimeException(JText::_('JERROR_ALERTNOAUTHOR'), 404); + } + + JHtml::_('behavior.tabstate'); + + JLoader::register('ContentHelper', __DIR__ . '/helpers/content.php'); + } +} diff --git a/administrator/components/com_content/content.php b/administrator/components/com_content/content.php deleted file mode 100644 index 38d2aa111f93a..0000000000000 --- a/administrator/components/com_content/content.php +++ /dev/null @@ -1,22 +0,0 @@ -authorise('core.manage', 'com_content')) -{ - return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); -} - -JLoader::register('ContentHelper', __DIR__ . '/helpers/content.php'); - -$controller = JControllerLegacy::getInstance('Content'); -$controller->execute(JFactory::getApplication()->input->get('task')); -$controller->redirect(); diff --git a/components/com_content/ContentDispatcher.php b/components/com_content/ContentDispatcher.php new file mode 100644 index 0000000000000..7973c23928032 --- /dev/null +++ b/components/com_content/ContentDispatcher.php @@ -0,0 +1,27 @@ +execute(JFactory::getApplication()->input->get('task')); -$controller->redirect(); diff --git a/libraries/cms.php b/libraries/cms.php index 88525f6d4a511..42089814cc4d6 100644 --- a/libraries/cms.php +++ b/libraries/cms.php @@ -29,6 +29,9 @@ // Register the library base path for CMS libraries. JLoader::registerPrefix('J', JPATH_PLATFORM . '/cms', false, true); +// Register the namespaced CMS core. +JLoader::registerNamespace('JoomlaCMS', JPATH_PLATFORM . '/core'); + // Add the Composer autoloader require_once JPATH_LIBRARIES . '/composer_autoload.php'; diff --git a/libraries/cms/component/helper.php b/libraries/cms/component/helper.php index 1b87717919e54..c97312e82ce04 100644 --- a/libraries/cms/component/helper.php +++ b/libraries/cms/component/helper.php @@ -345,7 +345,7 @@ public static function renderComponent($option, $params = array()) $path = JPATH_COMPONENT . '/' . $file . '.php'; // If component is disabled throw error - if (!static::isEnabled($option) || !file_exists($path)) + if (!static::isEnabled($option)) { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'), 404); } @@ -356,8 +356,34 @@ public static function renderComponent($option, $params = array()) // Handle template preview outlining. $contents = null; - // Execute the component. - $contents = static::executeComponent($path); + // Determine if the component uses the component DispatcherInterface or uses the legacy structure + $legacyComponent = file_exists($path); + + if ($legacyComponent) + { + // Legacy execute component + $contents = static::executeComponent($path); + } + else + { + // This may be a new component, check for the dispatcher + $className = ucfirst($file) . 'Dispatcher'; + + $path = JPATH_COMPONENT . '/' . $className . '.php'; + + if (!file_exists($path)) + { + throw new Exception(JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'), 404); + } + + require_once $path; + + // Boot the dispatcher + $dispatcher = new $className(JFactory::getApplication()); + + // And execute it + $contents = $dispatcher->execute(); + } // Revert the scope $app->scope = $scope; diff --git a/libraries/core/JoomlaCms/Component/AbstractDispatcher.php b/libraries/core/JoomlaCms/Component/AbstractDispatcher.php new file mode 100644 index 0000000000000..3d75ac626deba --- /dev/null +++ b/libraries/core/JoomlaCms/Component/AbstractDispatcher.php @@ -0,0 +1,85 @@ +application = $application; + + if (!$this->name) + { + $this->name = str_replace('Dispatcher', '', get_called_class()); + } + + $this->boot(); + } + + /** + * {@inheritdoc} + */ + public function boot() + { + // In the simplest implementation, we just return + return; + } + + /** + * {@inheritdoc} + */ + public function execute() + { + ob_start(); + $controller = \JControllerLegacy::getInstance($this->getName()); + $controller->execute($this->application->input->get('task')); + $controller->redirect(); + + $contents = ob_get_clean(); + + return $contents; + } + + /** + * Get the name of the component + * + * @return string + */ + public function getName() + { + if (!$this->name) + { + throw new \InvalidArgumentException('The component\'s name has not been set.'); + } + + return $this->name; + } +} diff --git a/libraries/core/JoomlaCms/Component/DispatcherInterface.php b/libraries/core/JoomlaCms/Component/DispatcherInterface.php new file mode 100644 index 0000000000000..11fd9cc674fcf --- /dev/null +++ b/libraries/core/JoomlaCms/Component/DispatcherInterface.php @@ -0,0 +1,33 @@ +