Handler.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace League\Flysystem;
  3. use BadMethodCallException;
  4. /**
  5. * @deprecated
  6. */
  7. abstract class Handler
  8. {
  9. /**
  10. * @var string
  11. */
  12. protected $path;
  13. /**
  14. * @var FilesystemInterface
  15. */
  16. protected $filesystem;
  17. /**
  18. * Constructor.
  19. *
  20. * @param FilesystemInterface $filesystem
  21. * @param string $path
  22. */
  23. public function __construct(FilesystemInterface $filesystem = null, $path = null)
  24. {
  25. $this->path = $path;
  26. $this->filesystem = $filesystem;
  27. }
  28. /**
  29. * Check whether the entree is a directory.
  30. *
  31. * @return bool
  32. */
  33. public function isDir()
  34. {
  35. return $this->getType() === 'dir';
  36. }
  37. /**
  38. * Check whether the entree is a file.
  39. *
  40. * @return bool
  41. */
  42. public function isFile()
  43. {
  44. return $this->getType() === 'file';
  45. }
  46. /**
  47. * Retrieve the entree type (file|dir).
  48. *
  49. * @return string file or dir
  50. */
  51. public function getType()
  52. {
  53. $metadata = $this->filesystem->getMetadata($this->path);
  54. return $metadata['type'];
  55. }
  56. /**
  57. * Set the Filesystem object.
  58. *
  59. * @param FilesystemInterface $filesystem
  60. *
  61. * @return $this
  62. */
  63. public function setFilesystem(FilesystemInterface $filesystem)
  64. {
  65. $this->filesystem = $filesystem;
  66. return $this;
  67. }
  68. /**
  69. * Retrieve the Filesystem object.
  70. *
  71. * @return FilesystemInterface
  72. */
  73. public function getFilesystem()
  74. {
  75. return $this->filesystem;
  76. }
  77. /**
  78. * Set the entree path.
  79. *
  80. * @param string $path
  81. *
  82. * @return $this
  83. */
  84. public function setPath($path)
  85. {
  86. $this->path = $path;
  87. return $this;
  88. }
  89. /**
  90. * Retrieve the entree path.
  91. *
  92. * @return string path
  93. */
  94. public function getPath()
  95. {
  96. return $this->path;
  97. }
  98. /**
  99. * Plugins pass-through.
  100. *
  101. * @param string $method
  102. * @param array $arguments
  103. *
  104. * @return mixed
  105. */
  106. public function __call($method, array $arguments)
  107. {
  108. array_unshift($arguments, $this->path);
  109. $callback = [$this->filesystem, $method];
  110. try {
  111. return call_user_func_array($callback, $arguments);
  112. } catch (BadMethodCallException $e) {
  113. throw new BadMethodCallException(
  114. 'Call to undefined method '
  115. . get_called_class()
  116. . '::' . $method
  117. );
  118. }
  119. }
  120. }