Neos\Flow\I18n\Cldr\Reader\DatesReader::initializeObject PHP Method

initializeObject() public method

Constructs the reader, loading parsed data from cache if available.
public initializeObject ( ) : void
return void
    public function initializeObject()
    {
        if ($this->cache->has('parsedFormats') && $this->cache->has('parsedFormatsIndices') && $this->cache->has('localizedLiterals')) {
            $this->parsedFormats = $this->cache->get('parsedFormats');
            $this->parsedFormatsIndices = $this->cache->get('parsedFormatsIndices');
            $this->localizedLiterals = $this->cache->get('localizedLiterals');
        }
    }

Usage Example

 /**
  * @test
  */
 public function localizedLiteralsAreCorrectlyReadFromCldr()
 {
     $getRawArrayCallback = function () {
         $args = func_get_args();
         $mockDatesCldrData = (require __DIR__ . '/../../Fixtures/MockDatesParsedCldrData.php');
         $lastPartOfPath = substr($args[0], strrpos($args[0], '/') + 1);
         // Eras have different XML structure than other literals so they have to be handled differently
         if ($lastPartOfPath === 'eras') {
             return $mockDatesCldrData['eras'];
         } else {
             return $mockDatesCldrData[$lastPartOfPath];
         }
     };
     $mockModel = $this->getAccessibleMock(I18n\Cldr\CldrModel::class, ['getRawArray'], [[]]);
     $mockModel->expects($this->exactly(5))->method('getRawArray')->will($this->returnCallback($getRawArrayCallback));
     $mockRepository = $this->createMock(I18n\Cldr\CldrRepository::class);
     $mockRepository->expects($this->once())->method('getModelForLocale')->with($this->sampleLocale)->will($this->returnValue($mockModel));
     $mockCache = $this->getMockBuilder(VariableFrontend::class)->disableOriginalConstructor()->getMock();
     $this->createCacheExpectations($mockCache);
     $reader = new I18n\Cldr\Reader\DatesReader();
     $reader->injectCldrRepository($mockRepository);
     $reader->injectCache($mockCache);
     $reader->initializeObject();
     $result = $reader->getLocalizedLiteralsForLocale($this->sampleLocale);
     $this->assertEquals('January', $result['months']['format']['wide'][1]);
     $this->assertEquals('Sat', $result['days']['format']['abbreviated']['sat']);
     $this->assertEquals('1', $result['quarters']['format']['narrow'][1]);
     $this->assertEquals('a.m.', $result['dayPeriods']['stand-alone']['wide']['am']);
     $this->assertEquals('Anno Domini', $result['eras']['eraNames'][1]);
     $reader->shutdownObject();
 }