geocoder-php / geocoder-php/Geocoder
How do I change the OpenRouteService::API_URL for "On-Premise" install of software
未关闭
还没有人认领这个 Issue。
improvement
provider
- 主要语言
- PHP
- 星标
- 4k
- 派生
- 525
- 平均合并
- 8 分钟
- 30 天内合并 PR
- 1
描述
I noticed the OpenRouteService::API_URL is being hard-coded into file Geocoder\Provider\OpenRouteService (vendor\geocoder-php\openrouteservice-provide\OpenRouteService.php)
Could someone please push the following code into the next version of OpenRouteService (updating Pelias would do the trick)
vendor\geocoder-php\pelias-provider\Pelias.php
/**
* @param HttpClient $client an HTTP adapter
* @param string $root url of Pelias API
* @param int $version version of Pelias API
*/
public function __construct(HttpClient $client, string $root, int $version = 1)
{
$this->_setPeliasApiRoot($root, $version);
parent::__construct($client);
}
/**
* Set the API root and version, see "_setPeliasApiRoot"
* @param string $root url of Pelias API
* @param int $version version of Pelias API
*/
public function set_Pelias_ApiRoot(string $root, int $version = 1)
{
return $this->_setPeliasApiRoot($root, $version);
}
/**
* Set the API root and version
* @param string $root url of Pelias API
* @param int $version version of Pelias API
*/
protected function _setPeliasApiRoot(string $root, int $version = 1)
{
$this->root = sprintf('%s/v%d', rtrim($root, '/'), $version);
$this->version = $version;
}
vendor\geocoder-php\openrouteservice-provider
const API_URL = 'https://api.openrouteservice.org/geocode';
const API_VERSION = 1;
/**
* @var string
*/
private $apiKey;
/**
* @param HttpClient $client an HTTP adapter
* @param string $apiKey an API key
*/
public function __construct(HttpClient $client, string $apiKey)
{
if (empty($apiKey)) {
throw new InvalidCredentials('No API key provided.');
}
$this->apiKey = $apiKey;
parent::__construct($client, self::API_URL, self::API_VERSION);
$this->_set_ORS_API_Root(self::API_URL, self::API_VERSION, TRUE);
}
/**
* Set the Openrouteservice URL
* @param string $root
* @param integer $version
* @param boolean $check_version
* @return void
*/
public function set_ORS_API_Root(string $root, $version, $check_version = false)
{
return $this->_set_ORS_API_Root($root, $version, $check_version);
}
/**
* Set the Openrouteservice URL
* @param string $root
* @param integer $version
* @param boolean $check_version
* @return void
*/
protected function _set_ORS_API_Root(string $root, $version, $check_version = false)
{
parent::_setPeliasApiRoot($root, $version);
if (filter_var($check_version, FILTER_VALIDATE_BOOLEAN)) {
$this->_check_ORS_API_Root_Version($root, $root, $version);
}
}
/**
* Openrouteservice does not use /v1 in first version, but plan to add
* /v2 in next version.
*
* @see https://ask.openrouteservice.org/t/pelias-version-in-api-url/1021
* @param string $root
* @param string $new_root
* @param string $version
* @return void
*/
protected function _check_ORS_API_Root_Version(string &$root, string $new_root, $version)
{
$version_ok = true;
$version_ok = ($version_ok && is_numeric($version));
$version_ok = ($version_ok && ($version === self::API_VERSION));
$version_ok = ($version_ok && is_string($new_root));
$version_ok = ($version_ok && !empty($new_root));
$version_ok = (bool) $version_ok;
if ($version_ok) {
$root = $new_root;
}
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 OpenRouteService provider 及其硬编码的 API_URL 开始,然后将其构造函数与 issue 中描述的 Pelias.php 入口点进行比较。确定在保留现有版本处理方式的同时,如何提供 on-premise API 根地址。完成标准是 OpenRouteService 可以指向 on-premise URL,而不再只能使用托管端点。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- api
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100