FilesystemServiceProvider.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Illuminate\Filesystem;
  3. use Illuminate\Support\ServiceProvider;
  4. class FilesystemServiceProvider extends ServiceProvider
  5. {
  6. /**
  7. * Register the service provider.
  8. *
  9. * @return void
  10. */
  11. public function register()
  12. {
  13. $this->registerNativeFilesystem();
  14. $this->registerFlysystem();
  15. }
  16. /**
  17. * Register the native filesystem implementation.
  18. *
  19. * @return void
  20. */
  21. protected function registerNativeFilesystem()
  22. {
  23. $this->app->singleton('files', function () {
  24. return new Filesystem;
  25. });
  26. }
  27. /**
  28. * Register the driver based filesystem.
  29. *
  30. * @return void
  31. */
  32. protected function registerFlysystem()
  33. {
  34. $this->registerManager();
  35. $this->app->singleton('filesystem.disk', function () {
  36. return $this->app['filesystem']->disk($this->getDefaultDriver());
  37. });
  38. $this->app->singleton('filesystem.cloud', function () {
  39. return $this->app['filesystem']->disk($this->getCloudDriver());
  40. });
  41. }
  42. /**
  43. * Register the filesystem manager.
  44. *
  45. * @return void
  46. */
  47. protected function registerManager()
  48. {
  49. $this->app->singleton('filesystem', function () {
  50. return new FilesystemManager($this->app);
  51. });
  52. }
  53. /**
  54. * Get the default file driver.
  55. *
  56. * @return string
  57. */
  58. protected function getDefaultDriver()
  59. {
  60. return $this->app['config']['filesystems.default'];
  61. }
  62. /**
  63. * Get the default cloud based file driver.
  64. *
  65. * @return string
  66. */
  67. protected function getCloudDriver()
  68. {
  69. return $this->app['config']['filesystems.cloud'];
  70. }
  71. }