Skip to content

Commit a189e3c

Browse files
committed
make autoload for legacy
1 parent 7a957bd commit a189e3c

File tree

6 files changed

+34
-29
lines changed

6 files changed

+34
-29
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"autoload": {
3535
"files": [
36-
"src/autoload.php"
36+
"src/phpFastCache.php"
3737
]
3838
}
3939
}

examples/testing/autoload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
require_once "../../src/autoload.php";
4+
5+
use phpFastCache\CacheManager;
6+
7+
CacheManager::setup(array());

src/autoload.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,5 @@
1111
* @author Georges.L (Geolim4) <[email protected]>
1212
*
1313
*/
14-
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
15-
require_once 'phpFastCache/Legacy/aliases.' . PHP_EXT;
1614

17-
/**
18-
* Register Autoload
19-
*/
20-
spl_autoload_register(function ($entity) {
21-
if (substr($entity, 0, 13) !== 'phpFastCache\\') {
22-
/**
23-
* Not a part of phpFastCache file
24-
* then we return here.
25-
*/
26-
return;
27-
}
28-
29-
$entity = str_replace('\\', '/', $entity);
30-
31-
$path = __DIR__ . '/' . $entity . '.' . PHP_EXT;
32-
if (is_readable($path)) {
33-
require_once $path;
34-
}
35-
});
15+
require_once __DIR__."/phpFastCache.php";

src/phpFastCache/Legacy/aliases.php renamed to src/phpFastCache.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,30 @@
1212
*
1313
*/
1414

15+
use phpFastCache\CacheManager;
16+
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
17+
1518
/**
16-
* This file ensure
17-
* a maximum compatibility
18-
* for user that do not
19-
* migrated to CacheManager::getInstance()
19+
* Register Autoload
2020
*/
21-
use phpFastCache\CacheManager;
21+
spl_autoload_register(function ($entity) {
22+
// Explode is faster than substr & strstr also more control
23+
$module = explode('\\',$entity,2);
24+
if ($module[0] !== 'phpFastCache') {
25+
/**
26+
* Not a part of phpFastCache file
27+
* then we return here.
28+
*/
29+
return;
30+
}
2231

32+
$entity = str_replace('\\', '/', $module[1]);
33+
34+
$path = __DIR__ . '/phpFastCache/' . $entity . '.' . PHP_EXT;
35+
if (is_readable($path)) {
36+
require_once $path;
37+
}
38+
});
2339

2440
/**
2541
* phpFastCache() Full alias
@@ -33,8 +49,6 @@ function phpFastCache($storage = 'auto', $config = array())
3349
return CacheManager::getInstance($storage, $config);
3450
}
3551
}
36-
37-
3852
/**
3953
* __c() Short alias
4054
* @param string $storage

src/phpFastCache/.htaccess

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
order deny,allow
2+
deny from all
3+
allow from 127.0.0.1

src/phpFastCache/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href="http://www.phpfastcache.com" title="Simple Php Caching Class">Visit www.phpfastcache.com</a>

0 commit comments

Comments
 (0)