PSR4 Automatic Loading Specification https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-4-autoloader-cn.md
We put third parties in the vendor directory using the PSR Standard class library
Modify the AutoLoad function
12345678910111213141516171819202122 |
//psr
if
(!
empty
(
$GLOBALS
[
‘_UCT‘
][
‘autoload_psr‘
])) {
//namespace
if
(false !==
strpos
(
$class_name
,
‘\\‘
)) {
$dir =
str_replace
(
‘\\‘
, DS, ltrim(
$class_name
,
‘\\‘
)).
‘.php‘
;
}
else
{
$dir
=
str_replace
(
‘_‘
, DS,
$class_name
).
‘.php‘
;
}
foreach (
$GLOBALS
[
‘_UCT‘
][
‘autoload_psr‘
]
as
$vendor
) {
if
(!
strncmp
(
$vendor
.DS,
$dir
,
strlen
(
$vendor
) + 1)) {
$f
= UCT_PATH .
‘vendor‘
. DS .
$dir
;
}
else
{
$f
= UCT_PATH .
‘vendor‘
. DS .
$vendor
. DS .
$dir
;
}
if
(
file_exists
(
$f
)) {
return
include
$f
;
}
}
}
|
Referencing third-party class libraries
123456789101112131415 |
function
uct_use_vendor(
$vendor
) {
if
(
empty
(
$GLOBALS
[
‘_UCT‘
][
‘autoload_psr‘
])) {
$GLOBALS
[
‘_UCT‘
][
‘autoload_psr‘
] =
array
(
$vendor
);
return
true;
}
if
(!in_array(
$vendor
,
$GLOBALS
[
‘_UCT‘
][
‘autoload_psr‘
])) {
//$GLOBALS[‘_UCT‘][‘autoload_psr‘][] = $app;
array_unshift
(
$GLOBALS
[
‘_UCT‘
][
‘autoload_psr‘
],
$vendor
);
return
true;
}
return
false;
}
|
How to implement a PHP Framework series article "3" Support PSR4 auto-load class