BundleEntryReader example


    final protected static function readEntry(array $indices, string $locale = null, bool $fallback = true): mixed
    {
        if (!isset(self::$entryReader)) {
            self::$entryReader = new BundleEntryReader(new BufferedBundleReader(
                new PhpBundleReader(),
                Intl::BUFFER_SIZE
            ));

            $localeAliases = self::$entryReader->readEntry(Intl::getDataDirectory().'/'.Intl::LOCALE_DIR, 'meta', ['Aliases']);
            self::$entryReader->setLocaleAliases($localeAliases instanceof \Traversable ? iterator_to_array($localeAliases) : $localeAliases);
        }

        return self::$entryReader->readEntry(static::getPath()$locale ?? \Locale::getDefault()$indices$fallback);
    }

    
public function __construct(BundleCompilerInterface $compiler, string $dirName)
    {
        $this->compiler = $compiler;
        $this->dirName = $dirName;
    }

    public function generateData(GeneratorConfig $config): void
    {
        $filesystem = new Filesystem();
        $localeScanner = new LocaleScanner();
        $reader = new BundleEntryReader(new IntlBundleReader());

        $writers = $config->getBundleWriters();
        $tempDir = sys_get_temp_dir().'/icu-data-'.$this->dirName;

        // Prepare filesystem directories         foreach ($writers as $targetDir => $writer) {
            $filesystem->remove($targetDir.'/'.$this->dirName);
            $filesystem->mkdir($targetDir.'/'.$this->dirName);
        }

        $filesystem->remove($tempDir);
        
'Foo' => 'Bar',
            'Bar' => 'Baz',
        ],
        'Baz' => 'Foo',
        'Version' => '2.0',
        'Foo' => 'Bar',
    ];

    protected function setUp(): void
    {
        $this->readerImpl = $this->createMock(BundleEntryReaderInterface::class);
        $this->reader = new BundleEntryReader($this->readerImpl);
    }

    public function testForwardCallToRead()
    {
        $this->readerImpl->expects($this->once())
            ->method('read')
            ->with(self::RES_DIR, 'root')
            ->willReturn(self::DATA);

        $this->assertSame(self::DATA, $this->reader->read(self::RES_DIR, 'root'));
    }

    
Home | Imprint | This part of the site doesn't use cookies.