Neos\Flow\I18n\Cldr\Reader\PluralsReader::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('rulesets') && $this->cache->has('rulesetsIndices')) {
            $this->rulesets = $this->cache->get('rulesets');
            $this->rulesetsIndices = $this->cache->get('rulesetsIndices');
        } else {
            $this->generateRulesets();
            $this->cache->set('rulesets', $this->rulesets);
            $this->cache->set('rulesetsIndices', $this->rulesetsIndices);
        }
    }

Usage Example

 /**
  * @return void
  */
 public function setUp()
 {
     $samplePluralRulesData = ['pluralRules[@locales="ro mo"]' => ['pluralRule[@count="one"]' => 'n is 1', 'pluralRule[@count="few"]' => 'n is 0 OR n is not 1 AND n mod 100 in 1..19']];
     $mockModel = $this->getAccessibleMock(I18n\Cldr\CldrModel::class, ['getRawArray'], [['fake/path']]);
     $mockModel->expects($this->once())->method('getRawArray')->with('plurals')->will($this->returnValue($samplePluralRulesData));
     $mockRepository = $this->createMock(I18n\Cldr\CldrRepository::class);
     $mockRepository->expects($this->once())->method('getModel')->with('supplemental/plurals')->will($this->returnValue($mockModel));
     $mockCache = $this->getMockBuilder(VariableFrontend::class)->disableOriginalConstructor()->getMock();
     $mockCache->expects($this->at(0))->method('has')->with('rulesets')->will($this->returnValue(false));
     $mockCache->expects($this->at(1))->method('set')->with('rulesets');
     $mockCache->expects($this->at(2))->method('set')->with('rulesetsIndices');
     $this->reader = new PluralsReader();
     $this->reader->injectCldrRepository($mockRepository);
     $this->reader->injectCache($mockCache);
     $this->reader->initializeObject();
 }