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.

41 lines
961 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. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class Cacher
  12. {
  13. /**
  14. * Initialized cachers
  15. *
  16. * @var array
  17. */
  18. static protected $caches = array();
  19. /**
  20. * @param $cacher
  21. * @param null|string $config
  22. * @return Cache
  23. * @throws InitializationException
  24. */
  25. static public function get($cacher, $config = null)
  26. {
  27. if (!isset(self::$caches[$cacher])) {
  28. if (!$config) {
  29. $config = Config::get($cacher);
  30. }
  31. $cache = new $cacher($config);
  32. if (!$cache instanceof Cache) {
  33. throw new InitializationException('Cache driver "' . $cacher . '" must extends Cache');
  34. }
  35. self::$caches[$cacher] = $cache;
  36. }
  37. return self::$caches[$cacher];
  38. }
  39. }