GenerationDirectoryAccessException.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Console\Exception;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. use Magento\Framework\Exception\FileSystemException;
  9. use Magento\Framework\Phrase;
  10. /**
  11. * The default exception for missing write permissions on compilation generated folder.
  12. */
  13. class GenerationDirectoryAccessException extends FileSystemException
  14. {
  15. /**
  16. * @inheritdoc
  17. */
  18. public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0)
  19. {
  20. $phrase = $phrase ?: new Phrase(
  21. 'Command line user does not have read and write permissions on '
  22. . $this->getDefaultDirectoryPath(DirectoryList::GENERATED) . ' directory. '
  23. . 'Please address this issue before using Magento command line.'
  24. );
  25. parent::__construct($phrase, $cause, $code);
  26. }
  27. /**
  28. * Get default directory path by code
  29. *
  30. * @param string $code
  31. * @return string
  32. */
  33. private function getDefaultDirectoryPath($code)
  34. {
  35. $config = DirectoryList::getDefaultConfig();
  36. $result = '';
  37. if (isset($config[$code][DirectoryList::PATH])) {
  38. $result = $config[$code][DirectoryList::PATH];
  39. }
  40. return $result;
  41. }
  42. }