ReadFactory.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Filesystem\File;
  7. use Magento\Framework\Filesystem\DriverInterface;
  8. use Magento\Framework\Filesystem\DriverPool;
  9. /**
  10. * Opens a file for reading
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class ReadFactory
  15. {
  16. /**
  17. * Pool of filesystem drivers
  18. *
  19. * @var DriverPool
  20. */
  21. private $driverPool;
  22. /**
  23. * Constructor
  24. *
  25. * @param DriverPool $driverPool
  26. */
  27. public function __construct(DriverPool $driverPool)
  28. {
  29. $this->driverPool = $driverPool;
  30. }
  31. /**
  32. * Create a {@see ReaderInterface}
  33. *
  34. * @param string $path
  35. * @param DriverInterface|string $driver Driver or driver code
  36. * @return \Magento\Framework\Filesystem\File\ReadInterface
  37. */
  38. public function create($path, $driver)
  39. {
  40. if (is_string($driver)) {
  41. return new Read($path, $this->driverPool->getDriver($driver));
  42. }
  43. return new Read($path, $driver);
  44. }
  45. }