| 1 |
<?php |
| 2 |
|
| 3 |
class HappyForms_Cache { |
| 4 |
|
| 5 |
private static $instance; |
| 6 |
|
| 7 |
private $cache = array(); |
| 8 |
|
| 9 |
public static function instance() { |
| 10 |
if ( is_null( self::$instance ) ) { |
| 11 |
self::$instance = new self(); |
| 12 |
} |
| 13 |
|
| 14 |
return self::$instance; |
| 15 |
} |
| 16 |
|
| 17 |
public function exists( $key ) { |
| 18 |
$exists = isset( $this->cache[$key] ); |
| 19 |
|
| 20 |
return $exists; |
| 21 |
} |
| 22 |
|
| 23 |
public function get( $key, &$found = null ) { |
| 24 |
$found = false; |
| 25 |
|
| 26 |
if ( $this->exists( $key ) ) { |
| 27 |
$found = true; |
| 28 |
|
| 29 |
if ( is_object( $this->cache[$key] ) ) { |
| 30 |
return clone( $this->cache[$key] ); |
| 31 |
} else { |
| 32 |
return $this->cache[$key]; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
public function set( $key, $value ) { |
| 40 |
if ( is_object( $value ) ) { |
| 41 |
$value = clone( $value ); |
| 42 |
} |
| 43 |
|
| 44 |
$this->cache[$key] = $value; |
| 45 |
|
| 46 |
return true; |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
if ( ! function_exists( 'happyforms_get_cache' ) ): |
| 52 |
|
| 53 |
function happyforms_get_cache() { |
| 54 |
return HappyForms_Cache::instance(); |
| 55 |
} |
| 56 |
|
| 57 |
endif; |
| 58 |
|
| 59 |
happyforms_get_cache(); |