Skip to content

Commit 6d16c51

Browse files
committed
v2: laravel 10 init
1 parent 0034ff3 commit 6d16c51

File tree

12 files changed

+70
-66
lines changed

12 files changed

+70
-66
lines changed

.github/workflows/pest.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
php: [ 8.2, 8.1 ]
15-
laravel: [ 9.*, 8.* ]
15+
laravel: [ 10.* ]
1616
db: [ 'mysql:8.0', 'mysql:5.7', 'mariadb:10.9' ]
1717
dependency-version: [ prefer-stable ]
1818
include:
19-
- laravel: 9.*
20-
testbench: ^7.0
21-
- laravel: 8.*
22-
testbench: ^6.23
19+
- laravel: 10.*
20+
testbench: ^8.0
2321

2422
services:
2523
db:

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-spatial` will be documented in this file.
44

5+
## v2.0.0 - 2023-06-02
6+
7+
Initial release for laravel 10
8+
59
## v1.0.0 - 2023-06-02
610

7-
Initial release
11+
Initial release for laravel 8,9

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
**This Laravel package allows you to easily work with spatial data types and functions.**
1212

13-
v1 supports Laravel 8,9 and PHP 8.1+.
13+
* v2 supports Laravel 10+ and PHP 8.1+
14+
* v1 supports Laravel 8,9 and PHP 8.1+
1415

1516
This package supports MySQL v8 or v5.7, and MariaDB v10.
1617

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
"php": "^8.1",
1414
"ext-json": "*",
1515
"ext-pdo": "*",
16-
"laravel/framework": "^8.0",
16+
"laravel/framework": "^10.0",
1717
"phayes/geophp": "^1.2"
1818
},
1919
"require-dev": {
2020
"doctrine/dbal": "^3.0",
2121
"laravel/pint": "^1.5",
2222
"nunomaduro/larastan": "^1.0|^2.4",
23-
"orchestra/testbench": "^6.23|^7.0",
24-
"pestphp/pest": "^1.0",
25-
"pestphp/pest-plugin-laravel": "^1.4.0"
23+
"orchestra/testbench": "^8.0",
24+
"pestphp/pest": "^1.0|^2.6",
25+
"pestphp/pest-plugin-laravel": "^1.0|^2.0"
2626
},
2727
"autoload": {
2828
"psr-4": {

phpstan.neon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,3 @@ parameters:
99
level: max
1010
checkMissingIterableValueType: true
1111
checkGenericClassInNonGenericObjectType: false
12-
ignoreErrors:
13-
-
14-
message: '#^Call to an undefined method Pest\\Expectation\|Pest\\Support\\Extendable\:\:.+\(\)\.$#'
15-
path: tests/*.php
16-
-
17-
message: '#^Access to an undefined property Pest\\Expectation\|Pest\\Support\\Extendable\:\:\$.+\.$#'
18-
path: tests/*.php

phpunit.xml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@
55
colors="true"
66
processIsolation="false"
77
stopOnFailure="false"
8-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.0/phpunit.xsd"
8+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
99
>
10-
<testsuites>
11-
<testsuite name="Test Suite">
12-
<directory>tests</directory>
13-
</testsuite>
14-
</testsuites>
15-
<coverage>
16-
<include>
17-
<directory suffix=".php">./src</directory>
18-
</include>
19-
<report>
20-
<html outputDirectory="build/coverage"/>
21-
<text outputFile="build/coverage.txt"/>
22-
<clover outputFile="build/logs/clover.xml"/>
23-
</report>
24-
</coverage>
25-
<logging>
26-
<junit outputFile="build/report.junit.xml"/>
27-
</logging>
28-
<php>
29-
<env name="DB_DATABASE" value="laravel"/>
30-
<env name="DB_HOST" value="127.0.0.1"/>
31-
<env name="DB_USERNAME" value="root"/>
32-
</php>
10+
<testsuites>
11+
<testsuite name="Test Suite">
12+
<directory>tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<coverage>
16+
<report>
17+
<html outputDirectory="build/coverage"/>
18+
<text outputFile="build/coverage.txt"/>
19+
<clover outputFile="build/logs/clover.xml"/>
20+
</report>
21+
</coverage>
22+
<logging>
23+
<junit outputFile="build/report.junit.xml"/>
24+
</logging>
25+
<php>
26+
<env name="DB_DATABASE" value="laravel"/>
27+
<env name="DB_HOST" value="127.0.0.1"/>
28+
<env name="DB_USERNAME" value="root"/>
29+
</php>
30+
<source>
31+
<include>
32+
<directory suffix=".php">./src</directory>
33+
</include>
34+
</source>
3335
</phpunit>

src/Eloquent/GeometryCast.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use ASanikovich\LaravelSpatial\Exceptions\LaravelSpatialException;
88
use ASanikovich\LaravelSpatial\Geometry\Geometry;
99
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
10-
use Illuminate\Database\Query\Expression;
10+
use Illuminate\Contracts\Database\Query\Expression;
11+
use Illuminate\Database\Connection;
12+
use Illuminate\Database\Eloquent\Model;
1113

1214
class GeometryCast implements CastsAttributes
1315
{
@@ -26,15 +28,15 @@ public function __construct(string $className)
2628
* @param string|Expression|null $value
2729
* @param array<string, mixed> $attributes
2830
*/
29-
public function get($model, string $key, mixed $value, array $attributes): ?Geometry
31+
public function get(Model $model, string $key, mixed $value, array $attributes): ?Geometry
3032
{
3133
if (! $value) {
3234
return null;
3335
}
3436

3537
if ($value instanceof Expression) {
36-
$wkt = $this->extractWktFromExpression($value);
37-
$srid = $this->extractSridFromExpression($value);
38+
$wkt = $this->extractWktFromExpression($value, $model->getConnection());
39+
$srid = $this->extractSridFromExpression($value, $model->getConnection());
3840

3941
return $this->className::fromWkt($wkt, $srid);
4042
}
@@ -48,7 +50,7 @@ public function get($model, string $key, mixed $value, array $attributes): ?Geom
4850
*
4951
* @throws LaravelSpatialException
5052
*/
51-
public function set($model, string $key, mixed $value, array $attributes): Expression|null
53+
public function set(Model $model, string $key, mixed $value, array $attributes): Expression|null
5254
{
5355
if (! $value) {
5456
return null;
@@ -64,24 +66,27 @@ public function set($model, string $key, mixed $value, array $attributes): Expre
6466

6567
if (! ($value instanceof $this->className)) {
6668
$geometryType = is_object($value) ? $value::class : gettype($value);
67-
throw new LaravelSpatialException(
68-
sprintf('Expected %s, %s given.', static::class, $geometryType) // todo
69-
);
69+
70+
throw new LaravelSpatialException(sprintf('Expected %s, %s given.', static::class, $geometryType));
7071
}
7172

7273
return $value->toSqlExpression($model->getConnection());
7374
}
7475

75-
private function extractWktFromExpression(Expression $expression): string
76+
private function extractWktFromExpression(Expression $expression, Connection $connection): string
7677
{
77-
preg_match('/ST_GeomFromText\(\'(.+)\', .+(, .+)?\)/', (string) $expression, $match);
78+
$expressionValue = $expression->getValue($connection->getQueryGrammar());
79+
80+
preg_match('/ST_GeomFromText\(\'(.+)\', .+(, .+)?\)/', (string) $expressionValue, $match);
7881

7982
return $match[1];
8083
}
8184

82-
private function extractSridFromExpression(Expression $expression): int
85+
private function extractSridFromExpression(Expression $expression, Connection $connection): int
8386
{
84-
preg_match('/ST_GeomFromText\(\'.+\', (.+)(, .+)?\)/', (string) $expression, $match);
87+
$expressionValue = $expression->getValue($connection->getQueryGrammar());
88+
89+
preg_match('/ST_GeomFromText\(\'.+\', (.+)(, .+)?\)/', (string) $expressionValue, $match);
8590

8691
return (int) $match[1];
8792
}

src/Eloquent/HasSpatial.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,6 @@ protected function toSpatialExpressionString(Builder $query, Expression|Geometry
329329
$expression = $query->raw($grammar->wrap($value));
330330
}
331331

332-
return (string) $expression;
332+
return (string) $expression->getValue($grammar);
333333
}
334334
}

src/Geometry/Geometry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use geoPHP;
1212
use Illuminate\Contracts\Database\Eloquent\Castable;
1313
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
14+
use Illuminate\Contracts\Database\Query\Expression;
1415
use Illuminate\Contracts\Support\Arrayable;
1516
use Illuminate\Contracts\Support\Jsonable;
1617
use Illuminate\Database\ConnectionInterface;
17-
use Illuminate\Database\Query\Expression;
1818
use Illuminate\Support\Facades\DB;
1919
use Illuminate\Support\Traits\Macroable;
2020
use JsonException;

tests/Eloquent/HasSpatialTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
TestPlace::factory()->create(['point' => new Point(0, 0, Srid::WGS84->value)]);
1414

1515
/** @var TestPlace $testPlaceWithDistance */
16-
$testPlaceWithDistance = TestPlace::query()->select(['id'])->selectRaw(DB::raw('id as id_new'))
16+
$testPlaceWithDistance = TestPlace::query()->select(['id'])->selectRaw('id as id_new')
1717
->withDistance('point', new Point(1, 1, Srid::WGS84->value))
1818
->firstOrFail();
1919

@@ -397,8 +397,9 @@
397397

398398
$result = $method->invoke($model, $model->newQuery(), $polygon);
399399

400+
$grammar = $model->newQuery()->getGrammar();
400401
$connection = $model->newQuery()->getConnection();
401-
$sqlSerializedPolygon = $polygon->toSqlExpression($connection)->getValue();
402+
$sqlSerializedPolygon = $polygon->toSqlExpression($connection)->getValue($grammar);
402403
expect($result)->toBe($sqlSerializedPolygon);
403404
});
404405

0 commit comments

Comments
 (0)