PHPackages                             zonuexe/kenall - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. zonuexe/kenall

ActiveLibrary[API Development](/categories/api)

zonuexe/kenall
==============

Unofficially kenall.jp client

v0.1.0(5y ago)97[1 issues](https://github.com/zonuexe/kenall.php/issues)Apache-2.0PHPPHP &gt;=7.1.0

Since Feb 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/zonuexe/kenall.php)[ Packagist](https://packagist.org/packages/zonuexe/kenall)[ RSS](/packages/zonuexe-kenall/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (6)Versions (5)Used By (0)

Kenall.php - ケンオール非公式APIクライアント
==============================

[](#kenallphp---ケンオール非公式apiクライアント)

[![Packagist Version](https://camo.githubusercontent.com/9fe196a2bad41ab956c34eca3b272d0bd4d7313b63cfedc2f58a455d50543936/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6f6e756578652f6b656e616c6c3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zonuexe/kenall)[![Packagist PHP Version Support](https://camo.githubusercontent.com/8da901279cf5bf0b80d605df350a1bbf0f62a135578a261cc13d1ed1579afab2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a6f6e756578652f6b656e616c6c3f7374796c653d666c61742d737175617265)](https://www.php.net/supported-versions.php)[![Packagist License](https://camo.githubusercontent.com/d93e28a6fa80bc07ac095334d633445b768a702481b6d2b4ec3295b3a97b6a11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a6f6e756578652f6b656e616c6c3f7374796c653d666c61742d737175617265)](https://www.apache.org/licenses/LICENSE-2.0)

PHP向けの[ケンオール 📮 郵便番号・住所検索API](https://kenall.jp/)の非公式クライアントです。このパッケージは個人によって開発されており、[Open Collector, Inc.](https://opencollector.co.jp/)が提供するものではありません。

このパッケージは開発の初期段階であり、現状有姿・無保証として提供されます。通常の用途で利用するための基本的な機能は実装していますが、エラーハンドリングなどは未実装です。機能追加などのPull Requestを歓迎します。

このパッケージを利用して郵便番号検索するには[ケンオール ホーム](https://kenall.jp/home)からAPIキーを取得する必要があります。

Install
-------

[](#install)

[Composer](https://getcomposer.org/)を利用します。

```
composer require zonuexe/kenall
```

このパッケージでは[php-http/discovery](https://github.com/php-http/discovery)を用いてインストール済みのPSR-HTTPパッケージを利用します。

使用時に以下のようなエラーが発生する場合はパッケージが不足しています。

```
PHP Fatal error:  Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors
 - Puli Factory is not available
 - No valid candidate found using strategy "Http\Discovery\Strategy\CommonClassesStrategy". We tested the following candidates: Nyholm\Psr7\Factory\HttplugFactory, Http\Message\MessageFactory\GuzzleMessageFactory, Http\Message\MessageFactory\DiactorosMessageFactory, Http\Message\MessageFactory\SlimMessageFactory.
 - No valid candidate found using strategy "Http\Discovery\Strategy\CommonPsr17ClassesStrategy". We tested the following candidates: .

```

以下の仮想パッケージからそれぞれ好きな組み合わせをComposerでインストールしてください。

- [`psr/http-factory-implementation`](https://packagist.org/providers/psr/http-factory-implementation)
- [`psr/http-client-implementation`](https://packagist.org/providers/psr/http-client-implementation)

もしGuzzleを利用しているなら以下のようなコマンドで最新版にアップデートできるかもしれません。

```
composer require guzzlehttp/guzzle guzzlehttp/psr7
```

API
---

[](#api)

### `function find(string $postal_code): AddressResolverResponse`

[](#function-findstring-postal_code-addressresolverresponse)

難しいことを考えずに郵便番号検索したいひと向けの関数です。

関数を呼び出す前に環境変数 `'KENALL_AUTHORIZATION_TOKEN'` をセットする必要があります。また、内部的には後述する `create_client()` の結果をキャッシュしています。

引数の `string $postal_code` は文字列型で7桁の数字である必要があります。

### `function create_client(string $api_key): KenallClient`

[](#function-create_clientstring-api_key-kenallclient)

APIクライアントのインスタンスを取得し、オブジェクト指向的に操作したい人向けの関数です。

内部では[php-http/discovery](https://github.com/php-http/discovery)を用いてPSR-18 Http Client および、PSR-17 Http Factory の実装クラスを探索して自動検出します。

### `class KenallClient`

[](#class-kenallclient)

ケンオールへのAPIリクエストを行なうクライアントクラスです。

- `findPostalCode(string $postal_code): AddressResolverResponse`
    - ケンオールの `GET /postalcode/:郵便番号` APIに対応します
    - 引数の `string $postal_code` は文字列型で7桁の数字である必要があります。

### `class AddressResolverResponse`

[](#class-addressresolverresponse)

ケンオールの `GET /postalcode/:郵便番号` APIから返される値に対応したオブジェクトです。

```
echo $response->version, PHP_EOL;
// => "2021-01-29"

```

このオブジェクトは `ArrayAccess` およびイテレータを実装しており、配列や `foreach` でのデータの取り出しに対応しています。これらの方法で `Address` を取得することができます。

### `class Address` (郵便区画レコード)

[](#class-address-郵便区画レコード)

一般的な意味での「住所」に相当するクラスです。プロパティは[ケンオールのドキュメント](https://www.notion.so/API-47ab1a425d9e48aaad5b34b4f703c718)に準じています。

使用のためのヒント
---------

[](#使用のためのヒント)

### 初心者向け

[](#初心者向け)

[ケンオール](https://kenall.jp/home)から取得できるAPIキーを環境変数 `KENALL_AUTHORIZATION_TOKEN` としてセットしておいてください。

```
setenv('KENALL_AUTHORIZATION_TOKEN', YOUR_API_KEY);

$postal_code = '1000001';
$area = zonuexe\Kenall\find('1000001')[0];
// => 東京都千代田区千代田
```

### 中級者向け

[](#中級者向け)

この方法で利用する場合、トークンは環境変数にセットする必要はありません。

```
$client = zonuexe\Kenall\create_client(getenv('KENALL_AUTHORIZATION_TOKEN'));

$postal_code = '1000001';
foreach ($client->findPostalCode($postal_code) as $area) {
    printf("%s%s%s\n", $area->prefecture, $area->city, $area->town);
}
// => 東京都千代田区千代田
```

### 上級者向け

[](#上級者向け)

上記の方法をそのままコードに組み込んだ場合、ユニットテストなどでケンオールAPIにリクエストしてしまうリスクがあります。PSR-18対応のHTTPクライアントクラスを注入することでテスト時のHTTPクライアントを差し替えることができます。

```
$http_client = new Your\Http\MockCloent()
$client = zonuexe\Kenall\create_client($api_key, $http_client);
```

あるいは[PHP-HTTP Discoveryのドキュメント](https://php-http.readthedocs.io/en/latest/discovery.html)を参考にMockClientをセットすることで実装コードに手を入れずにHTTPクライアントを避けることも可能です。

Copyright
---------

[](#copyright)

> Copyright 2021 USAMI Kenta
>
> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
>
> ```
> http://www.apache.org/licenses/LICENSE-2.0
>
> ```
>
>
>
> Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

1893d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1cc4bc1729b858086681a12494fda6cced8f26db3d0928ae4d81c68ddf8dc06?d=identicon)[zonuexe](/maintainers/zonuexe)

---

Top Contributors

[![zonuexe](https://avatars.githubusercontent.com/u/822086?v=4)](https://github.com/zonuexe "zonuexe (20 commits)")

### Embed Badge

![Health badge](/badges/zonuexe-kenall/health.svg)

```
[![Health](https://phpackages.com/badges/zonuexe-kenall/health.svg)](https://phpackages.com/packages/zonuexe-kenall)
```

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

963.1M35](/packages/getbrevo-brevo-php)[swisnl/json-api-client

A PHP package for mapping remote JSON:API resources to Eloquent like models and collections.

211473.2k12](/packages/swisnl-json-api-client)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[deeplcom/deepl-php

Official DeepL API Client Library

2616.2M66](/packages/deeplcom-deepl-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
