Search by

absolutoffice / geo-master

absolutoffice

Object-oriented PHP library for managing and querying geographic and postal data (countries, languages, currencies, major areas, subdivisions and postal codes) built on PDO with a repository structure.

Package info

github.com/absolutoffice/geoMaster

Type:project

pkg:composer/absolutoffice/geo-master

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-11-29 16:16 UTC

This package is auto-updated.

Last update: 2026-11-29 18:27:29 UTC


README

An object-oriented PHP library for managing and querying geographic and postal data: countries, languages, currencies, major areas, subdivisions and postal codes, built on a repository structure over PDO and bank access (docs/banking.md). It is designed to be used as a dependency from other applications without coupling their database configuration.

For more context on the project's goals, components and principles, see GeoMaster.md.

Requirements

Requirement Detail
PHP 8.0 or higher, declared as php: >=8.0 in composer.json and required by the included examples and tests
PHP extensions PDO and pdo_mysql
Database MariaDB (the schema is distributed as a MariaDB dump)
Composer To install dependencies and run the project scripts
Dependencies vlucas/phpdotenv (runtime) and phpstan/phpstan (static analysis, dev)

Installation

  1. Install the Composer dependencies:

    composer install
  2. Create an empty, dedicated database for GeoMaster and then import the schema. The dump does not create the database, so it must exist beforehand:

    mysql -u <user> -p -e "CREATE DATABASE geomaster CHARACTER SET utf8mb4;"
    mysql -u <user> -p geomaster < docs/db/geomaster.sql
  3. Copy the versioned environment template .env.example (in the project root) to .private/geoMaster/.env and fill in the values:

    mkdir -p .private/geoMaster
    cp .env.example .private/geoMaster/.env

    This example creates the private directory inside the local copy; .gitignore excludes it from Git. You can also place it in a parent folder: the loader (config/environment.php) searches for .private/geoMaster upward from the project root and uses the first matching directory. It does not load a .env located directly in the project root.

Environment variables

src/GeoMaster/GeoMasterConnection.php reads the following variables ($_ENV):

Variable Required Default Description
GEOMASTER_DB_HOST No 127.0.0.1 Database host
GEOMASTER_DB_NAME Yes — Database name
GEOMASTER_DB_USER Yes — Database user
GEOMASTER_DB_PASS Yes — Database password
GEOMASTER_DB_PORT No 3306 Server port
GEOMASTER_DB_PDO_CHARSET No utf8mb4 PDO DSN charset
GEOMASTER_DB_PDO_DSN_PREFIX No mysql PDO DSN prefix

Additional optional variables: GEOMASTER_DB_PERSISTENT (persistent connections, boolean value), GEOMASTER_DB_TIMEOUT (timeout, integer) and GEOMASTER_DB_TIMEZONE (runs SET time_zone on connect).

Usage: postal code service

GeoMaster\Postal\PostalCodeService requires no arguments on construction. The search applies the rules defined per country (exact match with priority, and abbreviated search only if the country defines search_pattern):

<?php

// Save this example in the project root.
require_once __DIR__ . '/config/environment.php';

use GeoMaster\Postal\PostalCodeService;

$service = new PostalCodeService();
$results = $service->search(
    'ES',      // ISO 3166-1 alpha-2 code
    '28001',   // postal code or abbreviated search
    100,       // limit (optional, default 100)
    0          // offset (optional, default 0)
);

If the country has no postal rule defined, search() throws RuntimeException. The included data is not exhaustive geographic coverage: source traceability and the actual scope of the catalog are described in GeoMaster.md.

Tests and analysis

Command What it does
composer test Runs the three regular tests (tests/LargeAreaCatalogTest.php, tests/SubdivisionCatalogTest.php, tests/PostalCanonicalGeographyTest.php). They use a PDO mock and only require vendor/autoload.php: they need neither a real database nor environment variables.
composer analyse Static analysis with PHPStan (phpstan analyse -c phpstan.neon.dist --no-progress).
composer docs Regenerates the reference under docs/api/ with the committed tools/phpDocumentor.phar. That output is generated: review a change to it by re-running this command and comparing the result, not by reading the HTML by hand.
composer test:db tests/CanonicalGeographyDatabaseTest.php: read-only (SELECT) assertions against a real database. Requires the environment configured with valid credentials and a MariaDB server reachable from the machine running it; it is a manual check, is not part of composer test, and is not run automatically by this project.

Included dataset

docs/db/geomaster.sql is a MariaDB 10.11 dump of the reference schema and data. It contains the 16 tables bancos, bancos_codigos, continentes, continentes_traducciones, country, country_idiomas, country_timezones, grandes_areas, idiomas, idiomas_idioma, monedas, monedas_idiomas, postal_code_rules, postal_codes, subdivisiones and timezones.

The dump holds data only: it does not create the database and carries no user or permission statements, so it is imported into the empty database you create in the installation steps. Coverage of postal codes and subdivisions is not exhaustive and matches this dump as published; no currency, freshness or per-country completeness is promised. Source traceability is described in GeoMaster.md.

License

Both the code and the included dataset are distributed under the same MIT license; see LICENSE.