diff --git a/libraries/src/Application/CMSApplication.php b/libraries/src/Application/CMSApplication.php index 7fc111d47e9bf..3a5eab5946f48 100644 --- a/libraries/src/Application/CMSApplication.php +++ b/libraries/src/Application/CMSApplication.php @@ -104,10 +104,10 @@ abstract class CMSApplication extends WebApplication implements ContainerAwareIn /** * The pathway object * - * @var Pathway + * @var Pathway[] * @since __DEPLOY_VERSION__ */ - protected $pathway = null; + protected $pathway = []; /** * Class constructor. @@ -603,12 +603,19 @@ public function getPathway($name = null) $name = $this->getName(); } - if (!$this->pathway) + $name = strtolower($name); + + if (!array_key_exists($name . 'pathway', $this->pathway)) { - $this->pathway = $this->getContainer()->get(ucfirst($name) . 'Pathway'); + if (!$this->getContainer()->has(ucfirst($name) . 'Pathway')) + { + throw new \RuntimeException(\JText::sprintf('JLIB_APPLICATION_ERROR_PATHWAY_LOAD', $name), 500); + } + + $this->pathway[$name . 'pathway'] = $this->getContainer()->get(ucfirst($name) . 'Pathway'); } - return $this->pathway; + return $this->pathway[$name . 'pathway']; } /** diff --git a/libraries/src/Service/Provider/Pathway.php b/libraries/src/Service/Provider/Pathway.php index a57326aca19aa..afda0d586ec85 100644 --- a/libraries/src/Service/Provider/Pathway.php +++ b/libraries/src/Service/Provider/Pathway.php @@ -11,6 +11,7 @@ defined('JPATH_PLATFORM') or die; use Joomla\CMS\Application\SiteApplication; +use Joomla\CMS\Pathway\Pathway as GlobalPathway; use Joomla\CMS\Pathway\SitePathway; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; @@ -44,5 +45,17 @@ function (Container $container) }, true ); + + $container->alias('Pathway', GlobalPathway::class) + ->alias('JPathway', GlobalPathway::class) + ->alias('pathway', GlobalPathway::class) + ->share( + GlobalPathway::class, + function (Container $container) + { + return new GlobalPathway; + }, + true + ); } } diff --git a/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php b/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php index 9f20399ff933d..face9dfb45814 100644 --- a/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php +++ b/tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php @@ -105,8 +105,12 @@ public function setUp() $config = new Registry; $config->set('session', false); + $container = new \Joomla\DI\Container; + $pathwayProvider = new \Joomla\CMS\Service\Provider\Pathway; + $pathwayProvider->register($container); + // Get a new JApplicationCmsInspector instance. - $this->class = new JApplicationCmsInspector($this->getMockInput(), $config); + $this->class = new JApplicationCmsInspector($this->getMockInput(), $config, null, $container); $this->class->setSession(JFactory::$session); $this->class->setDispatcher($this->getMockDispatcher()); diff --git a/tests/unit/suites/libraries/cms/application/JApplicationSiteTest.php b/tests/unit/suites/libraries/cms/application/JApplicationSiteTest.php index ca4ef62f8593b..3ffe95f27fecd 100644 --- a/tests/unit/suites/libraries/cms/application/JApplicationSiteTest.php +++ b/tests/unit/suites/libraries/cms/application/JApplicationSiteTest.php @@ -102,10 +102,16 @@ public function setUp() $config = new Registry; $config->set('session', false); + $container = new \Joomla\DI\Container; + $pathwayProvider = new \Joomla\CMS\Service\Provider\Pathway; + $pathwayProvider->register($container); + // Get a new JApplicationSite instance. $this->class = new JApplicationSite($this->getMockInput(), $config); $this->class->setSession(JFactory::$session); $this->class->setDispatcher($this->getMockDispatcher()); + $container->set('Joomla\CMS\Application\SiteApplication', $this->class); + $this->class->setContainer($container); TestReflection::setValue('JApplicationCms', 'instances', array('site' => $this->class)); JFactory::$application = $this->class;