Skip to content

Commit bf35ece

Browse files
authored
Merge pull request #1 from efureev/Laravel-11
feat: move to Laravel 11
2 parents 3f309c4 + 2b17374 commit bf35ece

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+551
-453
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
setup: [ 'basic', 'lowest', 'stable' ]
31-
php: [ '8.1', '8.2' , '8.3' ]
31+
php: [ '8.2' , '8.3' ]
3232

3333
services:
3434
postgres:
@@ -116,10 +116,10 @@ jobs:
116116
steps:
117117
- uses: actions/checkout@v4
118118

119-
- name: Use PHP 8.2
119+
- name: Use PHP 8.3
120120
uses: shivammathur/setup-php@v2 # Action page: <https://github.com/shivammathur/setup-php>
121121
with:
122-
php-version: '8.2'
122+
php-version: '8.3'
123123
extensions: mbstring
124124
coverage: xdebug
125125

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ Check MD [online][check-online].
99

1010
## [unreleased]
1111

12+
## [2.0.0] - 2024-03-13
13+
14+
### Added
15+
16+
- Add support Laravel 11
17+
18+
### Removed
19+
20+
- Remove support Laravel < 11
21+
- Remove support PHP < 8.2
22+
1223
## [1.11.0] - 2024-01-31
1324

1425
### Added

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
}
1818
],
1919
"require": {
20-
"php": "^8.1|^8.2|^8.3",
20+
"php": "^8.2|^8.3",
2121
"ext-pdo": "*",
22-
"illuminate/database": "^10.1",
23-
"doctrine/dbal": "^3.6"
22+
"illuminate/database": "^11.0"
2423
},
2524
"require-dev": {
26-
"phpunit/phpunit": "^10.0",
27-
"orchestra/testbench": "^8.0",
28-
"squizlabs/php_codesniffer": "^3.7"
25+
"phpunit/phpunit": "^11.0",
26+
"orchestra/testbench": "^9.0",
27+
"squizlabs/php_codesniffer": "^3.9"
2928
},
3029
"autoload": {
3130
"psr-4": {

phpunit.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
33
<coverage>
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
<exclude>
8-
<directory>./vendor</directory>
9-
</exclude>
104
<report>
115
<clover outputFile="./coverage/clover.xml"/>
126
<html outputDirectory="./coverage/html"/>
@@ -24,4 +18,12 @@
2418
<server name="APP_ENV" value="testing"/>
2519
<server name="APP_KEY" value="base64:VM+W1TpjK5cVtw1wHOPcu+e8mHiVYDuvgUJSLf+1QLA="/>
2620
</php>
21+
<source>
22+
<include>
23+
<directory suffix=".php">./src</directory>
24+
</include>
25+
<exclude>
26+
<directory>./vendor</directory>
27+
</exclude>
28+
</source>
2729
</phpunit>

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PHP Laravel Database Support
22

3-
![](https://img.shields.io/badge/php->=8.1|8.2-blue.svg)
4-
![](https://img.shields.io/badge/Laravel->=10.1-red.svg)
3+
![](https://img.shields.io/badge/php->=8.2|8.3-blue.svg)
4+
![](https://img.shields.io/badge/Laravel->=11.0-red.svg)
55
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5c8b9e85897f4c65b5a017d16f6af6cb)](https://app.codacy.com/manual/efureev/laravel-support-db)
66
![PHP Database Laravel Package](https://github.com/efureev/laravel-support-db/workflows/PHP%20Database%20Laravel%20Package/badge.svg)
77
[![Latest Stable Version](https://poser.pugx.org/efureev/laravel-support-db/v/stable?format=flat)](https://packagist.org/packages/efureev/laravel-support-db)
@@ -326,7 +326,7 @@ Schema::create(
326326
// or
327327

328328
Schema::create(self::TGT_TABLE, function (Blueprint $table) use ($tbl) {
329-
DB::statement('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');
329+
Schema::createExtensionIfNotExists('uuid-ossp');
330330

331331
$table->fromSelect(
332332
'select uuid_generate_v4() as id, key, title, sort from ' . $tbl
@@ -336,7 +336,7 @@ Schema::create(self::TGT_TABLE, function (Blueprint $table) use ($tbl) {
336336
// or
337337

338338
Schema::create(self::TGT_TABLE, function (Blueprint $table) use ($tbl) {
339-
DB::statement('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');
339+
Schema::createExtensionIfNotExists('uuid-ossp');
340340

341341
$table->fromSelect(
342342
'select uuid_generate_v4() as id, * ' . $tbl
@@ -383,8 +383,8 @@ The Schema facade supports the creation of extensions with the `createExtension`
383383
methods:
384384

385385
```php
386-
Schema::createExtension('tablefunc');
387-
Schema::createExtensionIfNotExists('tablefunc');
386+
Schema::createExtension('uuid-ossp');
387+
Schema::createExtensionIfNotExists('uuid-ossp');
388388
```
389389

390390
#### Dropping Extensions

src/Schema/Postgres/Blueprint.php

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Php\Support\Laravel\Database\Schema\Postgres;
66

7-
use Exception;
87
use Illuminate\Database\Query\Expression;
98
use Illuminate\Database\Schema\Blueprint as BaseBlueprint;
109
use Illuminate\Support\Facades\DB;
@@ -20,12 +19,6 @@
2019

2120
class Blueprint extends BaseBlueprint
2221
{
23-
/**
24-
* @param string $column
25-
* @param int $length
26-
*
27-
* @return ColumnDefinition
28-
*/
2922
public function bit(string $column, int $length): ColumnDefinition
3023
{
3124
return $this->addColumn('bit', $column, compact('length'));
@@ -45,40 +38,31 @@ public function numeric(string $column, ?int $precision = null, ?int $scale = nu
4538
return $this->addColumn('numeric', $column, compact('precision', 'scale'));
4639
}
4740

48-
/**
49-
* @param string $column
50-
* @param bool|callable|Expression|null $generate
51-
*
52-
* @return ColumnDefinition
53-
* @throws Exception
54-
*/
55-
public function generateUUID(string $column = 'id', $generate = true): ColumnDefinition
41+
public function generateUUID(string $column = 'id', bool|callable|Expression|null $default = true): ColumnDefinition
5642
{
5743
$defCol = $this->addColumn('uuid', $column);
58-
if ($generate === false) {
44+
if ($default === false) {
5945
return $defCol;
6046
}
6147

6248
DB::statement('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');
6349

6450
switch (true) {
65-
case is_bool($generate):
51+
case $default === true:
6652
$defaultExpression = new Expression('uuid_generate_v4()');
6753
break;
6854

69-
case is_callable($generate):
70-
$defaultExpression = new Expression($generate($column));
55+
case is_callable($default):
56+
$defaultExpression = new Expression($default($column));
7157
break;
7258

73-
case $generate === null:
74-
$defaultExpression = $generate;
59+
case $default === null:
60+
$defaultExpression = null;
7561
$defCol->nullable();
7662
break;
77-
case $generate instanceof Expression:
78-
$defaultExpression = $generate;
63+
case $default instanceof Expression:
64+
$defaultExpression = $default;
7965
break;
80-
default:
81-
$defaultExpression = new Expression($generate);
8266
}
8367

8468

@@ -131,10 +115,6 @@ public function geoPoint(string $column): ColumnDefinition
131115

132116
/**
133117
* Create a new PATH type column
134-
*
135-
* @param string $column
136-
*
137-
* @return ColumnDefinition
138118
*/
139119
public function geoPath(string $column): ColumnDefinition
140120
{
@@ -151,10 +131,6 @@ public function xml(string $column): ColumnDefinition
151131

152132
/**
153133
* Create a new uuid[] column
154-
*
155-
* @param string $column
156-
*
157-
* @return ColumnDefinition
158134
*/
159135
public function uuidArray(string $column): ColumnDefinition
160136
{
@@ -179,8 +155,6 @@ public function intArray(string $column): ColumnDefinition
179155
* @param string $type
180156
* @param string $name
181157
* @param array $parameters
182-
*
183-
* @return ColumnDefinition
184158
*/
185159
public function addColumn($type, $name, array $parameters = []): ColumnDefinition
186160
{
@@ -218,13 +192,14 @@ public function ifNotExists(): Fluent
218192
return $this->addCommand('ifNotExists');
219193
}
220194

221-
public function hasIndex($index, bool $unique = false): bool
195+
/**
196+
* @param array|string $index
197+
* @param string|null $type unique|primary
198+
* @return bool
199+
*/
200+
public function hasIndex(array|string $index, ?string $type = null): bool
222201
{
223-
if (is_array($index)) {
224-
$index = $this->createIndexName($unique === false ? 'index' : 'unique', $index);
225-
}
226-
227-
return array_key_exists($index, $this->getSchemaManager()->listTableIndexes($this->getTable()));
202+
return Schema::hasIndex($this->getTable(), $index, $type);
228203
}
229204

230205
/**
@@ -319,11 +294,6 @@ public function dropPartial($index): Fluent
319294
return $this->dropIndexCommand('dropIndex', 'partial', $index);
320295
}
321296

322-
protected function getSchemaManager()
323-
{
324-
return Schema::getConnection()->getDoctrineSchemaManager();
325-
}
326-
327297
private function addExtendedCommand(string $fluent, string $name, array $parameters = []): Fluent
328298
{
329299
$command = new $fluent(array_merge(compact('name'), $parameters));

src/Schema/Postgres/Compilers/PartialCompiler.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ public static function compile(
1818
PartialBuilder $fluent
1919
): string {
2020
$wheres = static::build($grammar, $blueprint, $fluent);
21+
$cols = implode(',', (array)$fluent->get('columns'));
22+
23+
if (count($wheres) === 0) {
24+
return sprintf(
25+
"CREATE INDEX %s ON %s (%s)",
26+
$fluent->get('index'),
27+
$blueprint->getTable(),
28+
$cols,
29+
);
30+
}
2131

22-
$where = count($wheres) === 0 ? '' : ' WHERE %s';
2332
return sprintf(
24-
"CREATE INDEX %s ON %s (%s)$where",
33+
"CREATE INDEX %s ON %s (%s) WHERE %s",
2534
$fluent->get('index'),
2635
$blueprint->getTable(),
27-
implode(',', (array)$fluent->get('columns')),
36+
$cols,
2837
static::removeLeadingBoolean(implode(' ', $wheres))
2938
);
3039
}

src/Schema/Postgres/Connection.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,9 @@
88
use PDO;
99
use Php\Support\Laravel\Database\Query\Builder as QueryBuilder;
1010
use Php\Support\Laravel\Database\Query\Grammars\PostgresGrammar as QueryPostgresGrammar;
11-
use Php\Support\Laravel\Database\Schema\Postgres\Types\DateRangeType;
12-
use Php\Support\Laravel\Database\Schema\Postgres\Types\GeoPathType;
13-
use Php\Support\Laravel\Database\Schema\Postgres\Types\GeoPointType;
14-
use Php\Support\Laravel\Database\Schema\Postgres\Types\IntArrayType;
15-
use Php\Support\Laravel\Database\Schema\Postgres\Types\IpNetworkType;
16-
use Php\Support\Laravel\Database\Schema\Postgres\Types\NumericType;
17-
use Php\Support\Laravel\Database\Schema\Postgres\Types\TsRangeType;
18-
use Php\Support\Laravel\Database\Schema\Postgres\Types\UuidArrayType;
19-
use Php\Support\Laravel\Database\Schema\Postgres\Types\XmlType;
2011

2112
class Connection extends BasePostgresConnection
2213
{
23-
private array $initialTypes = [
24-
DateRangeType::TYPE_NAME => DateRangeType::class,
25-
GeoPathType::TYPE_NAME => GeoPathType::class,
26-
GeoPointType::TYPE_NAME => GeoPointType::class,
27-
IntArrayType::TYPE_NAME => IntArrayType::class,
28-
IpNetworkType::TYPE_NAME => IpNetworkType::class,
29-
NumericType::TYPE_NAME => NumericType::class,
30-
TsRangeType::TYPE_NAME => TsRangeType::class,
31-
UuidArrayType::TYPE_NAME => UuidArrayType::class,
32-
XmlType::TYPE_NAME => XmlType::class,
33-
];
34-
3514
protected function getDefaultSchemaGrammar()
3615
{
3716
return $this->withTablePrefix((new Grammar())->addModifier('Compression'));
@@ -60,13 +39,6 @@ protected function getDefaultQueryGrammar()
6039
return new QueryPostgresGrammar();
6140
}
6241

63-
public function useDefaultPostProcessor(): void
64-
{
65-
parent::useDefaultPostProcessor();
66-
67-
$this->registerInitialTypes();
68-
}
69-
7042
public function bindValues($statement, $bindings): void
7143
{
7244
if ($this->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES)) {
@@ -86,13 +58,6 @@ public function bindValues($statement, $bindings): void
8658
}
8759
}
8860

89-
public function registerInitialTypes(): void
90-
{
91-
foreach ($this->initialTypes as $type => $typeClass) {
92-
$this->registerDoctrineType($typeClass, $type, $typeClass);
93-
}
94-
}
95-
9661
public function updateAndReturn($query, $bindings = []): array
9762
{
9863
return $this->affectingStatementArray($query, $bindings);

src/Schema/Postgres/Grammar/CompressionModifier.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait CompressionModifier
1313
{
1414
public function compileChange(BaseBlueprint $blueprint, Fluent $command, Connection $connection)
1515
{
16-
$queries = parent::compileChange($blueprint, $command, $connection);
16+
$queries = (array)parent::compileChange($blueprint, $command, $connection);
1717

1818
foreach ($blueprint->getChangedColumns() as $changedColumn) {
1919
if ($changedColumn->compression !== null) {
@@ -34,8 +34,10 @@ public function compileChange(BaseBlueprint $blueprint, Fluent $command, Connect
3434
*/
3535
protected function modifyCompression(Blueprint $blueprint, Fluent $column): ?string
3636
{
37-
if ($column->compression !== null) {
38-
return " compression $column->compression";
37+
$compression = $column->value('compression');
38+
39+
if ($compression !== null) {
40+
return " compression $compression";
3941
}
4042

4143
return null;

src/Schema/Postgres/Grammar/GrammarTable.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ public function compileCreate(Blueprint $blueprint, Fluent $command): string
2727

2828
/**
2929
* Compile a drop table (if exists) command.
30-
*
31-
* @param Blueprint $blueprint
32-
* @param Fluent $command
33-
*
34-
* @return string
3530
*/
36-
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
31+
public function compileDropIfExists(Blueprint $blueprint, Fluent $command): string
3732
{
3833
$baseCompile = parent::compileDropIfExists($blueprint, $command);
3934
$cascade = $command->get('cascade') ? ' cascade' : '';
35+
4036
return "$baseCompile$cascade";
4137
}
4238
}

0 commit comments

Comments
 (0)