/**
  * @param Database $database
  */
 public function generate(Database $database)
 {
     foreach ($database->getTables() as $table) {
         // Create namespace and inner class
         $namespace = new PhpNamespace($this->resolver->resolveRepositoryNamespace($table));
         $class = $namespace->addClass($this->resolver->resolveRepositoryName($table));
         // Detect extends class
         if (($extends = $this->config->get('repository.extends')) !== NULL) {
             $namespace->addUse($extends);
             $class->setExtends($extends);
         }
         // Save file
         $this->generateFile($this->resolver->resolveRepositoryFilename($table), (string) $namespace);
     }
     // Generate abstract base class
     if ($this->config->get('repository.extends') !== NULL) {
         // Create abstract class
         $namespace = new PhpNamespace($this->config->get('repository.namespace'));
         $class = $namespace->addClass(Helpers::extractShortName($this->config->get('repository.extends')));
         $class->setAbstract(TRUE);
         // Add extends from ORM/Repository
         $extends = $this->config->get('nextras.orm.class.repository');
         $namespace->addUse($extends);
         $class->setExtends($extends);
         // Save file
         $this->generateFile($this->resolver->resolveFilename(Helpers::extractShortName($this->config->get('repository.extends')), $this->config->get('repository.folder')), (string) $namespace);
     }
 }
Exemple #2
0
 /**
  * @return Database
  */
 public function analyse()
 {
     $database = new Database();
     foreach ($this->driver->getTables() as $tArray) {
         $table = new Table();
         $table->setName($tArray['name']);
         $this->analyseColumns($table);
         $this->analyseIndexes($table);
         $database->addTable($table);
     }
     return $database;
 }
Exemple #3
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);
     }
 }