[refactoring] renaming initialize() and initializeAction() methods to run() to correspond with router naming
parent
8505a34292
commit
ffd9cfc6c8
|
@ -143,19 +143,19 @@ abstract class AbstractController extends ContainerAware implements ControllerIn
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the controller.
|
* Run the controller.
|
||||||
*
|
*
|
||||||
* @param string $action if NULL, the action will be retrieved from user input (GET/POST)
|
* @param string $action if NULL, the action will be retrieved from user input (GET/POST)
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function initialize($action = null) {
|
public function run($action = null) {
|
||||||
if($action === null) {
|
if($action === null) {
|
||||||
$action = psm_GET('action', psm_POST('action', $this->action_default));
|
$action = psm_GET('action', psm_POST('action', $this->action_default));
|
||||||
}
|
}
|
||||||
$this->xhr = (bool) psm_GET('xhr', psm_POST('xhr', false));
|
$this->xhr = (bool) psm_GET('xhr', psm_POST('xhr', false));
|
||||||
|
|
||||||
if(!in_array($action, $this->actions) || !($result = $this->initializeAction($action))) {
|
if(!in_array($action, $this->actions) || !($result = $this->runAction($action))) {
|
||||||
$result = $this->initializeAction($this->action_default);
|
$result = $this->runAction($this->action_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($result instanceof Response) {
|
if($result instanceof Response) {
|
||||||
|
@ -173,7 +173,7 @@ abstract class AbstractController extends ContainerAware implements ControllerIn
|
||||||
* @param string $action
|
* @param string $action
|
||||||
* @return mixed FALSE when action couldnt be initialized, response otherwise
|
* @return mixed FALSE when action couldnt be initialized, response otherwise
|
||||||
*/
|
*/
|
||||||
protected function initializeAction($action) {
|
protected function runAction($action) {
|
||||||
if(isset($this->user_level_required_actions[$action])) {
|
if(isset($this->user_level_required_actions[$action])) {
|
||||||
if($this->getUser()->getUserLevel() > $this->user_level_required_actions[$action]) {
|
if($this->getUser()->getUserLevel() > $this->user_level_required_actions[$action]) {
|
||||||
// user is not allowed to access this action..
|
// user is not allowed to access this action..
|
||||||
|
|
|
@ -196,7 +196,7 @@ class ConfigController extends AbstractController {
|
||||||
$this->default_tab = 'pushover';
|
$this->default_tab = 'pushover';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->initializeAction('index');
|
return $this->runAction('index');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,9 +35,9 @@ interface ControllerInterface extends ContainerAwareInterface {
|
||||||
public function __construct(Database $db, \Twig_Environment $twig);
|
public function __construct(Database $db, \Twig_Environment $twig);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the module
|
* Run the controller
|
||||||
*/
|
*/
|
||||||
public function initialize();
|
public function run();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the minimum required user level for this controller
|
* Get the minimum required user level for this controller
|
||||||
|
|
|
@ -170,7 +170,7 @@ class ServerController extends AbstractServerController {
|
||||||
$edit_server = $this->getServers($this->server_id);
|
$edit_server = $this->getServers($this->server_id);
|
||||||
if(empty($edit_server)) {
|
if(empty($edit_server)) {
|
||||||
$this->addMessage(psm_get_lang('servers', 'error_server_no_match'), 'error');
|
$this->addMessage(psm_get_lang('servers', 'error_server_no_match'), 'error');
|
||||||
return $this->initializeAction('index');
|
return $this->runAction('index');
|
||||||
}
|
}
|
||||||
$tpl_data['titlemode'] = psm_get_lang('system', 'edit') . ' ' . $edit_server['label'];
|
$tpl_data['titlemode'] = psm_get_lang('system', 'edit') . ' ' . $edit_server['label'];
|
||||||
|
|
||||||
|
@ -298,9 +298,9 @@ class ServerController extends AbstractServerController {
|
||||||
|
|
||||||
$back_to = isset($_GET['back_to']) ? $_GET['back_to'] : 'index';
|
$back_to = isset($_GET['back_to']) ? $_GET['back_to'] : 'index';
|
||||||
if($back_to == 'view') {
|
if($back_to == 'view') {
|
||||||
return $this->initializeAction('view');
|
return $this->runAction('view');
|
||||||
} else {
|
} else {
|
||||||
return $this->initializeAction('index');
|
return $this->runAction('index');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ class ServerController extends AbstractServerController {
|
||||||
}
|
}
|
||||||
$this->addMessage(psm_get_lang('servers', 'deleted'), 'success');
|
$this->addMessage(psm_get_lang('servers', 'deleted'), 'success');
|
||||||
}
|
}
|
||||||
return $this->initializeAction('index');
|
return $this->runAction('index');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -329,12 +329,12 @@ class ServerController extends AbstractServerController {
|
||||||
*/
|
*/
|
||||||
protected function executeView() {
|
protected function executeView() {
|
||||||
if($this->server_id == 0) {
|
if($this->server_id == 0) {
|
||||||
return $this->initializeAction('index');
|
return $this->runAction('index');
|
||||||
}
|
}
|
||||||
$server = $this->getServers($this->server_id);
|
$server = $this->getServers($this->server_id);
|
||||||
|
|
||||||
if(empty($server)) {
|
if(empty($server)) {
|
||||||
return $this->initializeAction('index');
|
return $this->runAction('index');
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl_data = $this->getLabels();
|
$tpl_data = $this->getLabels();
|
||||||
|
|
|
@ -47,14 +47,14 @@ class UserController extends AbstractController {
|
||||||
$this->twig->addGlobal('subtitle', psm_get_lang('menu', 'user'));
|
$this->twig->addGlobal('subtitle', psm_get_lang('menu', 'user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initialize() {
|
public function run() {
|
||||||
$servers = $this->db->select(PSM_DB_PREFIX.'servers', null, array('server_id', 'label'), '', "ORDER BY `active` ASC, `status` DESC, `label` ASC");
|
$servers = $this->db->select(PSM_DB_PREFIX.'servers', null, array('server_id', 'label'), '', "ORDER BY `active` ASC, `status` DESC, `label` ASC");
|
||||||
// change the indexes to reflect their server ids
|
// change the indexes to reflect their server ids
|
||||||
foreach($servers as $server) {
|
foreach($servers as $server) {
|
||||||
$this->servers[$server['server_id']] = $server;
|
$this->servers[$server['server_id']] = $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::initialize();
|
return parent::run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,7 +33,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The router class opens the controller and initializes the module.
|
* The router class opens the controller and runs the module.
|
||||||
*
|
*
|
||||||
* It uses a so-called $mod param to determine which controller to load.
|
* It uses a so-called $mod param to determine which controller to load.
|
||||||
* The $mod of run() has 2 components, separated by an underscore. The first part determines
|
* The $mod of run() has 2 components, separated by an underscore. The first part determines
|
||||||
|
@ -96,7 +96,7 @@ class Router {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = $controller->initialize($action);
|
$response = $controller->run($action);
|
||||||
|
|
||||||
if(!($response instanceof Response)) {
|
if(!($response instanceof Response)) {
|
||||||
throw new \LogicException('Controller did not return a Response object.');
|
throw new \LogicException('Controller did not return a Response object.');
|
||||||
|
|
Loading…
Reference in New Issue