-
Notifications
You must be signed in to change notification settings - Fork 1
/
XCacheClassLoader.php
40 lines (32 loc) · 993 Bytes
/
XCacheClassLoader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Drupal\xautoload\ClassLoader;
use Drupal\xautoload\CacheManager\CacheManagerObserverInterface;
use Drupal\xautoload\ClassFinder\InjectedApi\LoadClassGetFileInjectedApi;
class XCacheClassLoader extends AbstractCachedClassLoader implements CacheManagerObserverInterface {
/**
* @return bool
*/
protected function checkRequirements() {
return extension_loaded('Xcache') && function_exists('xcache_isset');
}
/**
* {@inheritdoc}
*/
function loadClass($class) {
// Look if the cache has anything for this class.
if (xcache_isset($this->prefix . $class)
&& $file = xcache_get($this->prefix . $class)
) {
if (is_file($file)) {
require $file;
return;
}
xcache_unset($this->prefix . $class);
}
// Resolve cache miss.
$api = new LoadClassGetFileInjectedApi($class);
if ($this->finder->apiFindFile($api, $class)) {
xcache_set($this->prefix . $class, $api->getFile());
}
}
}