public function parseFile(\blaze\persistence\cfg\Configuration $config, $file)
 {
     $f = null;
     if ($file instanceof \blaze\io\File) {
         $f = $file;
     } else {
         $f = new \blaze\io\File(\blaze\lang\String::asNative($file));
     }
     $doc = new \DOMDocument();
     $doc->load($f->getAbsolutePath());
     $this->parseDom($config, $doc, $f->getName(), $f);
 }
Example #2
0
 /**
  *
  * @param \blaze\persistence\meta\ClassDescriptor $config
  * @param File $file
  */
 public function save(\blaze\persistence\meta\ClassDescriptor $config, $file)
 {
     $f = null;
     if ($file instanceof \blaze\io\File) {
         $f = $file;
     } else {
         $f = new \blaze\io\File(\blaze\lang\String::asNative($file));
     }
     $doc = new \DOMDocument();
     $root = $doc->createElement('persistence-mapping');
     $doc->appendChild($root);
     $node = $doc->createElement('class');
     $root->appendChild($node);
     AttributeUtil::set($node, 'package', $config->getPackage());
     AttributeUtil::set($node, 'name', $config->getName());
     AttributeUtil::set($node, 'schema', $config->getTableDescriptor()->getSchema());
     AttributeUtil::set($node, 'table', $config->getTableDescriptor()->getName());
     foreach ($config->getIdentifiers() as $member) {
         $this->saveId($node, $doc, $member);
     }
     foreach ($config->getSingleFields() as $member) {
         $this->saveField($node, $doc, $member);
     }
     foreach ($config->getCollectionFields() as $member) {
         $this->saveCollection($node, $doc, $member);
     }
     $doc->save($f->getAbsolutePath());
 }
Example #3
0
 private function handleChildren(\blaze\web\component\UIComponent $parent, $children, $compositionChildren)
 {
     $prefixComponents = array('b' => 'blaze\\web\\component\\html\\', 'e' => 'blaze\\web\\component\\event\\');
     foreach ($children as $node) {
         if ($node->nodeType == XML_ELEMENT_NODE) {
             if ($node->prefix == 'b' || $node->prefix == 'e') {
                 $class = ClassWrapper::forName($prefixComponents[$node->prefix] . ucfirst($node->localName));
                 $component = $class->newInstance();
                 if ($node->hasAttributes()) {
                     foreach ($node->attributes as $attribute) {
                         if ($attribute->nodeType == XML_ATTRIBUTE_NODE) {
                             $class->getMethod('set' . ucfirst($attribute->nodeName))->invoke($component, $attribute->nodeValue);
                         }
                     }
                 }
                 $parent->addChild($component);
                 if ($node->hasChildNodes()) {
                     $this->handleChildren($component, $node->childNodes, $compositionChildren);
                 }
             } else {
                 if ($node->prefix == 'ui') {
                     if ($node->localName == 'insert') {
                         if ($compositionChildren != null) {
                             $foundElem = $this->findCompositionDefinition($compositionChildren, $node->getAttribute('name'));
                             if ($foundElem == null) {
                                 $this->handleChildren($parent, $node->childNodes, $compositionChildren);
                             } else {
                                 $this->handleChildren($parent, $foundElem->childNodes, $compositionChildren);
                             }
                         } else {
                             $this->handleChildren($parent, $node->childNodes, $compositionChildren);
                         }
                     } else {
                         if ($node->localName == 'composite') {
                             $template = $node->getAttribute('template');
                             if ($template == '') {
                                 throw new Exception('No template view given');
                             }
                             $f = new \blaze\io\File($this->viewDir, $template);
                             if (!$f->exists()) {
                                 throw new \blaze\io\IOException('Template was not found');
                             }
                             $root = $this->getRoot($parent);
                             $newRoot = $this->parseAndCreateView($f, $node->childNodes);
                             $newRoot->setViewId($root->getViewId());
                             $this->views->put($newRoot->getViewId(), $newRoot);
                         }
                     }
                 } else {
                     $tag = '<' . $node->nodeName;
                     if ($node->hasAttributes()) {
                         foreach ($node->attributes as $attribute) {
                             if ($attribute->nodeType == XML_ATTRIBUTE_NODE) {
                                 $tag .= ' ' . $attribute->nodeName . '="' . $attribute->nodeValue . '"';
                             }
                         }
                     }
                     $parent->addChild(\blaze\web\component\html\PlainText::create()->setValue($tag . '>'));
                     if ($node->hasChildNodes()) {
                         $this->handleChildren($parent, $node->childNodes, $compositionChildren);
                     }
                     $parent->addChild(\blaze\web\component\html\PlainText::create()->setValue('</' . $node->nodeName . '>'));
                 }
             }
         } else {
             if ($node->nodeType == XML_TEXT_NODE) {
                 $content = trim($node->textContent);
                 if (strlen($content) != 0) {
                     $parent->addChild(\blaze\web\component\html\PlainText::create()->setValue($content));
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function clear()
 {
     foreach ($this->cacheDir->listFiles() as $file) {
         $file->delete();
     }
 }