|
4 | 4 |
|
5 | 5 | namespace Phpfastcache\Autoload;
|
6 | 6 |
|
| 7 | +use Composer\Autoload\ClassLoader; |
7 | 8 | /**
|
8 | 9 | *
|
9 | 10 | * This file is part of phpFastCache.
|
|
21 | 22 | const PFC_BIN_DIR = __DIR__ . '/../../../bin/';
|
22 | 23 | const PFC_LIB_DIR = __DIR__ . '/../../../lib/';
|
23 | 24 |
|
| 25 | +\trigger_error('The legacy autoload will be removed in the next major release. Please include Phpfastcache through composer by running `composer require phpfastcache/phpfastcache`.', \E_USER_DEPRECATED); |
24 | 26 | /**
|
25 | 27 | * Register Autoload
|
26 | 28 | */
|
27 | 29 | spl_autoload_register(
|
28 | 30 | static function ($entity): void {
|
29 | 31 | $module = explode('\\', $entity, 2);
|
30 |
| - if (!in_array($module[0], ['Phpfastcache', 'Psr'])) { |
| 32 | + if (!\in_array($module[0], ['Phpfastcache', 'Psr'])) { |
31 | 33 | /**
|
32 | 34 | * Not a part of phpFastCache file
|
33 | 35 | * then we return here.
|
34 | 36 | */
|
35 | 37 | return;
|
36 | 38 | }
|
37 | 39 |
|
38 |
| - if (strpos($entity, 'Psr\Cache') === 0) { |
| 40 | + if (\strpos($entity, 'Psr\Cache') === 0) { |
39 | 41 | $path = PFC_BIN_DIR . 'dependencies/Psr/Cache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
|
40 | 42 |
|
41 |
| - if (is_readable($path)) { |
| 43 | + if (\is_readable($path)) { |
42 | 44 | require_once $path;
|
43 | 45 | } else {
|
44 |
| - trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR); |
| 46 | + \trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR); |
45 | 47 | }
|
46 | 48 | return;
|
47 | 49 | }
|
48 | 50 |
|
49 |
| - if (strpos($entity, 'Psr\SimpleCache') === 0) { |
50 |
| - $path = PFC_BIN_DIR . 'dependencies/Psr/SimpleCache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT; |
| 51 | + if (\strpos($entity, 'Psr\SimpleCache') === 0) { |
| 52 | + $path = PFC_BIN_DIR . 'dependencies/Psr/SimpleCache/src/' . \substr(\strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT; |
51 | 53 |
|
52 |
| - if (is_readable($path)) { |
| 54 | + if (\is_readable($path)) { |
53 | 55 | require_once $path;
|
54 | 56 | } else {
|
55 |
| - trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR); |
| 57 | + \trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR); |
56 | 58 | }
|
57 | 59 | return;
|
58 | 60 | }
|
59 | 61 |
|
60 | 62 | $entity = str_replace('\\', '/', $entity);
|
61 | 63 | $path = PFC_LIB_DIR . $entity . '.' . PFC_PHP_EXT;
|
62 | 64 |
|
63 |
| - if (is_readable($path)) { |
| 65 | + if (\is_readable($path)) { |
64 | 66 | require_once $path;
|
65 | 67 | }
|
66 | 68 | }
|
67 | 69 | );
|
68 | 70 |
|
69 |
| -if ((!defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && class_exists(ClassLoader::class)) { |
| 71 | +if ((!\defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && \class_exists(ClassLoader::class)) { |
70 | 72 | trigger_error(
|
71 | 73 | 'Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.',
|
72 | 74 | E_USER_WARNING
|
|
0 commit comments