vendor/willdurand/js-translation-bundle/DependencyInjection/Compiler/TranslationResourceFilesPass.php
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Bazinga\Bundle\JsTranslationBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
/**
* @author Hugo MONTEIRO <hugo.monteiro@gmail.com>
*/
class TranslationResourceFilesPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->has('translator.default')) {
return;
}
$translationFiles = $this->getTranslationFilesFromAddResourceCalls($container);
$translationFiles = array_merge($translationFiles, $this->getTranslationFiles($container));
$container->getDefinition('bazinga.jstranslation.translation_finder')->replaceArgument(0, $translationFiles);
}
private function getTranslationFilesFromAddResourceCalls(ContainerBuilder $container)
{
$translationFiles = array();
$methodCalls = $container->findDefinition('translator.default')->getMethodCalls();
foreach ($methodCalls as $methodCall) {
if ($methodCall[0] === 'addResource') {
$locale = $methodCall[1][2];
$filename = $methodCall[1][1];
if (!isset($translationFiles[$locale])) {
$translationFiles[$locale] = array();
}
$translationFiles[$locale][] = $filename;
}
}
return $translationFiles;
}
private function getTranslationFiles(ContainerBuilder $container)
{
$translationFiles = array();
$translator = $container->findDefinition('translator.default');
try {
$translatorOptions = $translator->getArgument(4);
} catch (OutOfBoundsException $e) {
$translatorOptions = array();
}
$translatorOptions = array_merge($translatorOptions, $translator->getArgument(3));
if (isset($translatorOptions['resource_files'])) {
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。