Download the PHP package bvp/prefecture without Composer
On this page you can find all versions of the php package bvp/prefecture. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bvp/prefecture
More information about bvp/prefecture
Files in bvp/prefecture
Informations about the package prefecture
Prefecture
日本語
A small utility library for converting between Japanese prefecture/region numbers, names (kanji, hiragana, katakana, English), and the region each prefecture belongs to — backed by native PHP 8.1 enums.
Why
Japan's 47 prefectures show up differently across systems: numeric codes (1–47), full kanji names (青森県), short names (青森), hiragana/katakana readings, or romanized English names (aomori). Converting between these, and resolving which of the 8 regions (地方) a prefecture belongs to, normally means hand-rolling lookup tables scattered across a codebase.
Prefecture provides this as a single, tested source of truth, backed by native PHP enums so each prefecture/region is a real, type-safe value you can pass around, compare with ===, and switch over.
Installation
Usage
Available methods
Prefecture and Region (both under BVP\Prefecture) expose the same three lookup methods:
| Method | Behavior |
|---|---|
Prefecture::from($value) / Region::from($value) |
Resolves by number or name (number lookup takes priority; see below) |
Prefecture::fromNumber(int $number) / Region::fromNumber(int $number) |
Resolves by number only (1–47 / 1–8) |
Prefecture::fromName(string $name) / Region::fromName(string $name) |
Resolves by any name variant (kanji, short, hiragana, katakana, or English; English matching is case-insensitive) |
All lookup methods return null when no match is found.
Note on priority: from() always tries the value as a number first. Prefecture::from('13') resolves to prefecture number 13 (Tokyo), not a prefecture literally named "13".
Deprecated:
Prefecture::fromRegion(),fromRegionNumber(), andfromRegionName()still work but delegate to theRegionclass above and will be removed in the next major version. UseRegion::from()/fromNumber()/fromName()instead.
Enum methods
Once resolved, BVP\Prefecture\Enums\Prefecture and BVP\Prefecture\Enums\Region cases expose:
| Method | Behavior |
|---|---|
->toArray() |
All name variants as an array (and, for Prefecture, its region's name variants too) |
->name() / ->shortName() / ->hiraganaName() / ->katakanaName() / ->englishName() |
The corresponding name variant |
Prefecture->region() |
The Region case this prefecture belongs to |
Region->prefectures() |
All Prefecture cases belonging to this region, in number order |
->jsonSerialize() |
Same shape as toArray(); used automatically by json_encode() since both enums implement JsonSerializable |
What it does not do
- It does not cover municipalities (市区町村) or any administrative unit below the prefecture/region level.
- It does not track historical administrative changes; only the current 47 prefectures and 8 regions are represented.
License
Prefecture is open-source software released under the MIT license.