/** * EloquentModel constructor. * @param string $className * @param string $baseClassName * @param string|null $tableName */ public function __construct($className, $baseClassName, $tableName = null) { $this->setName(new ClassNameModel($className, ClassHelper::getShortClassName($baseClassName))); $this->addUses(new UseClassModel(ltrim($baseClassName, '\\'))); $this->tableName = $tableName ?: TitleHelper::getDefaultTableName($className); if ($this->tableName !== TitleHelper::getDefaultTableName($className)) { $property = new PropertyModel('table', 'protected', $this->tableName); $property->setDocBlock(new DocBlockModel('The table associated with the model.', '', '@var string')); $this->addProperty($property); } }
/** * @inheritdoc */ public function process(EloquentModel $model, Config $config) { $className = $config->get('class_name'); $baseClassName = $config->get('base_class_name'); $tableName = $config->get('table_name'); $model->setName(new ClassNameModel($className, $this->helper->getShortClassName($baseClassName))); $model->addUses(new UseClassModel(ltrim($baseClassName, '\\'))); $model->setTableName($tableName ?: $this->helper->getDefaultTableName($className)); if ($model->getTableName() !== $this->helper->getDefaultTableName($className)) { $property = new PropertyModel('table', 'protected', $model->getTableName()); $property->setDocBlock(new DocBlockModel('The table associated with the model.', '', '@var string')); $model->addProperty($property); } }
/** * @inheritdoc */ public function process(EloquentModel $model, Config $config) { if ($config->get('no_timestamps') === true) { $pNoTimestamps = new PropertyModel('timestamps', 'public', false); $pNoTimestamps->setDocBlock(new DocBlockModel('Indicates if the model should be timestamped.', '', '@var bool')); $model->addProperty($pNoTimestamps); } if ($config->has('date_format')) { $pDateFormat = new PropertyModel('dateFormat', 'protected', $config->get('date_format')); $pDateFormat->setDocBlock(new DocBlockModel('The storage format of the model\'s date columns.', '', '@var string')); $model->addProperty($pDateFormat); } if ($config->has('connection')) { $pConnection = new PropertyModel('connection', 'protected', $config->get('connection')); $pConnection->setDocBlock(new DocBlockModel('The connection name for the model.', '', '@var string')); $model->addProperty($pConnection); } }
/** * @inheritdoc */ public function process(EloquentModel $model, Config $config) { $schemaManager = $this->databaseManager->connection()->getDoctrineSchemaManager(); $prefix = $this->databaseManager->connection()->getTablePrefix(); $tableDetails = $schemaManager->listTableDetails($prefix . $model->getTableName()); $primaryColumnNames = $tableDetails->getPrimaryKey()->getColumns(); $columnNames = []; foreach ($tableDetails->getColumns() as $column) { $model->addProperty(new VirtualPropertyModel($column->getName(), $this->typeRegistry->resolveType($column->getType()->getName()))); if (!in_array($column->getName(), $primaryColumnNames)) { $columnNames[] = $column->getName(); } } $fillableProperty = new PropertyModel('fillable'); $fillableProperty->setAccess('protected')->setValue($columnNames)->setDocBlock(new DocBlockModel('@var array')); $model->addProperty($fillableProperty); return $this; }
/** * @param EloquentModel $model * @return $this */ protected function setFields(EloquentModel $model) { $tableDetails = $this->manager->listTableDetails($model->getTableName()); $primaryColumnNames = $tableDetails->getPrimaryKey()->getColumns(); $columnNames = []; foreach ($tableDetails->getColumns() as $column) { $model->addProperty(new VirtualPropertyModel($column->getName(), $this->resolveType($column->getType()->getName()))); if (!in_array($column->getName(), $primaryColumnNames)) { $columnNames[] = $column->getName(); } } $fillableProperty = new PropertyModel('fillable'); $fillableProperty->setAccess('protected')->setValue($columnNames)->setDocBlock(new DocBlockModel('@var array')); $model->addProperty($fillableProperty); return $this; }