コード例 #1
0
 /**
  * Every import defined on parent level.
  *
  * @return ImportInterface[]
  */
 public function getImports()
 {
     $supervisor = $this->parent->getSupervisor();
     if (!$supervisor instanceof Templater) {
         throw new TemplaterException("ExtendsBehaviour must be executed using Templater.", $this->token);
     }
     return $supervisor->getImports();
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function createNode()
 {
     //We need node with content being importer
     $node = $this->templater->createNode($this->location, '', $this->token);
     //Let's register user defined blocks (context and attributes) as placeholders
     $node->registerBlock(self::CONTEXT_BLOCK, [], [$this->createPlaceholder(self::CONTEXT_BLOCK, $contextID)], true);
     foreach ($this->attributes as $attribute => $value) {
         //Attributes counted as blocks to replace elements in included node
         $node->registerBlock($attribute, [], [$value], true);
     }
     //We now have to compile node content to pass it's body to parent node
     $content = $node->compile($outerBlocks);
     //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. Templater to decide.
     $content = $this->templater->exportBlocks($content, $outerBlocks);
     //Let's parse complied content without any imports (to prevent collision)
     $templater = clone $this->templater;
     $templater->flushImports();
     //Outer content must be protected using unique names
     $rebuilt = new Node($templater, $templater->uniquePlaceholder(), $content);
     if ($contextBlock = $rebuilt->findNode($contextID)) {
         //Now we can mount our content block
         $contextBlock->addNode($this->getContext());
     }
     return $rebuilt;
 }
コード例 #3
0
ファイル: Node.php プロジェクト: jwdeitch/components
 /**
  * Replace node content with content provided by external node, external node can still use
  * content of parent block by defining block named identical to it's parent.
  *
  * @param Node $node
  */
 private function replaceNode(Node $node)
 {
     //Looking for parent block call
     if (!empty($inner = $node->findNode($this->name))) {
         //This construction allows child block use parent content
         $inner->nodes = $this->nodes;
     }
     $this->nodes = $node->nodes;
 }
コード例 #4
0
ファイル: TemplateProcessor.php プロジェクト: jwdeitch/spiral
 /**
  * {@inheritdoc}
  *
  * @throws TemplaterException
  */
 public function process($source)
 {
     try {
         $root = new Node($this, '@root', $source);
     } catch (\Exception $exception) {
         throw $this->clarifyException($exception);
     }
     return $root->compile();
 }