Example #1
1
 public function findAllBlocks(\Twig_Template $template, array $context)
 {
     if (false !== ($parent = $template->getParent($context))) {
         return array_unique(array_merge($this->findAllBlocks($parent, $context), $template->getBlockNames()));
     }
     return $template->getBlockNames();
 }
Example #2
0
 /**
  * @param Template $template
  */
 public function addTemplate(Template $template)
 {
     $this->templates[$template->getTemplateName()] = $template;
     /** @var Template $parent */
     if ($parent = $template->getParent([])) {
         $this->addTemplate($parent);
     }
 }
Example #3
0
 protected function getBlocks(\Twig_Template $template, $parameters = [])
 {
     $blocks = [];
     if (false !== ($parent = $template->getParent($parameters))) {
         $blocks = $this->getBlocks($parent);
     }
     return array_merge($blocks, $template->getBlocks());
 }
 /**
  * @param \Twig_Template $template
  * @param string $blockName
  * @return \Twig_Template|bool
  */
 private function findTemplateWithBlock(\Twig_Template $template, $blockName)
 {
     if ($template->hasBlock($blockName)) {
         return $template;
     }
     // Check parents
     if (false !== ($parent = $template->getParent(array()))) {
         if ($this->findTemplateWithBlock($parent, $blockName) !== false) {
             return $template;
         }
     }
     return false;
 }
 /**
  * @param \Twig_Template $template
  * @param string         $blockName
  *
  * @return \Twig_Template|bool
  */
 private function findTemplateWithBlock(\Twig_Template $template, $blockName)
 {
     if ($template->hasBlock($blockName)) {
         return $template;
     }
     if (false === ($parent = $template->getParent([]))) {
         return false;
     }
     if (false !== $this->findTemplateWithBlock($parent, $blockName)) {
         return $template;
     }
     return false;
 }