Skip to content

Remove doctrine #1512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5296aad
Remove doctrine
barryvdh Feb 7, 2024
a56ed20
Fix tests
barryvdh Feb 7, 2024
e84463c
normalize composer.json
barryvdh Feb 7, 2024
8d28142
Add back platform
barryvdh Feb 7, 2024
ae54d75
Bump integration versions
barryvdh Feb 7, 2024
1f15faa
composer fix-style
Feb 7, 2024
a94383d
Fix stability
barryvdh Feb 7, 2024
8585c00
Bump minimum to 10.36
barryvdh Feb 7, 2024
b4db40d
Bump minimum to 10.38
barryvdh Feb 7, 2024
61fff6b
More types
barryvdh Feb 7, 2024
b74a5b2
Fast fail off
barryvdh Feb 7, 2024
b2ae029
Bump docblock
barryvdh Feb 7, 2024
6b4b1b0
Merge branch 'master' into feat-no-doctrine
barryvdh Feb 7, 2024
49e7fbc
composer fix-style
Feb 7, 2024
ad80415
Merge branch 'master' into feat-no-doctrine
barryvdh Feb 7, 2024
0809ab5
add bpchar
barryvdh Feb 8, 2024
fa77955
Merge branch 'master' into feat-no-doctrine
barryvdh Feb 8, 2024
6529f18
Use match for type detection
barryvdh Feb 8, 2024
8ecf2f6
Use driverName
barryvdh Feb 8, 2024
7d5eee7
fix match
barryvdh Feb 8, 2024
bbb2a7f
TWeak types
barryvdh Feb 8, 2024
b802d4f
Merge remote-tracking branch 'origin/master' into feat-no-doctrine
barryvdh Feb 8, 2024
31aebf2
Update snapshots
barryvdh Feb 8, 2024
7b9c4f5
Remove testbench 7
barryvdh Feb 8, 2024
5b989a7
composer fix-style
Feb 8, 2024
7f0dd9c
Update src/Console/ModelsCommand.php
barryvdh Feb 14, 2024
a48b17c
Update src/Console/ModelsCommand.php
barryvdh Feb 14, 2024
9848f11
Tweak bool
barryvdh Feb 14, 2024
87ee284
Update src/Console/ModelsCommand.php
barryvdh Feb 14, 2024
b6d3b72
composer fix-style
Feb 14, 2024
3da8278
Remove custom types, default to string
barryvdh Feb 15, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/fix-code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.3
coverage: none

- name: Install dependencies
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/run-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.3, 8.2, 8.1, 8.0]
laravel: [10.*, 9.*]
exclude:
- php: 8.0
laravel: 10.*
- php: 8.3
laravel: 9.*
php: [8.3, 8.2, 8.1]
laravel: [10.*]

name: P${{ matrix.php }} - Laravel${{ matrix.laravel }}
steps:
- name: Checkout code
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
coverage: none
extensions: pdo_sqlite

Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ jobs:
COMPOSER_NO_INTERACTION: 1

strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019]
php: [8.3, 8.2, 8.1, 8.0]
laravel: [9.*, 10.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- php: 8.0
laravel: 10.*
- php: 8.0
dependency-version: prefer-lowest
php: [8.3, 8.2, 8.1]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]

steps:
- name: Set git to use LF
if: ${{ matrix.os == 'windows-2019' }}
Expand All @@ -50,7 +47,7 @@ jobs:
composer remove vimeo/psalm --no-update --dev
composer remove friendsofphp/php-cs-fixer --no-update --dev
composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress
composer update --prefer-dist --no-progress
composer update --prefer-dist --no-progress --${{ matrix.stability }}

- name: Execute Unit Tests
run: composer test-ci
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"require": {
"php": "^8.0",
"ext-json": "*",
"barryvdh/reflection-docblock": "^2.0.6",
"barryvdh/reflection-docblock": "^2.1.1",
"composer/class-map-generator": "^1.0",
"doctrine/dbal": "^2.6 || ^3.1.4",
"illuminate/console": "^9 || ^10",
"illuminate/filesystem": "^9 || ^10",
"illuminate/support": "^9 || ^10",
"illuminate/console": "^10",
"illuminate/database": "^10.38",
"illuminate/filesystem": "^10",
"illuminate/support": "^10",
"nikic/php-parser": "^4.18 || ^5",
"phpdocumentor/type-resolver": "^1.1.0"
},
Expand All @@ -37,7 +37,7 @@
"illuminate/config": "^9 || ^10",
"illuminate/view": "^9 || ^10",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^7 || ^8",
"orchestra/testbench": "^8",
"phpunit/phpunit": "^9",
"spatie/phpunit-snapshot-assertions": "^4",
"vimeo/psalm": "^5.4"
Expand Down
126 changes: 46 additions & 80 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag;
use Composer\ClassMapGenerator\ClassMapGenerator;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Types\Type;
use Illuminate\Console\Command;
use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
Expand All @@ -39,6 +37,7 @@
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Schema\Builder;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -244,8 +243,6 @@ protected function generateDocs($loadModels, $ignore = '')
*/
\n\n";

$hasDoctrine = interface_exists('Doctrine\DBAL\Driver');

if (empty($loadModels)) {
$models = $this->loadModels();
} else {
Expand Down Expand Up @@ -288,9 +285,7 @@ protected function generateDocs($loadModels, $ignore = '')

$model = $this->laravel->make($name);

if ($hasDoctrine) {
$this->getPropertiesFromTable($model);
}
$this->getPropertiesFromTable($model);

if (method_exists($model, 'getCasts')) {
$this->castPropertiesType($model);
Expand All @@ -314,13 +309,6 @@ protected function generateDocs($loadModels, $ignore = '')
}
}

if (!$hasDoctrine) {
$this->error(
'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. ' .
'Please require that in your composer.json and run `composer update`.'
);
}

return $output;
}

Expand Down Expand Up @@ -508,86 +496,65 @@ protected function getTypeOverride($type)
*
* @param Model $model
*
* @throws DBALException If custom field failed to register
*/
public function getPropertiesFromTable($model)
{
$database = $model->getConnection()->getDatabaseName();
$table = $model->getConnection()->getTablePrefix() . $model->getTable();
$schema = $model->getConnection()->getDoctrineSchemaManager();
$databasePlatform = $schema->getDatabasePlatform();
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');
$table = $model->getTable();
$schema = $model->getConnection()->getSchemaBuilder();
$columns = $schema->getColumns($table);
$driverName = $model->getConnection()->getDriverName();

if (strpos($table, '.')) {
[$database, $table] = explode('.', $table);
}

$platformName = $databasePlatform->getName();
$customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", []);
foreach ($customTypes as $yourTypeName => $doctrineTypeName) {
try {
if (!Type::hasType($yourTypeName)) {
Type::addType($yourTypeName, get_class(Type::getType($doctrineTypeName)));
}
} catch (DBALException $exception) {
$this->error("Failed registering custom db type \"$yourTypeName\" as \"$doctrineTypeName\"");
throw $exception;
}
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
}

$columns = $schema->listTableColumns($table, $database);

if (!$columns) {
return;
}

$this->setForeignKeys($schema, $table);
foreach ($columns as $column) {
$name = $column->getName();
$name = $column['name'];
if (in_array($name, $model->getDates())) {
$type = $this->dateClass;
} else {
$type = $column->getType()->getName();
switch ($type) {
case 'string':
case 'text':
case 'date':
case 'time':
case 'guid':
case 'datetimetz':
case 'datetime':
case 'decimal':
case 'binary':
$type = 'string';
break;
case 'integer':
case 'bigint':
case 'smallint':
$type = 'integer';
break;
case 'boolean':
switch ($platformName) {
case 'sqlite':
case 'mysql':
$type = 'integer';
break;
default:
$type = 'boolean';
break;
}
break;
case 'float':
$type = 'float';
break;
default:
$type = 'mixed';
break;
}
// Allow to register custom types
$type = $this->laravel['config']->get("ide-helper.custom_db_types.{$driverName}.{$column['type_name']}", null);

// mysql and sqlite drivers return tinyint(1) as integer, not as bool
$type ??= $column['type'] === 'tinyint(1)' && !in_array($driverName, ['mysql', 'sqlite']) ? 'boolean' : null;

// Match other types to php equivalent
$type ??= match ($column['type_name']) {
'varchar', 'nvarchar',
'char', 'bpchar', 'nchar',
'binary', 'varbinary', 'blob', 'bytea',
'decimal', 'numeric',
'date', 'time', 'timetz', 'datetime', 'datetime2', 'datetimeoffset', 'timestamp', 'timestamptz', 'year',
'uuid', 'uniqueidentifier',
'json', 'jsonb',
'macaddr', 'inet',
'enum', 'set',
'geography', 'geometry', 'geometrycollection', 'linestring', 'multilinestring', 'multipoint', 'multipolygon', 'point', 'polygon',
'text', 'tinytext', 'longtext', 'mediumtext' => 'string',

'tinyint',
'integer', 'int', 'int4',
'smallint', 'int2',
'mediumint',
'bigint', 'int8' => 'integer',

'boolean', 'bool', 'bit' => 'boolean',

'float', 'real', 'float4',
'double', 'float8' => 'float',

default => 'mixed',
};
}

$comment = $column->getComment();
if (!$column->getNotnull()) {
$comment = $column['comment'];
if ($column['nullable']) {
$this->nullableColumns[$name] = true;
}
$this->setProperty(
Expand All @@ -596,7 +563,7 @@ public function getPropertiesFromTable($model)
true,
true,
$comment,
!$column->getNotnull()
$column['nullable']
);
if ($this->write_model_magic_where) {
$builderClass = $this->write_model_external_builder_methods
Expand Down Expand Up @@ -1681,14 +1648,13 @@ protected function runModelHooks($model): void
}

/**
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
* @param Builder $schema
* @param string $table
* @throws DBALException
*/
protected function setForeignKeys($schema, $table)
{
foreach ($schema->listTableForeignKeys($table) as $foreignKeyConstraint) {
foreach ($foreignKeyConstraint->getLocalColumns() as $columnName) {
foreach ($schema->getForeignKeys($table) as $foreignKeyConstraint) {
foreach ($foreignKeyConstraint['columns'] as $columnName) {
$this->foreignKeyConstraintsColumns[] = $columnName;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $binary_nullable
* @property string $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $binary_nullable
* @property string $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $binary_nullable
* @property string $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $binary_nullable
* @property string $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
* @property string $timestamptzNotNullable
* @property integer|null $yearNullable
* @property integer $yearNotNullable
* @property mixed|null $binaryNullable
* @property mixed $binaryNotNullable
* @property string|null $binaryNullable
* @property string $binaryNotNullable
* @property string|null $uuidNullable
* @property string $uuidNotNullable
* @property string|null $ipaddressNullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $binary_nullable
* @property string $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $binary_nullable
* @property string $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $binary_nullable
* @property string $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
Expand Down
Loading