Skip to content

Commit

Permalink
Issue #5114 class conflict handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Nov 24, 2023
1 parent 56edcd5 commit 9461602
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
27 changes: 19 additions & 8 deletions e107_handlers/e107_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class e107
'language' => '{e_HANDLER}language_class.php',
'news' => '{e_HANDLER}news_class.php',
'notify' => '{e_HANDLER}notify_class.php',
'e107\override' => '{e_HANDLER}override_class.php',
'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 @@ -272,6 +272,15 @@ class e107
'pageHelper' => '{e_PLUGIN}page/includes/pageHelper.php'
);

/**
* List of core classes using the 'e107' namespace.
*/
protected static $_named_handlers = [
'override' => true,

];



/**
* Overload core handlers array
Expand Down Expand Up @@ -994,7 +1003,9 @@ function getSitePath()
*/
public static function getHandlerPath($class_name, $parse_path = true)
{

$ret = isset(self::$_known_handlers[$class_name]) ? self::$_known_handlers[$class_name] : null;

if($parse_path && $ret)
{
$ret = self::getParser()->replaceConstants($ret);
Expand Down Expand Up @@ -1040,7 +1051,7 @@ public static function isHandler($class_name)

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

/**
Expand Down Expand Up @@ -1141,6 +1152,11 @@ public static function getSingleton($class_name, $path = true, $regpath = '',$va
}
}

if($named = self::isHandlerNamespaced($class_name))
{
$class_name = $named;
}

if($path && is_string($path) && !class_exists($class_name, false))
{
global $_E107;
Expand All @@ -1158,13 +1174,8 @@ public static function getSingleton($class_name, $path = true, $regpath = '',$va
//e107_require_once() is available without class2.php. - see core_functions.php
}


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

try
{
Expand Down Expand Up @@ -1965,7 +1976,7 @@ public static function getNotify()
/**
* Retrieve override handler singleton object
*
* @return override
* @return e107\override
*/
public static function getOverride()
{
Expand Down
9 changes: 9 additions & 0 deletions e107_tests/tests/unit/e107Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,20 @@ public function testGetSingleton()
{
$e107 = $this->e107;

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

$this->assertNotEmpty($result, 'Override class not loaded');

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

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

// Test without path.
$result2 = $e107::getOverride();
$exists2 = method_exists($result2, 'override_check');
$this->assertTrue($exists2, 'Failed to load override class singleton');

}

/*
Expand Down

0 comments on commit 9461602

Please sign in to comment.