/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
setup/src/Magento/Setup/Module/I18n/Dictionary/Generator.php
117 строк
3 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 11:23
22 окт 2025, 11:23
6c2f6e6
Код
Авторство
О чём код?
<?php /** * Copyright 2015 Adobe * All Rights Reserved. */ namespace Magento\Setup\Module\I18n\Dictionary; use Magento\Setup\Module\I18n\Factory; use Magento\Setup\Module\I18n\ParserInterface; /** * Dictionary generator */ class Generator { /** * Parser * * @var \Magento\Setup\Module\I18n\ParserInterface */ protected $parser; /** * Contextual parser * * @var \Magento\Setup\Module\I18n\ParserInterface */ protected $contextualParser; /** * Domain abstract factory * * @var \Magento\Setup\Module\I18n\Factory */ protected $factory; /** * Generator options resolver * * @var Options\ResolverFactory */ protected $optionResolverFactory; /** * @var WriterInterface */ protected $writer; /** * Generator construct * * @param ParserInterface $parser * @param ParserInterface $contextualParser * @param Factory $factory * @param Options\ResolverFactory $optionsResolver */ public function __construct( ParserInterface $parser, ParserInterface $contextualParser, Factory $factory, Options\ResolverFactory $optionsResolver ) { $this->parser = $parser; $this->contextualParser = $contextualParser; $this->factory = $factory; $this->optionResolverFactory = $optionsResolver; } /** * Generate dictionary * * @param string $directory * @param string $outputFilename * @param bool $withContext * @throws \UnexpectedValueException * @return void */ public function generate($directory, $outputFilename, $withContext = false) { $optionResolver = $this->optionResolverFactory->create($directory, $withContext); $parser = $this->getActualParser($withContext); $parser->parse($optionResolver->getOptions()); $phraseList = $parser->getPhrases(); if (!count($phraseList)) { throw new \UnexpectedValueException('No phrases found in the specified dictionary file.'); } foreach ($phraseList as $phrase) { $this->getDictionaryWriter($outputFilename)->write($phrase); } $this->writer = null; } /** * @param string $outputFilename * @return WriterInterface */ protected function getDictionaryWriter($outputFilename) { if (null === $this->writer) { $this->writer = $this->factory->createDictionaryWriter($outputFilename); } return $this->writer; } /** * Get actual parser * * @param bool $withContext * @return \Magento\Setup\Module\I18n\ParserInterface */ protected function getActualParser($withContext) { return $withContext ? $this->contextualParser : $this->parser; } }