yucadoo/laravel-geojson-rule

GeoJSON 的 Laravel 验证规则。

2.0.5 2024-03-04 09:25 UTC

This package is auto-updated.

Last update: 2024-09-04 10:41:00 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

GeoJSON 的 Laravel 验证规则。基于 GeoJSON PHP 库 构建。此包符合 PSR-1PSR-2PSR-4 标准。如果您注意到任何不符合标准的地方,请通过 pull request 提交补丁。

安装

通过 Composer

$ composer require yucadoo/laravel-geojson-rule

使用方法

创建一个新的不带参数的 GeoJsonRule 实例以接受任何 GeoJSON 几何形状。

use Illuminate\Support\Facades\Validator;
use YucaDoo\LaravelGeoJsonRule\GeoJsonRule;

$validator = Validator::make(
    ['geometry' => '{"type": "Point", "coordinates":[1, 2]}'],
    ['geometry' => new GeoJsonRule()] // Accept any geometry
);
$validator->passes(); // true

$validator = Validator::make(
    ['geometry' => '{"type": "Point", "coordinates":[1]}'],
    ['geometry' => new GeoJsonRule()] // Accept any geometry
);
$validator->passes(); // false
$messages = $validator->messages()->get('geometry');
$messages[0]; // The geometry does not satisfy the RFC 7946 GeoJSON Format specification because Position requires at least two elements

传递 GeoJson 几何形状类以限制它。

use GeoJson\Geometry\Point;
use Illuminate\Support\Facades\Validator;
use YucaDoo\LaravelGeoJsonRule\GeoJsonRule;

$validator = Validator::make(
    ['position' => '{"type": "Point", "coordinates":[1, 2]}'],
    ['position' => new GeoJsonRule(Point::class)] // Accept Points only
);
$validator->passes(); // true

$validator = Validator::make(
    ['position' => '{"type": "LineString", "coordinates":[[1, 2], [3, 4]]}'],
    ['position' => new GeoJsonRule(Point::class)] // Accept Points only
);
$validator->passes(); // false
$messages = $validator->messages()->get('position');
echo $messages[0]; // The position does not satisfy the RFC 7946 GeoJSON Format specification for Point.

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ composer test

贡献

有关详细信息,请参阅 CONTRIBUTINGCODE_OF_CONDUCT

安全

如果您发现任何安全相关的问题,请通过电子邮件 hrcajuka@gmail.com 而不是使用问题跟踪器。

致谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件