Skip to content

Commit 4c9e103

Browse files
MatanYadaevlaravel-shiftMatan Yadaev
authored
Laravel 10 support (#78)
* Bump dependencies for Laravel 10 * Update GitHub Actions for Laravel 10 * Format composer.json * Fix for Laravel 10 * Drop support for Laravel 8 and php 8.0 * fixes * fixes * Fix test * Support Laravel 9 * Support Laravel 10 only * Use getters --------- Co-authored-by: Shift <[email protected]> Co-authored-by: Matan Yadaev <[email protected]>
1 parent 5c7a8b6 commit 4c9e103

File tree

9 files changed

+140
-93
lines changed

9 files changed

+140
-93
lines changed

.github/workflows/pest.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ 8.2, 8.1, 8.0 ]
15-
laravel: [ 9.*, 8.* ]
14+
php: [ 8.2, 8.1 ]
15+
laravel: [ 10.* ]
1616
db: [ 'mysql:8.0', 'mysql:5.7', 'mariadb:10.9' ]
17-
# dependency-version: [prefer-lowest, prefer-stable]
18-
dependency-version: [ prefer-stable ]
17+
dependency-version: [ prefer-lowest, prefer-stable ]
1918
include:
20-
- laravel: 8.*
21-
testbench: ^6.23
22-
- laravel: 9.*
23-
testbench: 7.*
19+
- laravel: 10.*
20+
testbench: ^8.0
2421

2522
services:
2623
db:

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ 8.2, 8.1, 8.0 ]
14+
php: [ 8.2, 8.1 ]
1515

1616
steps:
1717
- name: Checkout code

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
Laravel package to work with spatial data types and functions.
1010

11+
The latest version (v3) supports Laravel 10 and PHP 8.1+. For Laravel 8 or 9, and PHP 8.0, use v2.
12+
1113
This package supports MySQL v8, MySQL v5.7, and MariaDB v10.
1214

1315
## Installation

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^8.0",
13+
"php": "^8.1",
1414
"ext-json": "*",
1515
"ext-pdo": "*",
16-
"laravel/framework": "^8.0|^9.0",
16+
"laravel/framework": "^10.0",
1717
"phayes/geophp": "^1.2"
1818
},
1919
"require-dev": {
20-
"doctrine/dbal": "^3.4",
21-
"friendsofphp/php-cs-fixer": "^3.0",
22-
"jubeki/laravel-code-style": "^1.0",
23-
"nunomaduro/larastan": "^1.0|^2.0",
24-
"orchestra/testbench": "^6.23|^7.0",
25-
"pestphp/pest": "^1.21",
26-
"pestphp/pest-plugin-laravel": "^1.2"
20+
"doctrine/dbal": "^3.5.3",
21+
"friendsofphp/php-cs-fixer": "^3.14.3",
22+
"jubeki/laravel-code-style": "^1.2",
23+
"nunomaduro/larastan": "^1.0|^2.4",
24+
"orchestra/testbench": "^8.0",
25+
"pestphp/pest": "^1.22.4",
26+
"pestphp/pest-plugin-laravel": "^1.4"
2727
},
2828
"autoload": {
2929
"psr-4": {

phpstan.neon

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
includes:
2-
- ./vendor/nunomaduro/larastan/extension.neon
2+
- ./vendor/nunomaduro/larastan/extension.neon
33
parameters:
4-
paths:
5-
- src
6-
- tests
7-
level: max
8-
ignoreErrors:
9-
-
10-
message: '#^Call to an undefined method Pest\\Expectation\|Pest\\Support\\Extendable\:\:.+\(\)\.$#'
11-
path: tests/*.php
12-
-
13-
message: '#^Access to an undefined property Pest\\Expectation\|Pest\\Support\\Extendable\:\:\$.+\.$#'
14-
path: tests/*.php
15-
-
16-
message: '#^Call to an undefined method Pest\\Expectation\:\:.+\(\)\.$#'
17-
path: tests/*.php
18-
excludePaths:
19-
- ./src/Factory.php
20-
checkMissingIterableValueType: true
21-
checkGenericClassInNonGenericObjectType: false
4+
paths:
5+
- src
6+
- tests
7+
excludePaths:
8+
- src/Factory.php
9+
level: max
10+
ignoreErrors:
11+
-
12+
message: '#^Call to an undefined method Pest\\Expectation\|Pest\\Support\\Extendable\:\:.+\(\)\.$#'
13+
path: tests/*.php
14+
-
15+
message: '#^Access to an undefined property Pest\\Expectation\|Pest\\Support\\Extendable\:\:\$.+\.$#'
16+
path: tests/*.php
17+
-
18+
message: '#^Call to an undefined method Pest\\Expectation\:\:.+\(\)\.$#'
19+
path: tests/*.php
20+
checkMissingIterableValueType: true
21+
checkGenericClassInNonGenericObjectType: false

src/GeometryCast.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
namespace MatanYadaev\EloquentSpatial;
66

77
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
8+
use Illuminate\Contracts\Database\Query\Expression as ExpressionContract;
9+
use Illuminate\Database\Connection;
810
use Illuminate\Database\Eloquent\Model;
9-
use Illuminate\Database\Query\Expression;
1011
use InvalidArgumentException;
1112
use MatanYadaev\EloquentSpatial\Objects\Geometry;
1213

@@ -26,7 +27,7 @@ public function __construct(string $className)
2627
/**
2728
* @param Model $model
2829
* @param string $key
29-
* @param string|Expression|null $value
30+
* @param string|ExpressionContract|null $value
3031
* @param array<string, mixed> $attributes
3132
* @return Geometry|null
3233
*/
@@ -36,9 +37,9 @@ public function get($model, string $key, $value, array $attributes): ?Geometry
3637
return null;
3738
}
3839

39-
if ($value instanceof Expression) {
40-
$wkt = $this->extractWktFromExpression($value);
41-
$srid = $this->extractSridFromExpression($value);
40+
if ($value instanceof ExpressionContract) {
41+
$wkt = $this->extractWktFromExpression($value, $model->getConnection());
42+
$srid = $this->extractSridFromExpression($value, $model->getConnection());
4243

4344
return $this->className::fromWkt($wkt, $srid);
4445
}
@@ -51,18 +52,18 @@ public function get($model, string $key, $value, array $attributes): ?Geometry
5152
* @param string $key
5253
* @param Geometry|mixed|null $value
5354
* @param array<string, mixed> $attributes
54-
* @return Expression|null
55+
* @return ExpressionContract|null
5556
*
5657
* @throws InvalidArgumentException
5758
*/
58-
public function set($model, string $key, $value, array $attributes): Expression|null
59+
public function set($model, string $key, $value, array $attributes): ExpressionContract|null
5960
{
6061
if (! $value) {
6162
return null;
6263
}
6364

6465
if (is_array($value)) {
65-
$value = Geometry::fromArray($value);
66+
$value = Geometry::fromArray($value);
6667
}
6768

6869
if (! ($value instanceof $this->className)) {
@@ -75,16 +76,22 @@ public function set($model, string $key, $value, array $attributes): Expression|
7576
return $value->toSqlExpression($model->getConnection());
7677
}
7778

78-
private function extractWktFromExpression(Expression $expression): string
79+
private function extractWktFromExpression(ExpressionContract $expression, Connection $connection): string
7980
{
80-
preg_match('/ST_GeomFromText\(\'(.+)\', .+(, .+)?\)/', (string) $expression, $match);
81+
$grammar = $connection->getQueryGrammar();
82+
$expressionValue = $expression->getValue($grammar);
83+
84+
preg_match('/ST_GeomFromText\(\'(.+)\', .+(, .+)?\)/', (string) $expressionValue, $match);
8185

8286
return $match[1];
8387
}
8488

85-
private function extractSridFromExpression(Expression $expression): int
89+
private function extractSridFromExpression(ExpressionContract $expression, Connection $connection): int
8690
{
87-
preg_match('/ST_GeomFromText\(\'.+\', (.+)(, .+)?\)/', (string) $expression, $match);
91+
$grammar = $connection->getQueryGrammar();
92+
$expressionValue = $expression->getValue($grammar);
93+
94+
preg_match('/ST_GeomFromText\(\'.+\', (.+)(, .+)?\)/', (string) $expressionValue, $match);
8895

8996
return (int) $match[1];
9097
}

src/Objects/Geometry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use geoPHP;
88
use Illuminate\Contracts\Database\Eloquent\Castable;
99
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
10+
use Illuminate\Contracts\Database\Query\Expression as ExpressionContract;
1011
use Illuminate\Contracts\Support\Arrayable;
1112
use Illuminate\Contracts\Support\Jsonable;
1213
use Illuminate\Database\ConnectionInterface;
13-
use Illuminate\Database\Query\Expression;
1414
use Illuminate\Support\Facades\DB;
1515
use Illuminate\Support\Traits\Macroable;
1616
use InvalidArgumentException;
@@ -210,9 +210,9 @@ public static function castUsing(array $arguments): CastsAttributes
210210

211211
/**
212212
* @param ConnectionInterface $connection
213-
* @return Expression
213+
* @return ExpressionContract
214214
*/
215-
public function toSqlExpression(ConnectionInterface $connection): Expression
215+
public function toSqlExpression(ConnectionInterface $connection): ExpressionContract
216216
{
217217
$wkt = $this->toWkt();
218218

0 commit comments

Comments
 (0)