Skip to content

Commit

Permalink
Make Prado::using able to autoload traits defined as prado3 namespaces (
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlaltca authored Mar 15, 2023
1 parent 428aec7 commit 2025461
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions framework/Prado.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,20 @@ public static function using($namespace): void

if (isset(self::$_usings[$namespace]) ||
class_exists($namespace, false) ||
interface_exists($namespace, false)) {
interface_exists($namespace, false) ||
trait_exists($namespace, false)) {
return;
}

if (array_key_exists($namespace, self::$classMap)) {
// fast autoload a Prado3 class name
$phpNamespace = self::$classMap[$namespace];
if (class_exists($phpNamespace, true) || interface_exists($phpNamespace, true)) {
if (!class_exists($namespace) && !interface_exists($namespace)) {
if (class_exists($phpNamespace, true) ||
interface_exists($phpNamespace, true) ||
trait_exists($phpNamespace, true)) {
if (!class_exists($namespace) &&
!interface_exists($namespace) &&
!trait_exists($namespace)) {
class_alias($phpNamespace, $namespace);
}
return;
Expand All @@ -394,8 +399,12 @@ class_alias($phpNamespace, $namespace);
$path = $v . DIRECTORY_SEPARATOR . $namespace . self::CLASS_FILE_EXT;
if (file_exists($path)) {
$phpNamespace = '\\' . $k . '\\' . $namespace;
if (class_exists($phpNamespace, true) || interface_exists($phpNamespace, true)) {
if (!class_exists($namespace) && !interface_exists($namespace)) {
if (class_exists($phpNamespace, true) ||
interface_exists($phpNamespace, true) ||
trait_exists($phpNamespace, true)) {
if (!class_exists($namespace) &&
!interface_exists($namespace) &&
!trait_exists($namespace)) {
class_alias($phpNamespace, $namespace);
}
return;
Expand All @@ -407,13 +416,17 @@ class_alias($phpNamespace, $namespace);
if ($className === '*') { // a directory
self::$_usings[substr($namespace, 0, $pos)] = $path;
} else { // a file
if (class_exists($className, false) || interface_exists($className, false)) {
if (class_exists($className, false) ||
interface_exists($className, false) ||
trait_exists($className, false)) {
return;
}

if (file_exists($path)) {
include_once($path);
if (!class_exists($className, false) && !interface_exists($className, false)) {
if (!class_exists($className, false) &&
!interface_exists($className, false) &&
!trait_exists($className, false)) {
class_alias($namespace, $className);
}
}
Expand Down

0 comments on commit 2025461

Please sign in to comment.