Skip to content

Commit

Permalink
[4.0] Add Controller suffix to extension controllers (#17624)
Browse files Browse the repository at this point in the history
* Add Controller suffix to extension controllers

* Support legacy classes
  • Loading branch information
laoneo authored and wilsonge committed Aug 24, 2017
1 parent 2dd9745 commit 70a6e43
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @since 1.6
*/
class Banner extends Form
class BannerController extends Form
{
/**
* The prefix to use with controller messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @since 1.6
*/
class Banners extends Admin
class BannersController extends Admin
{
/**
* The prefix to use with controller messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @since 1.6
*/
class Client extends Form
class ClientController extends Form
{
/**
* The prefix to use with controller messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @since 1.6
*/
class Clients extends Admin
class ClientsController extends Admin
{
/**
* The prefix to use with controller messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @since 1.6
*/
class Controller extends BaseController
class DisplayController extends BaseController
{
/**
* The default view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
defined('_JEXEC') or die;

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Controller\Controller as BaseController;
use Joomla\CMS\Controller\Controller;

/**
* Tracks list controller class.
*
* @since 1.6
*/
class Tracks extends BaseController
class TracksController extends Controller
{
/**
* The prefix to use with controller messages.
Expand Down
13 changes: 11 additions & 2 deletions libraries/src/Controller/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,21 @@ public function __construct($config = array(), MvcFactoryInterface $factory = nu
{
$r = null;

if (!preg_match('/(.*)Controller(.*)/i', get_class($this), $r))
$match = 'Controller';

// If there is a namespace append a backslash
if (strpos(get_class($this), '\\'))
{
$match .= '\\\\';
}

if (!preg_match('/(.*)' . $match . '(.*)/i', get_class($this), $r))
{
throw new \Exception(\JText::_('JLIB_APPLICATION_ERROR_CONTROLLER_GET_NAME'), 500);
}

$this->context = str_replace('\\', '', strtolower($r[2]));
// Remove the backslashes and the suffix controller
$this->context = str_replace(array('\\', 'controller'), '', strtolower($r[2]));
}

// Guess the item view as the context.
Expand Down
16 changes: 14 additions & 2 deletions libraries/src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function dispatch()
else
{
// Do we have a controller?
$controller = $this->input->get('controller', 'controller');
$controller = $this->input->get('controller', 'display');
$task = $command;
}

Expand Down Expand Up @@ -199,7 +199,19 @@ public function getController($name, $client = null, $config = array())
// Set up the client
$client = $client ? $client : ucfirst($this->app->getName());

$controllerClass = $namespace . $client . '\\Controller\\' . ucfirst($name);
$controllerClass = $namespace . $client . '\\Controller\\' . ucfirst($name) . 'Controller';

// @todo Remove me when core extensions are converted
if (!class_exists($controllerClass))
{
$controllerClass = $namespace . $client . '\\Controller\\' . ucfirst($name);
}

// @todo Remove me when core extensions are converted
if (!class_exists($controllerClass) && $name == 'display')
{
$controllerClass = $namespace . $client . '\\Controller\\Controller';
}

if (!class_exists($controllerClass))
{
Expand Down

0 comments on commit 70a6e43

Please sign in to comment.