/**
  * applies view helpers
  *
  * @todo refactor
  * @param MvcEvent $e
  * @return LayoutModifierListener
  */
 public function applyViewHelpers(EventInterface $e)
 {
     $viewHelperInstructions = $this->updater->getLayoutStructure()->get(LayoutUpdaterInterface::INSTRUCTION_VIEW_HELPERS);
     if ($viewHelperInstructions instanceof Config) {
         $viewHelperInstructions = $viewHelperInstructions->toArray();
     }
     foreach ($this->helperConfig as $helper => $config) {
         if (!isset($viewHelperInstructions[$helper])) {
             continue;
         }
         $defaultMethod = isset($config['default_method']) ? $config['default_method'] : '__invoke';
         $viewHelper = $this->viewHelperManager->get($helper);
         $viewHelperInstructions[$helper] = (array) $viewHelperInstructions[$helper];
         foreach ($viewHelperInstructions[$helper] as $value) {
             if (!$value) {
                 continue;
             }
             $value = (array) $value;
             $method = $this->getHelperMethod($value, $defaultMethod, $viewHelper);
             $args = isset($value['args']) ? (array) $value['args'] : array_values($value);
             $args[0] = $this->prepareHelperValue($args[0], $helper);
             call_user_func_array([$viewHelper, $method], $args);
         }
     }
     return $this;
 }
 public function testIncludedHandleDoesNotOverride()
 {
     $this->updater->setHandles([new Handle('handle/with-include', 10)]);
     $layoutStructure = $this->updater->getLayoutStructure();
     $block = $layoutStructure->blocks->get('do.not.override');
     $includedBlock = $layoutStructure->blocks->get('some.included.block');
     $this->assertEquals('some/tpl', $includedBlock->get('template'));
     $this->assertFalse($block->remove);
 }
 /**
  * set layout template if no template was set e.g. through controller
  * layout plugin
  *
  * @param MvcEvent $e
  */
 public function setLayoutTemplate(MvcEvent $e)
 {
     /* @var $layout ModelInterface */
     $layout = $e->getViewModel();
     $template = $layout->getTemplate();
     if ($template === '') {
         $layoutTemplate = $this->updater->getLayoutStructure()->get(LayoutUpdaterInterface::INSTRUCTION_LAYOUT_TEMPLATE, 'layout/layout');
         $layout->setTemplate($layoutTemplate);
     }
 }
 /**
  * collect data for zdt
  *
  * @param MvcEvent $mvcEvent
  * @return LayoutCollector
  */
 public function collect(MvcEvent $mvcEvent)
 {
     $layout = $mvcEvent->getViewModel();
     $blocks = [];
     foreach ($this->layout->getBlocks() as $blockName => $block) {
         $blocks[$blockName] = ['template' => $block->getTemplate(), 'capture_to' => $block->captureTo(), 'class' => get_class($block)];
     }
     $data = ['handles' => $this->updater->getHandles(true), 'layout_structure' => $this->updater->getLayoutStructure()->toArray(), 'blocks' => $blocks, 'layout_template' => $layout->getTemplate(), 'current_area' => $this->updater->getArea()];
     $this->data = $data;
     return $this;
 }
Beispiel #5
0
 public function setUp()
 {
     $eventManager = new EventManager();
     $this->layoutUpdater = new LayoutUpdater();
     $this->layoutUpdater->setEventManager($eventManager);
     $this->em = $eventManager;
     $this->em->getSharedManager()->clearListeners('ConLayout\\Updater\\LayoutUpdater');
     $this->em->getSharedManager()->attach('ConLayout\\Updater\\LayoutUpdater', 'getLayoutStructure.pre', function (UpdateEvent $e) {
         $layoutStructure = $e->getLayoutStructure();
         $layoutStructure->merge($this->getLayoutStructure());
     });
     $this->layout = new Layout(new BlockFactory(), $this->layoutUpdater);
 }
Beispiel #6
0
 public function setUp()
 {
     $eventManager = new EventManager();
     $this->layoutUpdater = new LayoutUpdater();
     $this->layoutUpdater->setEventManager($eventManager);
     $this->sm = Bootstrap::getServiceManager();
     $this->em = $eventManager;
     $this->blockPool = new BlockPool();
     $this->blockFactory = new BlockFactory([], new BlockManager(), $this->sm);
     $this->blocksGenerator = new BlocksGenerator($this->blockFactory, $this->blockPool);
     $this->layout = new Layout($this->layoutUpdater, $this->blockPool);
     $this->layout->attachGenerator(BlocksGenerator::NAME, $this->blocksGenerator);
 }
Beispiel #7
0
 /**
  * collect data for zdt
  *
  * @param MvcEvent $mvcEvent
  * @return LayoutCollector
  */
 public function collect(MvcEvent $mvcEvent)
 {
     $layout = $mvcEvent->getViewModel();
     $blocks = [];
     foreach ($this->layout->getBlocks() as $blockId => $block) {
         if ($parentBlock = $block->getOption('parent')) {
             $captureTo = $parentBlock . '::' . $block->captureTo();
         } else {
             $captureTo = $block->captureTo();
         }
         $blocks[$blockId] = ['instance' => $block, 'template' => $this->resolveTemplate($block->getTemplate()), 'capture_to' => $captureTo, 'class' => get_class($block)];
     }
     $data = ['handles' => $this->updater->getHandles(true), 'layout_structure' => $this->updater->getLayoutStructure()->toArray(), 'blocks' => $blocks, 'layout_template' => $layout->getTemplate(), 'current_area' => $this->updater->getArea()];
     $this->data = $data;
     return $this;
 }
Beispiel #8
0
 /**
  * @param array $generators
  * @return mixed|void
  */
 public function generate(array $generators = [])
 {
     $layoutStructure = $this->updater->getLayoutStructure();
     foreach ($this->generators as $name => $generator) {
         if (!$this->isGeneratorLoaded($name) && (empty($generators) || isset($generators[$name]))) {
             $generator->generate($layoutStructure);
             $this->loadedGenerators[$name] = true;
         }
     }
 }
Beispiel #9
0
 /**
  * removes blocks defined in layout instructions
  */
 protected function removeBlocksByInstructions()
 {
     if (!$this->blocksRemoved) {
         $removedBlocks = $this->updater->getLayoutStructure()->get(LayoutUpdaterInterface::INSTRUCTION_REMOVE_BLOCKS, []);
         if ($removedBlocks instanceof Config) {
             $removedBlocks = $removedBlocks->toArray();
             foreach ($removedBlocks as $removedBlockId => $value) {
                 if ($value) {
                     $this->removeBlock($removedBlockId);
                 }
             }
         }
         $this->blocksRemoved = true;
     }
 }
 /**
  *
  * @param ViewModel $block
  * @return array
  */
 private function getHandles(ViewModel $block)
 {
     $options = $block->getOption('esi');
     $optionHandles = isset($options['handles']) ? (array) $options['handles'] : [];
     $currentHandles = $this->layoutUpdater->getHandles(true);
     $handlesIndex = [];
     foreach ($currentHandles as $currentHandle) {
         $handlesIndex[$currentHandle->getName()] = $currentHandle->getPriority();
     }
     $handles = [];
     foreach ($optionHandles as $optionHandle) {
         $priority = isset($handlesIndex[$optionHandle]) ? $handlesIndex[$optionHandle] : 1;
         $handles[$optionHandle] = $priority;
     }
     return $handles;
 }
 public function testLayoutUpdaterContainsOnlyDefaultHandle()
 {
     $this->assertEquals(['default'], $this->updater->getHandles());
 }
 /**
  * Callback handler invoked when the dispatch error event is triggered.
  *
  * @param EventInterface $event
  * @return void
  */
 public function injectErrorHandle(EventInterface $event)
 {
     $this->updater->addHandle(new Handle($event->getError(), 666));
 }
Beispiel #13
0
 /**
  *
  * @param string $handle
  * @return LayoutManager
  */
 public function removeHandle($handle)
 {
     $this->updater->removeHandle($handle);
     return $this;
 }