Skip to content

Commit

Permalink
Use CMSWebApplicationInterface in controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Jan 4, 2022
1 parent e1541bd commit 6d1889e
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 84 deletions.
34 changes: 23 additions & 11 deletions libraries/src/MVC/Controller/AdminController.php
Expand Up @@ -10,7 +10,7 @@

\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Application\CMSWebApplicationInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
Expand All @@ -30,6 +30,14 @@
*/
class AdminController extends BaseController
{
/**
* The Application. Redeclared to show this class requires a web application.
*
* @var CMSWebApplicationInterface
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* The URL option for the component.
*
Expand Down Expand Up @@ -57,16 +65,17 @@ class AdminController extends BaseController
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The Application for the dispatcher
* @param Input $input The Input object for the request
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task',
* 'model_path', and 'view_path' (this list is not meant to be
* comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSWebApplicationInterface $app The Application for the dispatcher
* @param Input $input The Input object for the request
*
* @since 3.0
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null)
public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSWebApplicationInterface $app = null, ?Input $input = null)
{
parent::__construct($config, $factory, $app, $input);

Expand Down Expand Up @@ -135,7 +144,7 @@ public function delete()

if (!\is_array($cid) || \count($cid) < 1)
{
$this->app->getLogger()->warning(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), array('category' => 'jerror'));
$this->getLogger()->warning(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), array('category' => 'jerror'));
}
else
{
Expand Down Expand Up @@ -202,7 +211,7 @@ public function publish()

if (empty($cid))
{
$this->app->getLogger()->warning(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), array('category' => 'jerror'));
$this->getLogger()->warning(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), array('category' => 'jerror'));
}
else
{
Expand All @@ -223,7 +232,10 @@ public function publish()
{
if ($errors)
{
$this->app->enqueueMessage(Text::plural($this->text_prefix . '_N_ITEMS_FAILED_PUBLISHING', \count($cid)), 'error');
$this->app->enqueueMessage(
Text::plural($this->text_prefix . '_N_ITEMS_FAILED_PUBLISHING', \count($cid)),
CMSWebApplicationInterface::MSG_ERROR
);
}
else
{
Expand Down
27 changes: 18 additions & 9 deletions libraries/src/MVC/Controller/ApiController.php
Expand Up @@ -11,7 +11,7 @@
\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Application\CMSWebApplicationInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
Expand All @@ -33,6 +33,14 @@
*/
class ApiController extends BaseController
{
/**
* The Application. Redeclared to show this class requires a web application.
*
* @var CMSWebApplicationInterface
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* The content type of the item.
*
Expand Down Expand Up @@ -82,17 +90,18 @@ class ApiController extends BaseController
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The Application for the dispatcher
* @param Input $input Input
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task',
* 'model_path', and 'view_path' (this list is not meant to be
* comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSWebApplicationInterface $app The Application for the dispatcher
* @param Input $input Input
*
* @since 4.0.0
* @throws \Exception
* @since 4.0.0
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null)
public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSWebApplicationInterface $app = null, ?Input $input = null)
{
$this->modelState = new CMSObject;

Expand Down

0 comments on commit 6d1889e

Please sign in to comment.