Storage.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Illuminate\Support\Facades;
  3. use Illuminate\Filesystem\Filesystem;
  4. /**
  5. * @method static \Illuminate\Contracts\Filesystem\Filesystem disk(string $name = null)
  6. *
  7. * @see \Illuminate\Filesystem\FilesystemManager
  8. */
  9. class Storage extends Facade
  10. {
  11. /**
  12. * Replace the given disk with a local testing disk.
  13. *
  14. * @param string|null $disk
  15. *
  16. * @return void
  17. */
  18. public static function fake($disk = null)
  19. {
  20. $disk = $disk ?: self::$app['config']->get('filesystems.default');
  21. (new Filesystem)->cleanDirectory(
  22. $root = storage_path('framework/testing/disks/'.$disk)
  23. );
  24. static::set($disk, self::createLocalDriver(['root' => $root]));
  25. }
  26. /**
  27. * Replace the given disk with a persistent local testing disk.
  28. *
  29. * @param string|null $disk
  30. * @return void
  31. */
  32. public static function persistentFake($disk = null)
  33. {
  34. $disk = $disk ?: self::$app['config']->get('filesystems.default');
  35. static::set($disk, self::createLocalDriver([
  36. 'root' => storage_path('framework/testing/disks/'.$disk),
  37. ]));
  38. }
  39. /**
  40. * Get the registered name of the component.
  41. *
  42. * @return string
  43. */
  44. protected static function getFacadeAccessor()
  45. {
  46. return 'filesystem';
  47. }
  48. }