Example #1
0
 /**
  * Add document (class) to UML.
  *
  * @param DocumentSchema $document
  */
 protected function renderDocument(DocumentSchema $document)
 {
     $parent = $document->getParentDocument();
     $class = $this->normalizeName($document->getName());
     if ($document->isAbstract()) {
         $this->line("abstract class {$class} { ");
     } else {
         $this->line("class {$class} { ");
     }
     //Document fields
     foreach ($document->getFields() as $field => $type) {
         if (is_array($type)) {
             $type = $type[0] . '[]';
         }
         $field = $this->access[AbstractElement::ACCESS_PUBLIC] . ' ' . addslashes($type) . ' ' . $field;
         $this->line($field, 1);
     }
     //Methods
     foreach ($document->getLocalMethods() as $method) {
         $this->renderMethod($method);
     }
     $this->line('}', 0, true);
     //Parent class relation
     if (!empty($parent)) {
         $this->line("{$class} --|> " . $this->normalizeName($parent->getName()), 0, true);
     }
     foreach ($document->getCompositions() as $name => $composition) {
         if (!empty($parent) && isset($parent->getCompositions()[$name])) {
             //Already declared by parent
             continue;
         }
         if ($composition['type'] == ODM::CMP_MANY) {
             $this->line("{$class} ..*" . $this->normalizeName($composition['class']) . ":{$name}", 0, true);
         } else {
             $this->line("{$class} --* " . $this->normalizeName($composition['class']) . ":{$name}", 0, true);
         }
     }
     foreach ($document->getAggregations() as $name => $aggregation) {
         //Show connections only for parent document
         if (!empty($parent) && isset($parent->getAggregations()[$name])) {
             continue;
         }
         if ($aggregation['type'] == Document::MANY) {
             $this->line("{$class} ..o " . $this->normalizeName($aggregation['class']) . ":{$name}", 0, true);
         } else {
             $this->line("{$class} --o " . $this->normalizeName($aggregation['class']) . ":{$name}", 0, true);
         }
     }
 }
Example #2
0
 /**
  * Sort child documents in order or declared fields.
  *
  * @param DocumentSchema $childA
  * @param DocumentSchema $childB
  * @return int
  */
 private function sortChildren(DocumentSchema $childA, DocumentSchema $childB)
 {
     return count($childA->getFields()) > count($childB->getFields());
 }