let's stop being php5.2 compatible

This commit is contained in:
Shish 2016-06-19 23:23:34 +01:00
parent 6febdec7b5
commit cb73a0caa0
2 changed files with 16 additions and 23 deletions

View file

@ -85,18 +85,13 @@ abstract class Extension {
/** @var array which DBs this ext supports (blank for 'all') */ /** @var array which DBs this ext supports (blank for 'all') */
protected $db_support = []; protected $db_support = [];
/** this theme's Themelet object */ /** @var Themelet this theme's Themelet object */
public $theme; public $theme;
// in PHP5.3, late static bindings can take care of this; __CLASS__ public function __construct() {
// used here will refer to the subclass $this->theme = $this->get_theme_object(get_called_class());
// http://php.net/manual/en/language.oop5.late-static-bindings.php
/** @private */
public function i_am(Extension $child) {
if(is_null($this->theme)) $this->theme = $this->get_theme_object($child, false);
} }
public function is_live() { public function is_live() {
global $database; global $database;
return ( return (
@ -108,21 +103,21 @@ abstract class Extension {
/** /**
* Find the theme object for a given extension. * Find the theme object for a given extension.
* *
* @param Extension $class * @param string $base
* @param bool $fatal * @return Themelet
* @return bool
*/ */
private function get_theme_object(Extension $class, $fatal=true) { private function get_theme_object($base) {
$base = get_class($class); $custom = 'Custom'.$base.'Theme';
if(class_exists('Custom'.$base.'Theme')) { $normal = $base.'Theme';
$class = 'Custom'.$base.'Theme';
return new $class(); if(class_exists($custom)) {
return new $custom();
} }
elseif ($fatal || class_exists($base.'Theme')) { elseif(class_exists($normal)) {
$class = $base.'Theme'; return new $normal();
return new $class(); }
} else { else {
return false; return null;
} }
} }

View file

@ -1429,7 +1429,6 @@ function _set_event_listeners() {
elseif(is_subclass_of($class, "Extension")) { elseif(is_subclass_of($class, "Extension")) {
/** @var Extension $extension */ /** @var Extension $extension */
$extension = new $class(); $extension = new $class();
$extension->i_am($extension);
// skip extensions which don't support our current database // skip extensions which don't support our current database
if(!$extension->is_live()) continue; if(!$extension->is_live()) continue;
@ -1460,7 +1459,6 @@ function _dump_event_listeners($event_listeners, $path) {
if($rclass->isAbstract()) {} if($rclass->isAbstract()) {}
elseif(is_subclass_of($class, "Extension")) { elseif(is_subclass_of($class, "Extension")) {
$p .= "\$$class = new $class(); "; $p .= "\$$class = new $class(); ";
$p .= "\${$class}->i_am(\$$class);\n";
} }
} }