manager.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php namespace Laravel\Cache;
  2. use Laravel\IoC;
  3. class Manager {
  4. /**
  5. * All of the active cache drivers.
  6. *
  7. * @var array
  8. */
  9. protected static $drivers = array();
  10. /**
  11. * Get a cache driver instance.
  12. *
  13. * If no driver name is specified, the default cache driver will be returned
  14. * as defined in the cache configuration file.
  15. *
  16. * @param string $driver
  17. * @return Cache\Driver
  18. */
  19. public static function driver($driver = null)
  20. {
  21. if (is_null($driver)) $driver = Config::get('cache.default');
  22. if ( ! array_key_exists($driver, static::$drivers))
  23. {
  24. if ( ! IoC::container()->registered('laravel.cache.'.$driver))
  25. {
  26. throw new \Exception("Cache driver [$driver] is not supported.");
  27. }
  28. return static::$drivers[$driver] = IoC::container()->resolve('laravel.cache.'.$driver);
  29. }
  30. return static::$drivers[$driver];
  31. }
  32. /**
  33. * Pass all other methods to the default cache driver.
  34. *
  35. * Passing method calls to the driver instance provides a convenient API for the developer
  36. * when always using the default cache driver.
  37. */
  38. public static function __callStatic($method, $parameters)
  39. {
  40. return call_user_func_array(array(static::driver(), $method), $parameters);
  41. }
  42. }