mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/10586] Change the interface to an abstract class
This allows the common phpBB objects to be automatically accessible to extensions without the author having to globalize and assign each one himself. This is better because it also gives purpose to the phpbb_extension_controller class; instead of just being the way to ensure a handle() method is present, it also does this work for us. PHPBB3-10586
This commit is contained in:
parent
7c3ebcc3ff
commit
cb7dabbffc
4 changed files with 87 additions and 33 deletions
85
phpBB/includes/extension/controller.php
Normal file
85
phpBB/includes/extension/controller.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package extension
|
||||||
|
* @copyright (c) 2011 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class extended by extension front controller classes
|
||||||
|
*
|
||||||
|
* @package extension
|
||||||
|
*/
|
||||||
|
abstract class phpbb_extension_controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var phpbb_request Request class object
|
||||||
|
*/
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var dbal DBAL class object
|
||||||
|
*/
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var user User class object
|
||||||
|
*/
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var phpbb_template Template class object
|
||||||
|
*/
|
||||||
|
protected $template;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array Config array
|
||||||
|
*/
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string PHP Extension
|
||||||
|
*/
|
||||||
|
protected $phpEx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Relative path to board root
|
||||||
|
*/
|
||||||
|
protected $phpbb_root_path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method that provides the common phpBB objects as inherited class
|
||||||
|
* properties for automatic availability in extension controllers
|
||||||
|
*/
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
global $request, $db, $user, $template, $config;
|
||||||
|
global $phpEx, $phpbb_root_path;
|
||||||
|
|
||||||
|
$this->request =& $request;
|
||||||
|
$this->db =& $db;
|
||||||
|
$this->user =& $user;
|
||||||
|
$this->template =& $template;
|
||||||
|
$this->config =& $config;
|
||||||
|
|
||||||
|
$this->phpEx = $phpEx;
|
||||||
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the request to display a page from an extension
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
abstract public function handle();
|
||||||
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package extension
|
|
||||||
* @copyright (c) 2011 phpBB Group
|
|
||||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
if (!defined('IN_PHPBB'))
|
|
||||||
{
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface that extension classes have to implement to run front pages
|
|
||||||
*
|
|
||||||
* @package extension
|
|
||||||
*/
|
|
||||||
interface phpbb_extension_controller_interface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* handle the request to display a page from an extension
|
|
||||||
*
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function handle();
|
|
||||||
}
|
|
|
@ -47,7 +47,7 @@ if ($ext = $request->variable('ext', ''))
|
||||||
|
|
||||||
$controller = new $class;
|
$controller = new $class;
|
||||||
|
|
||||||
if (!($controller instanceof phpbb_extension_controller_interface))
|
if (!($controller instanceof phpbb_extension_controller))
|
||||||
{
|
{
|
||||||
send_status_line(500, 'Internal Server Error');
|
send_status_line(500, 'Internal Server Error');
|
||||||
trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class));
|
trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class));
|
||||||
|
|
|
@ -186,7 +186,7 @@ $lang = array_merge($lang, array(
|
||||||
'EXPAND_VIEW' => 'Expand view',
|
'EXPAND_VIEW' => 'Expand view',
|
||||||
'EXTENSION' => 'Extension',
|
'EXTENSION' => 'Extension',
|
||||||
'EXTENSION_CONTROLLER_MISSING' => 'The extension <strong>%s</strong> is missing a controller class and cannot be accessed through the front-end.',
|
'EXTENSION_CONTROLLER_MISSING' => 'The extension <strong>%s</strong> is missing a controller class and cannot be accessed through the front-end.',
|
||||||
'EXTENSION_CLASS_WRONG_TYPE' => 'The extension controller class <strong>%s</strong> is not an instance of the phpbb_extension_controller_interface.',
|
'EXTENSION_CLASS_WRONG_TYPE' => 'The extension controller class <strong>%s</strong> is not an instance of the phpbb_extension_controller.',
|
||||||
'EXTENSION_DISABLED' => 'The extension <strong>%s</strong> is not enabled.',
|
'EXTENSION_DISABLED' => 'The extension <strong>%s</strong> is not enabled.',
|
||||||
'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension <strong>%s</strong> has been deactivated and can no longer be displayed.',
|
'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension <strong>%s</strong> has been deactivated and can no longer be displayed.',
|
||||||
'EXTENSION_DOES_NOT_EXIST' => 'The extension <strong>%s</strong> does not exist.',
|
'EXTENSION_DOES_NOT_EXIST' => 'The extension <strong>%s</strong> does not exist.',
|
||||||
|
|
Loading…
Add table
Reference in a new issue