WriteFactory.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 and/or writing
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class WriteFactory extends 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. parent::__construct($driverPool);
  30. $this->driverPool = $driverPool;
  31. }
  32. /**
  33. * Create a {@see WriterInterface}
  34. *
  35. * @param string $path
  36. * @param DriverInterface|string $driver Driver or driver code
  37. * @param string $mode [optional]
  38. * @return WriteInterface
  39. */
  40. public function create($path, $driver, $mode = 'r')
  41. {
  42. if (is_string($driver)) {
  43. return new Write($path, $this->driverPool->getDriver($driver), $mode);
  44. }
  45. return new Write($path, $driver, $mode);
  46. }
  47. }