Debian Codegraph @

includes/block/BlockCache.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Block;
4
5 use MediaWiki\User\UserIdentity;
6
7 /**
8 * @internal For use by BlockManager
9 */
10 class BlockCache {
11 /** @var BlockCacheEntry[] The cache entries indexed by partial key */
12 private $cache = [];
13
14 /**
15 * Get a cached Block for the given key, or null if there is no cache entry,
16 * or false if there is a cache entry indicating that the given target is
17 * not blocked.
18 *
19 * @param BlockCacheKey $key
20 * @return AbstractBlock|false|null
21 */
22 public function get( BlockCacheKey $key ) {
23 $entry = $this->cache[$key->getPartialKey()] ?? null;
24 if ( $entry === null ) {
25 return null;
26 }
27 return $key->matchesStored( $entry->key ) ? $entry->block : null;
28 }
29
30 /**
31 * Set a block cache entry
32 *
33 * @param BlockCacheKey $key The bundled block cache parameters
34 * @param AbstractBlock|false $value The block, or false to indicate that
35 * the target is not blocked.
36 */
37 public function set( BlockCacheKey $key, $value ) {
38 $this->cache[$key->getPartialKey()] = new BlockCacheEntry( $key, $value );
39 }
40
41 /**
42 * Clear all block cache entries associated with a user
43 *
44 * @param UserIdentity $user
45 */
46 public function clearUser( UserIdentity $user ) {
47 foreach ( $this->cache as $partialKey => $entry ) {
48 if ( $entry->key->isUser( $user ) ) {
49 unset( $this->cache[$partialKey] );
50 }
51 }
52 }
53 }