コード例 #1
0
ファイル: helpers.php プロジェクト: proai/laravel-datamapper
 /**
  * Get the classname of an entity that is used for the mapped eloquent model.
  *
  * @param string $class
  * @param boolean $check
  * @return string
  */
 function get_mapped_model($class, $check = true)
 {
     $model = get_mapped_model_namespace() . '\\Entity' . get_mapped_model_hash($class);
     if (class_exists($model) || !$check) {
         return $model;
     } else {
         throw new Exception('There is no mapped Eloquent class for class "' . $class . '".');
     }
 }
コード例 #2
0
 /**
  * Generate model from metadata.
  *
  * @param \ProAI\Datamapper\Metadata\Definitions\Entity $entityMetadata
  * @return void
  */
 public function generateModel($entityMetadata)
 {
     $stub = $this->stubs['model'];
     // header
     $this->replaceNamespace(get_mapped_model_namespace(), $stub);
     $this->replaceClass(class_basename(get_mapped_model($entityMetadata['class'], false)), $stub);
     $this->replaceMappedClass($entityMetadata['class'], $stub);
     // traits
     $this->replaceTraits($entityMetadata, $stub);
     // table name
     $this->replaceTable($entityMetadata['table']['name'], $stub);
     // primary key
     $columnMetadata = $this->getPrimaryKeyColumn($entityMetadata);
     $this->replacePrimaryKey($columnMetadata['name'], $stub);
     $this->replaceIncrementing(!empty($columnMetadata['options']['autoIncrement']), $stub);
     $this->replaceAutoUuids($entityMetadata, $stub);
     // timestamps
     $this->replaceTimestamps($entityMetadata['timestamps'], $stub);
     // misc
     $this->replaceTouches($entityMetadata['touches'], $stub);
     $this->replaceWith($entityMetadata['with'], $stub);
     $this->replaceVersioned($entityMetadata['versionTable'], $stub);
     $this->replaceMorphClass($entityMetadata['morphClass'], $stub);
     // mapping data
     $this->replaceMapping($entityMetadata, $stub);
     // relations
     $this->replaceRelations($entityMetadata['relations'], $stub);
     $this->files->put($this->path . '/' . get_mapped_model_hash($entityMetadata['class']), $stub);
 }