vendor/sylius/theme-bundle/src/Translation/Finder/LegacyTranslationFilesFinder.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ThemeBundle\Translation\Finder;
  12. use Sylius\Bundle\ThemeBundle\Factory\FinderFactoryInterface;
  13. use Symfony\Component\Finder\SplFileInfo;
  14. /**
  15.  * @deprecated Deprecated since Sylius/ThemeBundle 2.0 and will be removed in 3.0.
  16.  */
  17. final class LegacyTranslationFilesFinder implements TranslationFilesFinderInterface
  18. {
  19.     private FinderFactoryInterface $finderFactory;
  20.     public function __construct(FinderFactoryInterface $finderFactory)
  21.     {
  22.         @trigger_error(sprintf(
  23.             '"%s" is deprecated since Sylius/ThemeBundle 2.0 and will be removed in 3.0.',
  24.             self::class,
  25.         ), \E_USER_DEPRECATED);
  26.         $this->finderFactory $finderFactory;
  27.     }
  28.     public function findTranslationFiles(string $path): array
  29.     {
  30.         $themeFiles $this->getFiles($path);
  31.         $translationsFiles = [];
  32.         foreach ($themeFiles as $themeFile) {
  33.             $themeFilepath = (string) $themeFile;
  34.             if (!$this->isTranslationFile($themeFilepath)) {
  35.                 continue;
  36.             }
  37.             $translationsFiles[] = $themeFilepath;
  38.         }
  39.         return $translationsFiles;
  40.     }
  41.     /**
  42.      * @return iterable|SplFileInfo[]
  43.      */
  44.     private function getFiles(string $path): iterable
  45.     {
  46.         $finder $this->finderFactory->create();
  47.         $finder
  48.             ->ignoreUnreadableDirs()
  49.             ->in($path)
  50.         ;
  51.         return $finder;
  52.     }
  53.     private function isTranslationFile(string $file): bool
  54.     {
  55.         return false !== strpos($file'translations' \DIRECTORY_SEPARATOR) &&
  56.             (bool) preg_match('/^[^\.]+?\.[a-zA-Z_]{2,}?\.[a-z0-9]{2,}?$/'basename($file));
  57.     }
  58. }