Skip to content

Commit

Permalink
FIX Conflict with autoload (#30399)
Browse files Browse the repository at this point in the history
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
  • Loading branch information
fcharlaix-opendsi and eldy authored Jul 17, 2024
1 parent 50646e7 commit 4479b1e
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ private function loadLastResort($className, $loader = null)
return $this->loadThisLoader($className, $loader);
}
foreach ($loaders as $loader)
if (false !== $file = $this->loadThisLoader($className, $loader))
return $file;
if (false !== $file = $this->loadThisLoader($className, $loader))
return $file;

return false;
}
Expand All @@ -285,23 +285,52 @@ private function loadLastResort($className, $loader = null)
*/
private function loadThisLoader($className, $loader)
{
if (is_array($loader)
&& is_callable($loader)) {
$b = new $loader[0];
//avoid PHP Fatal error: Uncaught Error: Access to undeclared static property: Composer\\Autoload\\ClassLoader::$loader
//in case of multiple autoloader systems
if (property_exists($b, $loader[1])) {
if (false !== $file = $b::$loader[1]($className)
&& $this->exists($className, $b::$loader[1])) {
return $file;
}
}
} elseif (is_callable($loader)
&& false !== $file = $loader($className)
&& $this->exists($className, $loader)) {
return $file;
}
return false;

/* other code tested to reduce autoload conflict
$s = '';
if (is_array($loader)
&& is_callable($loader)) {
// @CHANGE DOL avoid autoload conflict
if (!preg_match('/LuraCast/', get_class($loader[0]))) {
return false;
}
$b = new $loader[0];
//avoid PHP Fatal error: Uncaught Error: Access to undeclared static property: Composer\\Autoload\\ClassLoader::$loader
// @CHANGE DOL avoid PHP Fatal error: Uncaught Error: Access to undeclared static property: Composer\\Autoload\\ClassLoader::$loader
//in case of multiple autoloader systems
if (property_exists($b, $loader[1])) {
if (false !== $file = $b::$loader[1]($className)
&& $this->exists($className, $b::$loader[1])) {
return $file;
}
&& $this->exists($className, $b::$loader[1])) {
return $file;
}
}
} elseif (is_callable($loader, false, $s)) {
// @CHANGE DOL avoid PHP infinite loop (detected when xdebug is on)
if ($s == 'Luracast\Restler\AutoLoader::__invoke') {
return false;
}
if (false !== ($file = $loader($className)) && $this->exists($className, $loader)) {
return $file;
}
} elseif (is_callable($loader)
&& false !== $file = $loader($className)
&& $this->exists($className, $loader)) {
return $file;
}
return false;
*/
}

/**
Expand Down Expand Up @@ -417,7 +446,7 @@ public function __invoke($className)
if (false !== $includeReference = $this->discover($className))
return $includeReference;

static::thereCanBeOnlyOne();
//static::thereCanBeOnlyOne();

if (false !== $includeReference = $this->loadAliases($className))
return $includeReference;
Expand All @@ -426,7 +455,7 @@ public function __invoke($className)
return $includeReference;

if (false !== $includeReference = $this->loadLastResort($className))
return $includeReference;
return $includeReference;

static::seen($className, true);
return null;
Expand Down

0 comments on commit 4479b1e

Please sign in to comment.