yucadoo / laravel-geojson-rule
GeoJSON 的 Laravel 验证规则。
2.0.5
2024-03-04 09:25 UTC
Requires
- php: >=7.2
- illuminate/contracts: ^5.5|^6.0|^7.0|^8.0|^9.0|^10|^11.0
- jmikola/geojson: ^1.0
Requires (Dev)
- phpunit/phpunit: >=8.0
- squizlabs/php_codesniffer: ^3.5.7
README
GeoJSON 的 Laravel 验证规则。基于 GeoJSON PHP 库 构建。此包符合 PSR-1、PSR-2 和 PSR-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
贡献
有关详细信息,请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT。
安全
如果您发现任何安全相关的问题,请通过电子邮件 hrcajuka@gmail.com 而不是使用问题跟踪器。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。