CacheServiceProvider.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Illuminate\Cache;
  3. use Illuminate\Contracts\Support\DeferrableProvider;
  4. use Illuminate\Support\ServiceProvider;
  5. use Symfony\Component\Cache\Adapter\Psr16Adapter;
  6. class CacheServiceProvider extends ServiceProvider implements DeferrableProvider
  7. {
  8. /**
  9. * Register the service provider.
  10. *
  11. * @return void
  12. */
  13. public function register()
  14. {
  15. $this->app->singleton('cache', function ($app) {
  16. return new CacheManager($app);
  17. });
  18. $this->app->singleton('cache.store', function ($app) {
  19. return $app['cache']->driver();
  20. });
  21. $this->app->singleton('cache.psr6', function ($app) {
  22. return new Psr16Adapter($app['cache.store']);
  23. });
  24. $this->app->singleton('memcached.connector', function () {
  25. return new MemcachedConnector;
  26. });
  27. $this->app->singleton(RateLimiter::class, function ($app) {
  28. return new RateLimiter($app->make('cache')->driver(
  29. $app['config']->get('cache.limiter')
  30. ));
  31. });
  32. }
  33. /**
  34. * Get the services provided by the provider.
  35. *
  36. * @return array
  37. */
  38. public function provides()
  39. {
  40. return [
  41. 'cache', 'cache.store', 'cache.psr6', 'memcached.connector', RateLimiter::class,
  42. ];
  43. }
  44. }