Codes.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Locale\Deployed;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. use Magento\Framework\Filesystem;
  9. use Magento\Framework\Locale\AvailableLocalesInterface;
  10. use Magento\Framework\View\Design\Theme\FlyweightFactory;
  11. use Magento\Framework\View\DesignInterface;
  12. /**
  13. * Returns array of deployed locale codes for the theme.
  14. */
  15. class Codes implements AvailableLocalesInterface
  16. {
  17. /**
  18. * Works with file system.
  19. *
  20. * @var Filesystem
  21. */
  22. private $fileSystem;
  23. /**
  24. * Factory for creating objects that implements \Magento\Framework\View\Design\ThemeInterface.
  25. *
  26. * @var FlyweightFactory
  27. */
  28. private $flyweightFactory;
  29. /**
  30. * @param FlyweightFactory $flyweightFactory factory for creating objects
  31. * that implements \Magento\Framework\View\Design\ThemeInterface
  32. * @param Filesystem $fileSystem works with file system
  33. */
  34. public function __construct(
  35. FlyweightFactory $flyweightFactory,
  36. Filesystem $fileSystem
  37. ) {
  38. $this->fileSystem = $fileSystem;
  39. $this->flyweightFactory = $flyweightFactory;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. *
  44. * If theme or file directory for theme static content does not exist then return an empty array.
  45. */
  46. public function getList($code, $area = DesignInterface::DEFAULT_AREA)
  47. {
  48. try {
  49. $theme = $this->flyweightFactory->create($code, $area);
  50. $reader = $this->fileSystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
  51. $dirs = $reader->read($theme->getFullPath());
  52. } catch (\Exception $e) {
  53. return [];
  54. }
  55. return array_map('basename', $dirs);
  56. }
  57. }