You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
918 B

13 years ago
13 years ago
13 years ago
  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Cache
  7. * @since 2010-03-04
  8. */
  9. class Cacher
  10. {
  11. /**
  12. * Initialized cachers
  13. *
  14. * @var array
  15. */
  16. static protected $caches = array();
  17. /**
  18. * @param $cacher
  19. * @param null|string $config
  20. * @return Cache
  21. * @throws InitializationException
  22. */
  23. static public function get($cacher, $config = null)
  24. {
  25. if (!isset(self::$caches[$cacher])) {
  26. if (!$config) {
  27. $config = Config::get($cacher);
  28. }
  29. $cache = new $cacher($config);
  30. if (!$cache instanceof Cache) {
  31. throw new InitializationException('Cache driver "' . $cacher . '" must extends Cache');
  32. }
  33. self::$caches[$cacher] = $cache;
  34. }
  35. return self::$caches[$cacher];
  36. }
  37. }