arberd/geonames 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arberd/geonames

Composer 安装命令:

composer require arberd/geonames

包简介

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

README 文档

README

Build Status Coverage Status

Based on ipalaus/geonames

A collection of Eloquent models and Commands to get all the power of GeoNames in Laravel.

Installation

Add arberd/geonames as a requirement to composer.json:

{
    "require": {
        "arberd/geonames": "dev-master"
    }
}

Note: if you're using Laravel 5.1 you can use the version "arberd/geonames": "2.0.*".

Update your packages with composer update or install with composer install.

Once you have installed the dependency, you need to register geonames in Laravel. Open your app/config/app.php and add the next provider to your providers array:

'Arberd\Geonames\GeonamesServiceProvider'

If you run now php artisan you should see a new namespace geonames with a few commands related to the package. In order to proceed with the install, run the next command:

$ php artisan vendor:publish --provider="Arberd\Geonames\GeonamesServiceProvider"

This will publish the config file to config/geonames.php and the migrations to your database/migrations directory. To be able to control what's going on, we recommend you to manually trigger php artisan migrate.

Artisan Commands

Import

The import command downloads the needed files (configurable in the config file) and run a seeder for each of them. A few options are provided:

  • --country=XX: downloads the specific country (ie. US, ES, FR...)
  • --development: downloads a smaller names file (~10MB) very useful for development environments.
  • --fetch-only: only fetch the files but won't run the seeder. If you want to download the files and then be able to regenerate the tables while offline.
  • --wipe-files: forces a delete of the old files.
$ php artisan geonames:import [--country="..."] [--development] [--fetch-only] [--wipe-files]

Importing a production database can take a while. Main file is ~1GB and the seeder has to insert ~6M rows while creating indexes for some fields. In development environments, I highly recommend to use the --development option and keep complete imports to production. The final table sizes can also affect your local MySQL instance.

Install

Publish the package's config and run the needed migrations. You can force the config publishing with the --force option.

$ php artisan geonames:install [-f|--force]

Seed

The is called by the geonames:import command. It extends the Laravel's db:seed but add to extra options: path and country. This is due to the size of the files to import and the queries that we have to run, geonames:import creates a new Symfony\Component\Process\Process for each seeder.

You shouldn't need to call this command directly.

Truncate

Do you want to truncate the table and start from scratch? Run:

$ php artisan geonames:truncate

Eloquent Models

Continent

  • Relationships:
  • hasMany countries

Country

  • Relationships:
  • belongsTo continent
  • hasMany names

Name

  • Relationships:
  • belongsTo country, eager loaded on every request

... and more to come up!

Integrating to a current Eloquent model

Integrating arberd/geonames with your existing Eloquent models as easy as:

<?php

class User extends Eloquent {

	public function geoname()
	{
		return $this->belongsTo('Arberd\Geonames\Eloquent\Name');
	}

}

Now you can a geoname_id to your User model and getting the results with a simple:

$user = User::with('geoname')->find(1);
echo $user->geoname->name;

The belongsTo country relationship in the Name model is always eager loaded. That means that you can get the country name with the same code as above. You just have to echo:

echo $user->geoname->country->name;

You can go a step further and eager loaded the geoname.country.continent relationship (or whatever existing relation in Geoname models):

$user = User::with('geoname.country.continent')->find(1);
echo $user->geoname->country->continent->name;

GeoNames

Tables reference

I think the original table names are ugly and they can conflict with other tables in a current project. I switched to a less uglier ones. You can check the migration files to see the used names for our database schema.

Original Eloquent Geonames
geoname geonames_names
alternatename geonames_alternate_names
countryinfo geonames_countries
iso_languagecodes geonames_language_codes
admin1CodesAscii geonames_admin_divisions
admin2Codes geonames_admin_subdivisions
hierarchy geonames_hierarchy
featureCodes geonames_features
timeZones geonames_timezones
continentCodes geonames_continents

arberd/geonames 适用场景与选型建议

arberd/geonames 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.08k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「location」 「eloquent」 「geonames」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 arberd/geonames 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arberd/geonames 我们能提供哪些服务?
定制开发 / 二次开发

基于 arberd/geonames 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 33
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-10