Beispiel #1
0
 /**
  * @param Table $table
  * @param PhpNamespace $namespace
  * @return mixed
  */
 protected function getRealUse(Table $table, PhpNamespace $namespace)
 {
     $use = $namespace->unresolveName($this->resolver->resolveEntityNamespace($table) . Helpers::NS . $this->resolver->resolveEntityName($table));
     if (Strings::compare($use, $table->getName())) {
         return NULL;
     }
     return $use;
 }
Beispiel #2
0
 /**
  * @param Database $database
  */
 public function generate(Database $database)
 {
     foreach ($database->getTables() as $table) {
         // Create namespace and inner class
         $namespace = new PhpNamespace($this->resolver->resolveEntityNamespace($table));
         $class = $namespace->addClass($this->resolver->resolveEntityName($table));
         // Detect extends class
         if (($extends = $this->config->get('entity.extends')) === NULL) {
             $extends = $this->config->get('nextras.orm.class.entity');
         }
         // Add namespace and extends class
         $namespace->addUse($extends);
         $class->setExtends($extends);
         // Add table columns
         foreach ($table->getColumns() as $column) {
             if ($this->config->get('generator.entity.exclude.primary')) {
                 if ($column->isPrimary()) {
                     continue;
                 }
             }
             foreach ($this->decorators as $decorator) {
                 $decorator->doDecorate($column, $class, $namespace);
             }
         }
         // Save file
         $this->generateFile($this->resolver->resolveEntityFilename($table), (string) $namespace);
     }
     // Generate abstract base class
     if ($this->config->get('entity.extends') !== NULL) {
         // Create abstract class
         $namespace = new PhpNamespace($this->config->get('entity.namespace'));
         $class = $namespace->addClass(Helpers::extractShortName($this->config->get('entity.extends')));
         $class->setAbstract(TRUE);
         // Add extends from ORM/Entity
         $extends = $this->config->get('nextras.orm.class.entity');
         $namespace->addUse($extends);
         $class->setExtends($extends);
         // Save file
         $this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->get('entity.extends')), $this->config->get('entity.folder')), (string) $namespace);
     }
 }