HTMLFileCache refactoring:
[lhc/web/wiklou.git] / includes / cache / ObjectFileCache.php
1 <?php
2 class ObjectFileCache extends FileCacheBase {
3
4 public static function newFromKey( $key, $type ) {
5 $cache = new self();
6
7 $allowedTypes = self::cacheableTypes();
8 if ( !isset( $allowedTypes[$type] ) ) {
9 throw new MWException( "Invalid filecache type given." );
10 }
11 $cache->mKey = (string)$key;
12 $cache->mType = (string)$type;
13 $cache->mExt = $allowedTypes[$cache->mType];
14
15 return $cache;
16 }
17
18 /*
19 * Get the type => extension mapping
20 * @return array
21 */
22 protected static function cacheableTypes() {
23 return array( 'resources-js' => 'js', 'resources-css' => 'css' );
24 }
25
26 /**
27 * Get the base file cache directory
28 * @return string
29 */
30 protected function cacheDirectory() {
31 global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth;
32 if ( $wgFileCacheDirectory ) {
33 $dir = $wgFileCacheDirectory;
34 } elseif ( $wgCacheDirectory ) {
35 $dir = "$wgCacheDirectory/object";
36 } else {
37 throw new MWException( 'Please set $wgCacheDirectory in LocalSettings.php if you wish to use the HTML file cache' );
38 }
39 return $dir;
40 }
41 }