Skip to content

Commit bfbc107

Browse files
committed
Deprecated legacy autoload
1 parent c13f666 commit bfbc107

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
- Removed deprecated config option `$ignoreSymfonyNotice`
1818
- Removed "fallback" feature (use aggregated cluster Master/Slave instead)
1919
- Enforced PSR-12 compliance
20+
- Deprecated legacy autoload for removal in next major release

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ echo implode('<br />', $CachedString->get());// Will echo your product list
332332
```
333333

334334
##### :floppy_disk: Legacy support (Without Composer)
335-
* See the file examples/withoutComposer.php for more information.
335+
~~* See the file examples/withoutComposer.php for more information.~~
336+
:warning: The legacy autoload will be removed in the next major release :warning:
337+
Please include Phpfastcache through composer by running `composer require phpfastcache/phpfastcache`.
336338

337339
#### :zap: Step 3: Enjoy ! Your website is now faster than lightning !
338340
For curious developers, there is a lot of other examples available [here](./docs/examples).

lib/Phpfastcache/Autoload/Autoload.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Phpfastcache\Autoload;
66

7+
use Composer\Autoload\ClassLoader;
78
/**
89
*
910
* This file is part of phpFastCache.
@@ -21,52 +22,53 @@
2122
const PFC_BIN_DIR = __DIR__ . '/../../../bin/';
2223
const PFC_LIB_DIR = __DIR__ . '/../../../lib/';
2324

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);
2426
/**
2527
* Register Autoload
2628
*/
2729
spl_autoload_register(
2830
static function ($entity): void {
2931
$module = explode('\\', $entity, 2);
30-
if (!in_array($module[0], ['Phpfastcache', 'Psr'])) {
32+
if (!\in_array($module[0], ['Phpfastcache', 'Psr'])) {
3133
/**
3234
* Not a part of phpFastCache file
3335
* then we return here.
3436
*/
3537
return;
3638
}
3739

38-
if (strpos($entity, 'Psr\Cache') === 0) {
40+
if (\strpos($entity, 'Psr\Cache') === 0) {
3941
$path = PFC_BIN_DIR . 'dependencies/Psr/Cache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT;
4042

41-
if (is_readable($path)) {
43+
if (\is_readable($path)) {
4244
require_once $path;
4345
} 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);
4547
}
4648
return;
4749
}
4850

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;
5153

52-
if (is_readable($path)) {
54+
if (\is_readable($path)) {
5355
require_once $path;
5456
} 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);
5658
}
5759
return;
5860
}
5961

6062
$entity = str_replace('\\', '/', $entity);
6163
$path = PFC_LIB_DIR . $entity . '.' . PFC_PHP_EXT;
6264

63-
if (is_readable($path)) {
65+
if (\is_readable($path)) {
6466
require_once $path;
6567
}
6668
}
6769
);
6870

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)) {
7072
trigger_error(
7173
'Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.',
7274
E_USER_WARNING

0 commit comments

Comments
 (0)