Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/Processor/TableWithoutTimestamps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Krlove\EloquentModelGenerator\Processor;

use Illuminate\Database\DatabaseManager;
use Krlove\CodeGenerator\Model\DocBlockModel;
use Krlove\CodeGenerator\Model\PropertyModel;
use Krlove\CodeGenerator\Model\UseTraitModel;
use Krlove\EloquentModelGenerator\Config;
use Krlove\EloquentModelGenerator\Model\EloquentModel;

/**
* Class CustomPrimaryKeyProcessor
* @package Krlove\EloquentModelGenerator\Processor
*/
class TableWithoutTimestamps implements ProcessorInterface
{
/**
* @var DatabaseManager
*/
protected $databaseManager;

/**
* @var TypeRegistry
*/
protected $typeRegistry;

/**
* FieldProcessor constructor.
* @param DatabaseManager $databaseManager
*/
public function __construct(DatabaseManager $databaseManager)
{
$this->databaseManager = $databaseManager;
}

/**
* @inheritdoc
*/
public function process(EloquentModel $model, Config $config)
{
$schemaManager = $this->databaseManager->connection($config->get('connection'))->getDoctrineSchemaManager();
$prefix = $this->databaseManager->connection($config->get('connection'))->getTablePrefix();

$tableDetails = $schemaManager->listTableDetails($prefix . $model->getTableName());

if (isset($tableDetails->getColumns()['created_at']) || isset($tableDetails->getColumns()['updated_at'])) {
return;
}

$pNoTimestamps = new PropertyModel('timestamps', 'public', false);
$pNoTimestamps->setDocBlock(
new DocBlockModel('Indicates if the model should be timestamped.', '', '@var bool')
);
$model->addProperty($pNoTimestamps);
}

/**
* @inheritdoc
*/
public function getPriority()
{
return 6;
}
}
2 changes: 2 additions & 0 deletions src/Provider/GeneratorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Krlove\EloquentModelGenerator\Processor\NamespaceProcessor;
use Krlove\EloquentModelGenerator\Processor\RelationProcessor;
use Krlove\EloquentModelGenerator\Processor\TableNameProcessor;
use Krlove\EloquentModelGenerator\Processor\TableWithoutTimestamps;

/**
* Class GeneratorServiceProvider
Expand All @@ -38,6 +39,7 @@ public function register()
CustomPropertyProcessor::class,
TableNameProcessor::class,
CustomPrimaryKeyProcessor::class,
TableWithoutTimestamps::class,
], self::PROCESSOR_TAG);

$this->app->bind(EloquentModelBuilder::class, function ($app) {
Expand Down