public function start(ChariotContext $context, ChariotTagRepository $repository)
 {
     $currentNode = $context->currentNode;
     if (null === $currentNode) {
         // nop ?
         return;
     }
     $currentValue = $context->currentValue;
     $currentIndex = $context->currentIndex;
     $isEven = $currentIndex % 2 === 0;
     $contextValues = $context->getAttributes();
     $xpath = $context->getGlobalAttribute('xpath');
     foreach ($xpath->query('*[@c:value]', $currentNode) as $child) {
         $key = $child->getAttributeNodeNS(self::URN, 'value')->nodeValue;
         $value = ChariotTagUtils::lookupVariable($contextValues, $currentValue, $key);
         if (is_array($currentValue)) {
             $currentValue['_index'] = $currentIndex;
             $currentValue['_odd'] = !$isEven;
             $currentValue['_even'] = $isEven;
             $child->nodeValue = $value;
         } else {
             if (is_object($currentValue)) {
             } else {
                 $child->nodeValue = $value;
             }
         }
         $child->removeAttributeNS(self::URN, 'value');
     }
 }
 protected static function notExists(DOMXPath $xpath, ChariotContext $context, ChariotTagRepository $repository)
 {
     $nodes = array();
     if (isset($context->currentNode)) {
         $nodes = $xpath->query('*[@c:notExists]', $context->currentNode);
     } else {
         $nodes = $xpath->query('//*[@c:notExists]');
     }
     foreach ($nodes as $child) {
         $existsValue = $child->getAttributeNodeNS(self::URN, 'notExists')->nodeValue;
         $child->removeAttributeNS(self::URN, 'notExists');
         if ($context->hasAttribute($existsValue)) {
             $child->nodeValue = '';
             $child->parentNode->removeChild($child);
             continue;
         }
         $ctx = $context->createChild();
         $ctx->currentIndex = -1;
         $ctx->currentValue = null;
         $ctx->currentNode = $child;
         $repos = clone $repository;
         foreach ($repos as $r) {
             $r->start($ctx, $repository);
         }
     }
 }
 public function testNotExists()
 {
     $context = new ChariotContext();
     $context->setAttribute('Hoge', 'hello world');
     $chariot = new Chariot();
     $chariot->setTemplateDirectory(dirname(__FILE__) . '/templates');
     $chariot->setContext($context);
     $result = $chariot->render('example/exists2');
     $this->assertEquals(file_get_contents(dirname(__FILE__) . '/results/example/exists2.html'), $result, 'notExistsでは存在しない値も出力すること');
 }
 public function start(ChariotContext $context, ChariotTagRepository $repository)
 {
     $rootDocument = $context->getGlobalAttribute('document');
     $rootElement = $rootDocument->createElement('div');
     $xpath = new DOMXPath($rootDocument);
     $xpath->registerNamespace('c', ChariotTagHandler::URN);
     $context->setGlobalAttibute('xpath', $xpath);
     $context->setGlobalAttibute('rootElement', $rootElement);
     foreach ($xpath->query('//*[@class="dummy"]') as $dummyNode) {
         $dummyNode->parentNode->removeChild($dummyNode);
     }
     $parsed = false;
     foreach ($xpath->query('//*[@c:template]') as $child) {
         $templateName = $child->getAttributeNodeNS(ChariotTagHandler::URN, 'template')->nodeValue;
         $child->removeAttributeNS(ChariotTagHandler::URN, 'template');
         $className = '';
         if ($child->hasAttribute('class')) {
             $className = $child->getAttribute('class');
         }
         $child->setAttribute('class', $className . ' ' . $templateName);
         $ctx = $context->createChild();
         $ctx->currentNode = $child;
         $ctx->currentTemplateName = $templateName;
         foreach ($repository as $handler) {
             $handler->start($ctx, $repository);
         }
         $rootElement->appendChild($child);
         $parsed = true;
     }
     if ($parsed) {
         // remove all nodes
         $rootDocument->removeChild($rootDocument->firstChild);
         // as root(first) element
         $rootDocument->appendChild($rootElement);
         // remove all chariot urn
         //foreach($rootDocument->getElementsByTagNameNS(ChariotTagHandler::URN, '*') as $node){
         //}
     }
     return $rootDocument;
 }
 public function start(ChariotContext $context, ChariotTagRepository $repository)
 {
     $xpath = $context->getGlobalAttribute('xpath');
     $nodes = array();
     if (isset($context->currentNode)) {
         $nodes = $xpath->query('*[@c:foreach]', $context->currentNode);
     } else {
         $nodes = $xpath->query('//*[@c:foreach]');
     }
     foreach ($nodes as $child) {
         $foreachValue = $child->getAttributeNodeNS(self::URN, 'foreach')->nodeValue;
         $child->removeAttributeNS(self::URN, 'foreach');
         $children = array();
         $replacement = $context->getAttribute($foreachValue);
         foreach ($replacement as $index => $replaceValue) {
             foreach ($child->childNodes as $c) {
                 $clone = $c->cloneNode(true);
                 $ctx = $context->createChild();
                 $ctx->currentNode = $clone;
                 $ctx->currentIndex = $index;
                 $ctx->currentValue = $replaceValue;
                 $repos = clone $repository;
                 foreach ($repos as $r) {
                     $r->start($ctx, $repository);
                 }
                 $children[] = $clone;
             }
         }
         // remove all children
         $child->nodeValue = '';
         // append new clone nodes
         foreach ($children as $_cloneChild) {
             $child->appendChild($_cloneChild);
         }
     }
 }