Skip to content

Commit 7af2880

Browse files
committed
Improved autoload performances (reverted from commit beccf6e)
1 parent c7e19b6 commit 7af2880

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

src/autoload.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@
1616
define('PFC_BIN_DIR', __DIR__ . '/../bin/');
1717

1818
/**
19-
* Register PhpFastCache Autoload
20-
*/
21-
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__);
22-
spl_autoload_register();
23-
24-
/**
25-
* Register PhpFastCache
26-
* embedded-libraries Autoload
19+
* Register Autoload
2720
*/
2821
spl_autoload_register(function ($entity) {
29-
/**
30-
* Attempting to load Psr\Cache
31-
*/
32-
if (strpos($entity, 'Psr\Cache') === 0) {
22+
$module = explode('\\', $entity, 2);
23+
if (!in_array($module[ 0 ], ['phpFastCache', 'Psr'])) {
24+
/**
25+
* Not a part of phpFastCache file
26+
* then we return here.
27+
*/
28+
return;
29+
} else if (strpos($entity, 'Psr\Cache') === 0) {
3330
$path = PFC_BIN_DIR . 'legacy/Psr/Cache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
3431

3532
if (is_readable($path)) {
@@ -38,12 +35,7 @@
3835
trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR);
3936
}
4037
return;
41-
}
42-
43-
/**
44-
* Attempting to load Psr\SimpleCache
45-
*/
46-
if (strpos($entity, 'Psr\SimpleCache') === 0) {
38+
} else if (strpos($entity, 'Psr\SimpleCache') === 0) {
4739
$path = PFC_BIN_DIR . 'legacy/Psr/SimpleCache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
4840

4941
if (is_readable($path)) {
@@ -53,6 +45,13 @@
5345
}
5446
return;
5547
}
48+
49+
$entity = str_replace('\\', '/', $entity);
50+
$path = __DIR__ . '/' . $entity . '.' . PFC_PHP_EXT;
51+
52+
if (is_readable($path)) {
53+
require_once $path;
54+
}
5655
});
5756

5857
if ((!defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && class_exists('Composer\Autoload\ClassLoader')) {

tests/Autoload.test.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
$testHelper->printPassText('Autoload successfully found the CacheManager');
2121
}
2222

23-
/**
24-
* Testing Psr autoload
25-
*/
26-
if (!class_exists('phpFastCache\Drivers\Files\Driver')) {
27-
$testHelper->printFailText('Autoload failed to find the "files" driver');
28-
}else{
29-
$testHelper->printPassText('Autoload successfully found the "files" driver');
30-
}
31-
3223
/**
3324
* Testing Psr autoload
3425
*/

0 commit comments

Comments
 (0)