crovitche / swiss-geo-bundle
使用 Doctrine ORM 在您的 MySQL 数据库中本地导入瑞士建筑地址、街道和地区
1.0-alpha
2022-11-09 15:03 UTC
Requires
- php: ^8.1
- doctrine/doctrine-bundle: ^2.1
- doctrine/orm: ^2.13
- guzzlehttp/guzzle: ^7.5
- http-interop/http-factory-guzzle: ^1.0
- league/csv: ^9.7
- meilisearch/meilisearch-php: ^0.24.2
- symfony/cache: 6.1.*
- symfony/config: 6.1.*
- symfony/console: 6.1.*
- symfony/dependency-injection: 6.1.*
- symfony/filesystem: 6.1.*
- symfony/finder: 6.1.*
- symfony/form: 6.1.*
- symfony/http-client: 6.1.*
- symfony/http-foundation: 6.1.*
- symfony/lock: 6.1.*
- symfony/monolog-bundle: ^3.1
- symfony/options-resolver: 6.1.*
Requires (Dev)
Suggests
- ext-curl: *
This package is auto-updated.
Last update: 2024-09-13 06:58:16 UTC
README
SwissGeoBundle 提供了一种干净的方式来使用瑞士建筑地址。如果您有以下用例,这个包可能对您很有用
- 一个自动完成的地址输入,没有错误的地址条目
- 本地存储地址(离线 !)
- "我想在离线地图上定位我的客户。"
- 根据地址创建统计信息
- "我在哪个地区有大多数客户?"
- 避免使用 Google Map 服务,从而节省资金
- 避免使用不再有效的邮政地址。
- "这位客户怎么住在这里?这栋楼已经被摧毁了!"
- 获取有关地址的一些信息
- "这栋楼部分是住宅吗?"
- "这个地址在街上还是地方上?"
- "这个地址已经建成或计划中吗?"
- ...
技术要求
SwissGeoBundle 需要
- MySQL 8.0 或更高版本(其他 RDBMS 将很快推出...)并启用以下选项
- PHP 8.1 或更高
composer.json
中指定的 Symfony 组件- Doctrine ORM 实体(不支持 Doctrine ODM)
- Meilisearch v1.5 - 必要的,用于完整地址搜索(否则性能太低)
version: '3.7' services: meilisearch: hostname: meilisearch image: getmeili/meilisearch:v1.5 environment: - MEILI_ENV=development # set the max payload to 200Mb instead of 100 default one # addresses file is around 170Mb - MEILI_HTTP_PAYLOAD_SIZE_LIMIT=209715200 - MEILI_NO_ANALYTICS=true ports: - '7701:7700' networks: - network volumes: - meilisearch-data:/data.ms restart: unless-stopped
安装
确保已全局安装 Composer,如 Composer 文档中的安装章节所述。
使用 Symfony Flex 的应用程序
打开命令行,进入您的项目目录,然后执行
composer require crovitche/swiss-geo-bundle
然后确保在 config/bundles.php
中的已注册包中启用了此包,如果您的应用程序不使用 Symfony Flex。
入门
运行以下命令,如果希望定期更新数据,请将它们放入 cron 中。
1. 配置您的实体
<?php declare(strict_types=1); namespace App\Entity; use Crovitche\SwissGeoBundle\Entity\BuildingAddress; use Doctrine\ORM\Mapping as ORM; //... #[ORM\Entity(CustomerRepository::class), ORM\Table("Customer")] #[ORM\Index(["egaid"], name: "IX___Customer___building_address")] class Customer { //... #[ORM\ManyToOne(BuildingAddress::class)] #[ORM\JoinColumn("egaid", "egaid", false, true, "SET NULL")] private ?BuildingAddress $postalAddress = null; }
2. 创建数据库迁移。
为此,您必须使用 DoctrineMigrationBundle。
使用 Maker 包 生成迁移。
php bin/console make:migration
此命令将自动在迁移 php 文件中生成 SQL。
检查创建的迁移,如果不存在则添加以下代码
public function up(Schema $schema): void { // ... $this->addSql(/** @lang MySQL */' ALTER TABLE Building_address ADD CONSTRAINT CK___Building_address___building_name__xor__address_number CHECK ((building_name IS NOT NULL XOR address_number IS NOT NULL) OR (building_name IS NULL AND address_number IS NULL)); '); // ... } public function down(Schema $schema): void { // ... $this->addSql(/** @lang MySQL */' ALTER TABLE Building_address DROP CONSTRAINT CK___Building_address___building_name__xor__address_number; '); // ... } public function isTransactional(): bool { return false; }
3. 执行迁移
php bin/console doctrine:migrations:migrate -n
4. 导入数据
注意:您也可以在 cron job 中运行以下命令,以便定期更新您的数据。
4.1 地区
php bin/console swiss-geo-bundle:import:localities --no-debug
4.2 街道
php bin/console swiss-geo-bundle:import:streets --no-debug
4.3 建筑地址
php bin/console swiss-geo-bundle:import:building-addresses --no-debug
4.4 在 Meilisearch 中生成/更新文档
php bin/console swiss-geo-bundle:import:meilisearch:documents:generate --no-debug