Loader.php 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * 缓存类
  4. *
  5. * @author Zhu Jinhui<zhujinhui@zhangyue.com>2015-10-31 22:35
  6. */
  7. namespace Qii\Cache;
  8. class Loader
  9. {
  10. const VERSION = '1.2';
  11. private $cache;
  12. public function __construct($cache)
  13. {
  14. $this->setCache($cache);
  15. }
  16. /**
  17. * 初始化缓存类
  18. *
  19. * @param Array $policy
  20. * @return Object
  21. */
  22. public function initialization($policy)
  23. {
  24. return \Qii\Autoloader\Psr4::getInstance()->loadClass('Qii\Cache\\' . ucwords($this->cache), $policy);
  25. }
  26. /**
  27. * 设置用于缓存的类
  28. *
  29. * @param String $cache
  30. */
  31. public function setCache($cache)
  32. {
  33. $this->cache = $cache;
  34. $cacheFile = dirname(__FILE__) . DS . DS . ucwords($cache) . '.php';
  35. if (!is_file($cacheFile)) {
  36. throw new \Exception('Unsupport cache class '. $cacheFile);
  37. }
  38. \Qii\Autoloader\Import::requires($cacheFile);
  39. }
  40. }