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'); } }
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); } } }
public function start(ChariotContext $context, ChariotTagRepository $repository) { $xpath = $context->getGlobalAttribute('xpath'); self::exists($xpath, $context, $repository); self::notExists($xpath, $context, $repository); }