Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Php\Support\Laravel\Caster; | ||
|
||
use Php\Support\Types\GeoPoint as BaseGeoPoint; | ||
|
||
/** | ||
* Class GeoPoint | ||
* @package Php\Support\Laravel\Caster | ||
* | ||
* GeoPoint for PG | ||
*/ | ||
class GeoPoint extends BaseGeoPoint implements Caster | ||
{ | ||
public static function castToDatabase($value): ?string | ||
{ | ||
if (!$value) { | ||
return null; | ||
} | ||
|
||
if ($value instanceof static) { | ||
return $value->toPgDB(); | ||
} | ||
|
||
throw new \RuntimeException('Invalid type of $value: ' . gettype($value)); | ||
} | ||
|
||
public static function isEquivalent($value, $original): bool | ||
{ | ||
return $value->toJson() === $original?->toJson(); | ||
} | ||
|
||
public function value(): ?string | ||
{ | ||
return static::castToDatabase($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters