Skip to content

Commit

Permalink
Issue #5114 - Prevent override class conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Nov 24, 2023
1 parent 98eaf0c commit 56edcd5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
36 changes: 34 additions & 2 deletions e107_handlers/e107_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
if (!defined('e107_INIT')) { exit; }



/**
*
* @package e107
Expand Down Expand Up @@ -153,6 +154,8 @@ class e107

protected static $_breadcrumb = array();



/**
* Core handlers array
* For new/missing handler add
Expand Down Expand Up @@ -250,7 +253,7 @@ class e107
'language' => '{e_HANDLER}language_class.php',
'news' => '{e_HANDLER}news_class.php',
'notify' => '{e_HANDLER}notify_class.php',
'override' => '{e_HANDLER}override_class.php',
'e107\override' => '{e_HANDLER}override_class.php',
'rater' => '{e_HANDLER}rate_class.php',
'redirection' => '{e_HANDLER}redirection_class.php',
'secure_image' => '{e_HANDLER}secure_img_handler.php',
Expand All @@ -269,6 +272,7 @@ class e107
'pageHelper' => '{e_PLUGIN}page/includes/pageHelper.php'
);


/**
* Overload core handlers array
* Format: 'core_class' => array('overload_class', 'overload_path');
Expand Down Expand Up @@ -1034,6 +1038,11 @@ public static function isHandler($class_name)
return isset(self::$_known_handlers[$class_name]);
}

public static function isHandlerNamespaced($className)
{
return isset(self::$_known_handlers['e107\\'.$className]) ? '\\e107\\'.$className : false;
}

/**
* Get overlod class and path (if any)
*
Expand Down Expand Up @@ -1148,9 +1157,26 @@ public static function getSingleton($class_name, $path = true, $regpath = '',$va
// remove the need for external function.
//e107_require_once() is available without class2.php. - see core_functions.php
}


if(class_exists($class_name, false))
{
self::setRegistry($id, new $class_name($vars));
if($named = self::isHandlerNamespaced($class_name))
{
$class_name = $named;
}

try
{
$cls = is_null($vars) ? new $class_name() : new $class_name($vars);
}
catch (Exception $e)
{
trigger_error($e->getMessage());
return false;
}

self::setRegistry($id, $cls);
}

return self::getRegistry($id);
Expand Down Expand Up @@ -5932,12 +5958,18 @@ private static function autoload_namespaced($className)
return;
}



$levels[0] = e_HANDLER;
$classPath = implode('/', $levels).'.php';
if (is_file($classPath) && is_readable($classPath))
{
include($classPath);
}
elseif($filename = self::getHandlerPath($className))
{
include($filename);
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion e107_handlers/override_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* $Author$
*/

namespace e107;

if (!defined('e107_INIT')) { exit; }

/*
Expand All @@ -40,7 +42,7 @@ class override {
protected $functions = array();
protected $includes = array();



/**
* Replace an existing function or class method
Expand Down
12 changes: 9 additions & 3 deletions e107_tests/tests/unit/e107Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,19 @@ public function testIsHandlerOverloadable()
$res = null;
$this->assertTrue($res);
}
*/
public function testGetSingleton()
{
$res = null;
$this->assertTrue($res);
$e107 = $this->e107;

$result = $e107::getSingleton('override', e_HANDLER . 'override_class.php');

$exists = method_exists($result, 'override_check');

$this->assertTrue($exists, 'Failed to load override class singleton');
}

/*
public function testGetObject()
{
$res = null;
Expand Down

0 comments on commit 56edcd5

Please sign in to comment.