private function getCreateClassSql(OClass $node)
 {
     $sql = sprintf('CREATE CLASS %s', $node->getName());
     if ($node->getSuperClass()) {
         $sql .= sprintf(' EXTENDS %s', $node->getSuperClass()->getName());
     }
     if ($node->isAbstract()) {
         $sql .= ' ABSTRACT';
     }
     return $sql;
 }
Ejemplo n.º 2
0
 /**
  * @test
  * @depends getClass_returns_instance
  *
  * @param OClass $class
  */
 public function class_has_expected_properties(OClass $class)
 {
     $expected = ['articles', 'username', 'status', 'phonenumbers', 'name'];
     sort($expected);
     $props = $class->getProperties();
     $names = array_keys($props);
     sort($names);
     $this->assertCount(5, $props, 'unexpected number of properties');
     $this->assertEquals($expected, $names, 'properties do not match');
     $p = $props['articles'];
 }
Ejemplo n.º 3
0
 /**
  * listClasses returns a list of available OrientDB classes for the current database
  *
  * @return OClass[]
  */
 public function listClasses()
 {
     $res = $this->_cn->getDatabaseInfo();
     /** @var OClass[] $hasSuper */
     $hasSuper = [];
     /** @var OClass[] $classes */
     $classes = [];
     foreach ($res['classes'] as $meta) {
         $classes[$meta['name']] = $c = new OClass($meta);
         if (!empty($meta->superClass)) {
             $hasSuper[] = $c;
         }
     }
     foreach ($hasSuper as $c) {
         $c->setSuperClass($classes[$c->getSuperClassName()]);
     }
     return $classes;
 }
Ejemplo n.º 4
0
 private function gatherProperties(ClassMetadata $class, OClass $oclass)
 {
     foreach ($class->fieldMappings as $mapping) {
         if (isset($mapping['inherited'])) {
             continue;
         }
         $name = $mapping['name'];
         if (OSchema::isSystemProperty($name)) {
             continue;
         }
         if (isset($mapping['association'])) {
             continue;
         }
         $options = ['readonly' => $mapping['readonly'], 'mandatory' => $mapping['mandatory'], 'min' => $mapping['min'], 'max' => $mapping['max'], 'regexp' => $mapping['regexp'], 'notNull' => !$mapping['nullable']];
         $oclass->addProperty($name, $mapping['type'], $options);
     }
     foreach ($class->associationMappings as $mapping) {
         if (isset($mapping['inherited'])) {
             continue;
         }
         if (isset($mapping['direction'])) {
             // no in / outgoing references
             continue;
         }
         $name = $mapping['name'];
         if (isset($mapping['targetDoc'])) {
             $linkedClass = $this->_dm->getClassMetadata($mapping['targetDoc'])->orientClass;
         } else {
             $linkedClass = null;
         }
         $options = ['notNull' => !$mapping['nullable'], 'linkedClass' => $linkedClass];
         $oclass->addProperty($name, $mapping['type'], $options);
     }
 }