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