protected function _buildEntries(&$entries, $block, $alias, $level)
 {
     $blocks = $this->_layout->getAllBlocks();
     $extras = array();
     $extras[] = count($block->getChild()) ? count($block->getChild()) : "-";
     $extras[] = $block->getType();
     if ($block->getType() === 'cms/block') {
         $extras[] = $block->getBlockId();
     } elseif ($block->getType() == 'cms/page') {
         $extras[] = $block->getPage()->getIdentifier();
     } elseif ($template = $block->getTemplate()) {
         $extras[] = $template;
     } else {
         $extras[] = '-';
     }
     $extras[] = get_class($block);
     // sprintf("$offset%s %s\n", $alias, $this->_colorize($extraString, self::COLOR_DARK_GRAY))
     $name = $block->getNameInLayout();
     $entry = array('name' => $name, 'alias' => $alias, 'level' => $level, 'extras' => $extras);
     $profileName = "BLOCK: {$name}";
     if (isset($this->timers[$profileName])) {
         $entry['time'] = $this->timers[$profileName]['sum'] * 1000;
     }
     $entries[] = $entry;
     foreach ($block->getChild() as $alias => $childBlock) {
         $this->_buildEntries($entries, $childBlock, $alias, $level + 1);
     }
 }
Exemplo n.º 2
0
 public function testRenameElement()
 {
     $oldName = 'old_name';
     $newName = 'new_name';
     $blockMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->structureMock->expects($this->once())->method('renameElement')->with($this->equalTo($oldName), $this->equalTo($newName))->will($this->returnSelf());
     $this->assertSame($this->model, $this->model->setBlock($oldName, $blockMock));
     $this->assertSame($this->model, $this->model->renameElement($oldName, $newName));
     $this->assertSame([$newName => $blockMock], $this->model->getAllBlocks());
 }
Exemplo n.º 3
0
 /**
  * A smoke test for generating elements
  *
  * See sophisticated tests at \Magento\Framework\View\LayoutDirectivesTest
  * @see \Magento\Framework\View\LayoutDirectivesTest
  * @magentoAppIsolation enabled
  */
 public function testGenerateGetAllBlocks()
 {
     $this->_layout->setXml(simplexml_load_string('<layout>
             <block class="Magento\\Framework\\View\\Element\\Text" name="block1">
                 <block class="Magento\\Framework\\View\\Element\\Text"/>
             </block>
             <block class="Magento\\Framework\\View\\Element\\Text" template="test" ttl="360"/>
             <block class="Magento\\Framework\\View\\Element\\Text"/>
         </layout>', 'Magento\\Framework\\View\\Layout\\Element'));
     $this->assertEquals([], $this->_layout->getAllBlocks());
     $this->_layout->generateElements();
     $expected = ['block1', 'block1_schedule_block0', 'schedule_block1', 'schedule_block2'];
     $this->assertSame($expected, array_keys($this->_layout->getAllBlocks()));
     $child = $this->_layout->getBlock('block1_schedule_block0');
     $this->assertSame($this->_layout->getBlock('block1'), $child->getParentBlock());
     $this->assertEquals('test', $this->_layout->getBlock('schedule_block1')->getData('template'));
     $this->assertEquals('360', $this->_layout->getBlock('schedule_block1')->getData('ttl'));
     $this->assertFalse($this->_layout->getBlock('nonexisting'));
 }
Exemplo n.º 4
0
 /**
  * Retrieve all identities from blocks for further cache invalidation
  *
  * @param \Magento\Framework\View\Layout $subject
  * @param mixed $result
  * @return mixed
  */
 public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
 {
     if ($this->layout->isCacheable() && $this->config->isEnabled()) {
         $tags = array();
         foreach ($this->layout->getAllBlocks() as $block) {
             if ($block instanceof \Magento\Framework\View\Block\IdentityInterface) {
                 $isEsiBlock = $block->getTtl() > 0;
                 $isVarnish = $this->config->getType() == \Magento\PageCache\Model\Config::VARNISH;
                 if ($isVarnish && $isEsiBlock) {
                     continue;
                 }
                 $tags = array_merge($tags, $block->getIdentities());
             }
         }
         $tags = array_unique($tags);
         $this->response->setHeader('X-Magento-Tags', implode(',', $tags));
     }
     return $result;
 }
 /**
  * Set X-Cache-Tags header with all the Magento Cache Tags so
  * they can be purged by the CloudFlare API
  *
  * @param \Magento\Framework\View\Layout $subject
  * @param $result
  * @return mixed
  */
 public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
 {
     if (!$subject->isCacheable() || !$this->config->isEnabled()) {
         return $result;
     }
     $tags = [];
     foreach ($subject->getAllBlocks() as $block) {
         if ($block->getIdentities() !== null) {
             $tags = array_merge($tags, $block->getIdentities());
         }
     }
     $tags = array_unique($tags);
     $this->cacheTagsUtil->setCloudFlareCacheTagsResponseHeader($this->response, $tags);
     return $result;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function getAllBlocks()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAllBlocks');
     if (!$pluginInfo) {
         return parent::getAllBlocks();
     } else {
         return $this->___callPlugins('getAllBlocks', func_get_args(), $pluginInfo);
     }
 }