/** * {@inheritdoc} * * @param Layout\Reader\Context $readerContext * @param Layout\Element $bodyElement * @return $this */ public function interpret(Layout\Reader\Context $readerContext, Layout\Element $bodyElement) { /** @var \Magento\Framework\View\Layout\Element $element */ foreach ($bodyElement as $element) { if ($element->getName() === self::BODY_ATTRIBUTE) { $this->setBodyAttributeToStructure($readerContext, $element); } } $this->readerPool->interpret($readerContext, $bodyElement); return $this; }
public function testInterpret() { /** @var Reader\Context $contextMock */ $contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock(); $currentElement = new \Magento\Framework\View\Layout\Element('<element><move name="block"/><remove name="container"/><ignored name="user"/></element>'); /** * @var \Magento\Framework\View\Layout\Reader\Move|\PHPUnit_Framework_MockObject_MockObject $moveReaderMock */ $moveReaderMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Move')->disableOriginalConstructor()->getMock(); $moveReaderMock->expects($this->exactly(2))->method('interpret')->willReturn($this->returnSelf()); $moveReaderMock->method('getSupportedNodes')->willReturn(['move']); $this->readerFactoryMock->expects($this->once())->method('create')->willReturnMap([['Magento\\Framework\\View\\Layout\\Reader\\Move', [], $moveReaderMock]]); $this->pool->interpret($contextMock, $currentElement); $this->pool->interpret($contextMock, $currentElement); }
/** * {@inheritdoc} * * @param Context $readerContext * @param Layout\Element $currentElement * @param Layout\Element $parentElement * @return $this */ public function interpret(Context $readerContext, Layout\Element $currentElement) { switch ($currentElement->getName()) { case self::TYPE_CONTAINER: $this->helper->scheduleStructure($readerContext->getScheduledStructure(), $currentElement, $currentElement->getParent()); $this->mergeContainerAttributes($readerContext->getScheduledStructure(), $currentElement); break; case self::TYPE_REFERENCE_CONTAINER: $this->containerReference($readerContext->getScheduledStructure(), $currentElement); break; default: break; } $this->readerPool->interpret($readerContext, $currentElement); return $this; }
/** * {@inheritdoc} * * @param Context $readerContext * @param Layout\Element $currentElement * @param Layout\Element $parentElement * @return $this */ public function interpret(Context $readerContext, Layout\Element $currentElement) { $scheduledStructure = $readerContext->getScheduledStructure(); switch ($currentElement->getName()) { case self::TYPE_BLOCK: $this->scheduleBlock($scheduledStructure, $currentElement); break; case self::TYPE_REFERENCE_BLOCK: $this->scheduleReference($scheduledStructure, $currentElement); break; default: break; } $this->readerPool->interpret($readerContext, $currentElement); return $this; }
/** * Create structure of elements from the loaded XML configuration * * @return void */ public function generateElements() { \Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__); $cacheId = 'structure_' . $this->getUpdate()->getCacheId(); $result = $this->cache->load($cacheId); if ($result) { $this->readerContext = unserialize($result); } else { \Magento\Framework\Profiler::start('build_structure'); $this->readerPool->interpret($this->getReaderContext(), $this->getNode()); \Magento\Framework\Profiler::stop('build_structure'); $this->cache->save(serialize($this->getReaderContext()), $cacheId, $this->getUpdate()->getHandles()); } $generatorContext = $this->generatorContextFactory->create(['structure' => $this->structure, 'layout' => $this]); \Magento\Framework\Profiler::start('generate_elements'); $this->generatorPool->process($this->getReaderContext(), $generatorContext); \Magento\Framework\Profiler::stop('generate_elements'); $this->addToOutputRootContainers(); \Magento\Framework\Profiler::stop(__CLASS__ . '::' . __METHOD__); }
/** * Read page layout structure and fill reader context * * @param Layout\Reader\Context $readerContext * @param string $pageLayout * @return void */ public function read(Layout\Reader\Context $readerContext, $pageLayout) { $this->getPageLayoutMerge()->load($pageLayout); $xml = $this->getPageLayoutMerge()->asSimplexml(); $this->reader->interpret($readerContext, $xml); }