Skip to content

Commit 39a25bc

Browse files
committed
Merge pull request #262 from khoaofgod/final
Fix Autoload Confict
2 parents 60f0a98 + 81a52a1 commit 39a25bc

File tree

3 files changed

+90
-31
lines changed

3 files changed

+90
-31
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* As reported, HOA Project cause some conflict problem with Autoload of Composer.
5+
* This is not phpFastCache problem, we used same autoload with Google Re-Capcha.
6+
* So, Until HOA, or the your project fixed the autoload.
7+
* All you need is put this line on your config.
8+
*/
9+
10+
// In your Setting / Config.php or Index.php
11+
define("PHPFASTCACHE_LEGACY",true);
12+
13+
// If you use composer, then it auto included our "src/phpFastCache/phpFastCache.php" on vendor folder already, you don't need to do anything else
14+
15+
require_once __DIR__.'/../src/autoload.php';
16+
17+
// run Files Example
18+
require_once __DIR__.'/files.php';
19+
20+
/*
21+
* It also bring back the __c() legacy function
22+
*/

src/phpFastCache/Util/Legacy.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
* If Any problem with Autoload on other project
4+
* Try to put this line on your config project
5+
* define("PHPFASTCACHE_LEGACY",true);
6+
* and just keep include phpFastCache/phpFastCache.php or Composer Autoloader
7+
*/
8+
9+
use phpFastCache\CacheManager;
10+
11+
require_once __DIR__.'/../Core/DriverInterface.php';
12+
require_once __DIR__.'/../Core/DriverAbstract.php';
13+
require_once __DIR__.'/../Core/phpFastCache.php';
14+
require_once __DIR__.'/../Core/phpFastCacheExtensions.php';
15+
require_once __DIR__.'/../Exceptions/phpFastCacheCoreException.php';
16+
require_once __DIR__.'/../Exceptions/phpFastCacheDriverException.php';
17+
18+
require_once __DIR__.'/../Drivers/files.php';
19+
require_once __DIR__.'/../Drivers/memcache.php';
20+
require_once __DIR__.'/../Drivers/memcached.php';
21+
require_once __DIR__.'/../Drivers/mongodb.php';
22+
require_once __DIR__.'/../Drivers/predis.php';
23+
require_once __DIR__.'/../Drivers/redis.php';
24+
require_once __DIR__.'/../Drivers/sqlite.php';
25+
26+
require_once __DIR__.'/../CacheManager.php';
27+
require_once __DIR__.'/../phpFastCache.php';
28+
29+
30+
/**
31+
* __c() Short alias
32+
* @param string $storage
33+
* @param array $config
34+
* @return mixed
35+
*/
36+
if (!function_exists("__c")) {
37+
function __c($storage = 'auto', $config = array())
38+
{
39+
return CacheManager::getInstance($storage, $config);
40+
}
41+
}
42+
43+

src/phpFastCache/phpFastCache.php

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,32 @@
1414

1515
use phpFastCache\CacheManager;
1616
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
17-
/**
18-
* Register Autoload
19-
*/
20-
spl_autoload_register(function ($entity) {
21-
// Explode is faster than substr & strstr also more control
22-
$module = explode('\\',$entity,2);
23-
if ($module[0] !== 'phpFastCache') {
24-
/**
25-
* Not a part of phpFastCache file
26-
* then we return here.
27-
*/
28-
return;
29-
}
3017

31-
$entity = str_replace('\\', '/', $module[1]);
32-
$path = __DIR__ . '/' . $entity . '.' . PHP_EXT;
33-
if (is_readable($path)) {
34-
require_once $path;
35-
}
36-
});
18+
if(!defined("PHPFASTCACHE_LEGACY")) {
19+
/**
20+
* Register Autoload
21+
*/
22+
spl_autoload_register(function ($entity) {
23+
// Explode is faster than substr & strstr also more control
24+
$module = explode('\\',$entity,2);
25+
if ($module[0] !== 'phpFastCache') {
26+
/**
27+
* Not a part of phpFastCache file
28+
* then we return here.
29+
*/
30+
return;
31+
}
32+
33+
$entity = str_replace('\\', '/', $module[1]);
34+
$path = __DIR__ . '/' . $entity . '.' . PHP_EXT;
35+
if (is_readable($path)) {
36+
require_once $path;
37+
}
38+
});
39+
40+
} else {
41+
require_once __DIR__.'/Util/Legacy.php';
42+
}
3743

3844
/**
3945
* phpFastCache() Full alias
@@ -47,15 +53,3 @@ function phpFastCache($storage = 'auto', $config = array())
4753
return CacheManager::getInstance($storage, $config);
4854
}
4955
}
50-
/**
51-
* __c() Short alias
52-
* @param string $storage
53-
* @param array $config
54-
* @return mixed
55-
*/
56-
if (!function_exists("__c")) {
57-
function __c($storage = 'auto', $config = array())
58-
{
59-
return CacheManager::getInstance($storage, $config);
60-
}
61-
}

0 commit comments

Comments
 (0)