public function generate(\blaze\lang\StringBuffer $buffer)
 {
     $buffer->append("\t" . '/**' . PHP_EOL);
     $buffer->append("\t" . ' * @var blaze\\collections\\Set[' . $this->classDescriptor->getFullName() . ']' . PHP_EOL);
     $buffer->append("\t" . ' */' . PHP_EOL);
     $buffer->append("\t" . 'private $');
     $buffer->append($this->fieldDescriptor->getName());
     $buffer->append(';' . PHP_EOL . PHP_EOL);
     $buffer->append("\t" . '/**' . PHP_EOL);
     $buffer->append("\t" . ' * @return blaze\\collections\\Set[' . $this->classDescriptor->getFullName() . ']' . PHP_EOL);
     $buffer->append("\t" . ' */' . PHP_EOL);
     $buffer->append("\t" . 'public function get' . $this->fieldDescriptor->getName()->toUpperCase(true)->toNative() . '(){' . PHP_EOL);
     $buffer->append("\t" . "\t" . ' return $this->' . $this->fieldDescriptor->getName() . ';' . PHP_EOL);
     $buffer->append("\t" . '}' . PHP_EOL . PHP_EOL);
     $buffer->append("\t" . '/**' . PHP_EOL);
     $buffer->append("\t" . ' * @param blaze\\collections\\Set[' . $this->classDescriptor->getFullName() . '] $' . $this->fieldDescriptor->getName() . PHP_EOL);
     $buffer->append("\t" . ' */' . PHP_EOL);
     $buffer->append("\t" . 'public function set' . $this->fieldDescriptor->getName()->toUpperCase(true)->toNative() . '($' . $this->fieldDescriptor->getName() . '){' . PHP_EOL);
     $buffer->append("\t" . "\t" . ' $this->' . $this->fieldDescriptor->getName() . ' = $' . $this->fieldDescriptor->getName() . ';' . PHP_EOL);
     $buffer->append("\t" . '}' . PHP_EOL . PHP_EOL);
 }
Example #2
0
 /**
  *
  * @param \DOMNode $xmlNode 
  */
 private function parseCollection(\DOMNode $xmlNode)
 {
     $collection = new \blaze\persistence\meta\CollectionFieldDescriptor();
     $field = new \blaze\persistence\meta\SingleFieldDescriptor();
     $field->setName($xmlNode->getAttribute('name'));
     $field->setType(new \blaze\lang\String('blaze\\collections\\Set'));
     $collection->setFieldDescriptor($field);
     $tbl = $xmlNode->getAttribute('table');
     if ($tbl !== '') {
         // many-to-many
         $collection->setTableDescriptor(\blaze\persistence\meta\TableDescriptor::getTableDescriptor($tbl));
         $column = new \blaze\persistence\meta\ColumnDescriptor();
         $column->setName($xmlNode->getAttribute('column'));
         $collection->setColumnDescriptor($column);
         foreach ($xmlNode->childNodes as $node) {
             if ($node->localName === 'many-to-many') {
                 $collection->setClassDescriptor(\blaze\persistence\meta\ClassDescriptor::getClassDescriptor($node->getAttribute('class')));
                 $column = new \blaze\persistence\meta\ColumnDescriptor();
                 $column->setName($node->getAttribute('column'));
                 $collection->setJunctionColumnDescriptor($column);
             }
         }
     } else {
         // one-to-many
         $column = new \blaze\persistence\meta\ColumnDescriptor();
         $column->setName($xmlNode->getAttribute('column'));
         $collection->setColumnDescriptor($column);
         foreach ($xmlNode->childNodes as $node) {
             if ($node->localName === 'one-to-many') {
                 $collection->setClassDescriptor(\blaze\persistence\meta\ClassDescriptor::getClassDescriptor($node->getAttribute('class')));
             }
         }
     }
     return $collection;
 }
 /**
  *
  * @param \DOMDocument $doc
  * @param \DOMElement $elem
  * @param blaze\collections\ListI[blaze\ds\meta\ColumnMetaData] $columns
  */
 private function reverseForeignColumns(\blaze\persistence\meta\ClassDescriptor $elem, $columns)
 {
     $usedNames = array();
     foreach ($columns as $column) {
         $foreignConstraint = null;
         foreach ($column->getConstraints() as $constraint) {
             if ($constraint instanceof \blaze\ds\meta\ForeignKeyMetaData) {
                 $foreignConstraint = $constraint;
                 break;
             }
         }
         $field = new \blaze\persistence\meta\SingleFieldDescriptor();
         $name = $this->getMemberName($foreignConstraint->getReferencedColumn()->getTable()->getTableName());
         if (array_key_exists($name, $usedNames)) {
             $name .= $usedNames[$name]++;
         } else {
             $usedNames[$name] = 0;
         }
         $field->setName($name);
         $field->setType($this->package . '\\' . $this->getClassName($foreignConstraint->getReferencedColumn()->getTable()->getTableName()));
         $col = new \blaze\persistence\meta\ColumnDescriptor();
         $col->apply($column);
         $field->setColumnDescriptor($col);
         $elem->addSingleField($field);
     }
 }