Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions libraries/src/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ abstract class CMSApplication extends WebApplication implements ContainerAwareIn
*/
protected $template = null;

/**
* The pathway object
*
* @var Pathway
* @since __DEPLOY_VERSION__
*/
protected $pathway = null;

/**
* Class constructor.
*
Expand Down Expand Up @@ -580,23 +588,27 @@ public function getName()
}

/**
* Returns the application \JPathway object.
* Returns the application Pathway object.
*
* @param string $name The name of the application.
* @param array $options An optional associative array of configuration settings.
*
* @return Pathway
*
* @since 3.2
*/
public function getPathway($name = null, $options = array())
public function getPathway($name = null)
{
if (!isset($name))
{
$name = $this->getName();
}

return Pathway::getInstance($name, $options);
if (!$this->pathway)
{
$this->pathway = $this->getContainer()->get(ucfirst($name) . 'Pathway');
}

return $this->pathway;
}

/**
Expand Down
1 change: 1 addition & 0 deletions libraries/src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ protected static function createContainer(): Container
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Form)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Logger)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Menu)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Pathway)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Session)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Toolbar);

Expand Down
22 changes: 7 additions & 15 deletions libraries/src/Pathway/Pathway.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,26 @@ class Pathway
* Returns a Pathway object
*
* @param string $client The name of the client
* @param array $options An associative array of options
*
* @return Pathway A Pathway object.
*
* @since 1.5
* @throws \RuntimeException
* @since 1.5
* @throws \RuntimeException
* @deprecated 5.0 Get the instance from the application, eg. $application->getPathway()
*/
public static function getInstance($client, $options = array())
public static function getInstance($client)
{
if (empty(self::$instances[$client]))
{
// Create a Pathway object
$classname = 'JPathway' . ucfirst($client);
$name = ucfirst($client) . 'Pathway';

if (!class_exists($classname))
if (!\JFactory::getContainer()->has($name))
{
throw new \RuntimeException(\JText::sprintf('JLIB_APPLICATION_ERROR_PATHWAY_LOAD', $client), 500);
}

// Check for a possible service from the container otherwise manually instantiate the class
if (\JFactory::getContainer()->has($classname))
{
self::$instances[$client] = \JFactory::getContainer()->get($classname);
}
else
{
self::$instances[$client] = new $classname($options);
}
self::$instances[$client] = \JFactory::getContainer()->get($name);
}

return self::$instances[$client];
Expand Down
3 changes: 1 addition & 2 deletions libraries/src/Pathway/SitePathway.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ class SitePathway extends Pathway
/**
* Class constructor.
*
* @param array $options The class options.
* @param SiteApplication $app Application Object
*
* @since 1.5
*/
public function __construct($options = array(), SiteApplication $app = null)
public function __construct(SiteApplication $app = null)
{
$this->pathway = array();

Expand Down
48 changes: 48 additions & 0 deletions libraries/src/Service/Provider/Pathway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Service\Provider;

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Pathway\SitePathway;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

/**
* Service provider for the application's database dependency
*
* @since 4.0
*/
class Pathway implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0
*/
public function register(Container $container)
{
$container->alias('SitePathway', SitePathway::class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick. IMO container keys should either be class names or some kind of dot separated key like you use for Registry options. So this particular service should have one key and two aliases:

  • SitePathway::class (already in place)
  • JPathwaySite (legacy class name)
  • pathway.site (this is a pathway service and the second part of the key specifies a specific sub-object, this also does not block potential future use of a pathway key if we have other apps supporting one and in the future if we had it we'd add a pathway.administrator service).

->alias('JPathwaySite', SitePathway::class)
->alias('pathway.site', SitePathway::class)
->share(
SitePathway::class,
function (Container $container)
{
return new SitePathway($container->get(SiteApplication::class));
},
true
);
}
}