/**
  * Create node to be injected into template at place of tag caused import.
  *
  * @return Node
  */
 public function createNode()
 {
     //Content of node to be imported
     $node = $this->supervisor->createNode($this->path, $this->token);
     //Let's register user defined blocks (context and attributes) as placeholders
     $node->mountBlock(self::CONTEXT_BLOCK, [], [$this->createPlaceholder(self::CONTEXT_BLOCK, $contextID)], true);
     foreach ($this->token[HtmlTokenizer::TOKEN_ATTRIBUTES] as $attribute => $value) {
         //Attributes counted as blocks to replace elements in included node
         $node->mountBlock($attribute, [], [$value], true);
     }
     //We now have to compile node content to pass it's body to parent node
     $content = $node->compile($dynamic);
     //Outer blocks (usually user attributes) can be exported to template using non default
     //rendering technique, for example every "extra" attribute can be passed to specific
     //template location. Stempler to decide.
     foreach ($this->supervisor->syntax()->blockExporters() as $exporter) {
         $content = $exporter->mountBlocks($content, $dynamic);
     }
     //Let's parse complied content without any imports (to prevent collision)
     $supervisor = clone $this->supervisor;
     $supervisor->flushImporters();
     //Outer content must be protected using unique names
     $rebuilt = new Node($supervisor, $supervisor->uniquePlaceholder(), $content);
     if (!empty($contextBlock = $rebuilt->findNode($contextID))) {
         //Now we can mount our content block
         $contextBlock->mountNode($this->contextNode());
     }
     return $rebuilt;
 }
Beispiel #2
0
 /**
  * @param Supervisor $supervisor
  * @param string     $path
  * @param array      $token
  */
 public function __construct(Supervisor $supervisor, $path, array $token = [])
 {
     $node = $supervisor->createNode($path, $token);
     $supervisor = $node->supervisor();
     if ($supervisor instanceof Supervisor) {
         $this->importers = $supervisor->getImporters();
     }
 }