Skip to content

Commit

Permalink
Require MVC factory
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Mar 6, 2018
1 parent b5cf8f3 commit eaa4c43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
11 changes: 5 additions & 6 deletions administrator/components/com_login/dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,23 @@ class LoginDispatcher extends Dispatcher
protected $namespace = 'Joomla\\Component\\Login';

/**
* Constructor for Dispatcher
* Dispatch a controller task.
*
* @param CMSApplication $app The application for the dispatcher
* @param \JInput $input The input object
* @return void
*
* @since 4.0.0
*/
public function __construct(CMSApplication $app, \JInput $input = null)
public function dispatch()
{
parent::__construct($app, $input);

// Only accept two values login and logout for `task`
$task = $this->input->get('task');

if ($task != 'login' && $task != 'logout')
{
$this->input->set('task', '');
}

parent::dispatch();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Component/ComponentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Access\Access;
use Joomla\CMS\Component\Exception\MissingComponentException;
use Joomla\CMS\MVC\Factory\MVCFactoryFactory;
use Joomla\Registry\Registry;
use Joomla\CMS\Dispatcher\DispatcherInterface;

Expand Down Expand Up @@ -368,7 +369,7 @@ public static function renderComponent($option, $params = array())
}

// Dispatch the component.
$contents = static::dispatchComponent(new $class($app, $app->input));
$contents = static::dispatchComponent(new $class($app, $app->input, new MVCFactoryFactory('Joomla\\Component\\' . ucwords($file))));
}
else
{
Expand Down
20 changes: 4 additions & 16 deletions libraries/src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ abstract class Dispatcher implements DispatcherInterface
*
* @param CMSApplication $app The application instance
* @param Input $input The input instance
* @param MVCFactoryFactoryInterface $mvcFactory The input instance
* @param MVCFactoryFactoryInterface $mvcFactory The MVC factory instance
*
* @since 4.0.0
*/
public function __construct(CMSApplication $app, Input $input = null, MVCFactoryFactoryInterface $mvcFactory = null)
public function __construct(CMSApplication $app, Input $input, MVCFactoryFactoryInterface $mvcFactory)
{
if (empty($this->namespace))
{
throw new \RuntimeException('Namespace can not be empty!');
}

$this->app = $app;
$this->input = $input ?: $app->input;
$this->input = $input;
$this->mvcFactory = $mvcFactory;

// If option is not provided, detect it from dispatcher class name, ie ContentDispatcher
Expand Down Expand Up @@ -216,20 +216,8 @@ public function getController(string $name, string $client = '', array $config =
throw new \InvalidArgumentException(\JText::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS', $controllerClass));
}

$factory = null;

// Will be removed when all dispatchers are converted
if ($this->mvcFactory)
{
$factory = $this->mvcFactory->createFactory($this->app);
}
else
{
$factory = $this->app->bootComponent($this->option)->createMVCFactory($this->app);
}

// Create the controller instance
$controller = new $controllerClass($config, $factory, $this->app, $this->input);
$controller = new $controllerClass($config, $this->mvcFactory->createFactory($this->app), $this->app, $this->input);

// Set the form factory when possible
if ($controller instanceof FormFactoryAwareInterface)
Expand Down

0 comments on commit eaa4c43

Please sign in to comment.