Download the PHP package salesrender/plugin-core-geocoder without Composer
On this page you can find all versions of the php package salesrender/plugin-core-geocoder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download salesrender/plugin-core-geocoder
More information about salesrender/plugin-core-geocoder
Files in salesrender/plugin-core-geocoder
Package plugin-core-geocoder
Short Description SalesRender plugin geocoder core
License proprietary
Informations about the package plugin-core-geocoder
Plugin Core Geocoder
Type-specific core framework for SalesRender GEOCODER plugins
Overview
salesrender/plugin-core-geocoder is a specialized core library that extends the base salesrender/plugin-core to build Geocoder-type plugins. Geocoder plugins resolve addresses to geographic coordinates, timezones, and structured address data.
This core provides:
- A
GeocoderInterfacethat the developer must implement with actual geocoding logic - A
GeocoderContainerfor registering the geocoder implementation - An HTTP endpoint (
POST /protected/geocoder/handle) for processing geocoding requests - A
GeocoderResultvalue object for returning structured results (address, timezone, info) - A
Timezoneclass supporting both named timezones and UTC offsets - A
GeocoderActionthat parses requests and invokes the configured geocoder
Installation
Requirements
- PHP >= 7.4
- ext-json
salesrender/plugin-core^0.4.0 (installed automatically)salesrender/component-address^1.0.0 (installed automatically)adbario/php-dot-notation^2.2 (installed automatically)
Architecture
How This Core Extends plugin-core
plugin-core-geocoder overrides both factory classes from the base plugin-core:
WebAppFactory (extends \SalesRender\Plugin\Core\Factories\WebAppFactory):
- Adds CORS support
- Registers the
GeocoderActionatPOST /protected/geocoder/handlewith protected middleware
ConsoleAppFactory (extends \SalesRender\Plugin\Core\Factories\ConsoleAppFactory):
- Inherits all base commands without adding new ones (geocoding is synchronous, no queue needed)
Request Flow
Getting Started: Creating a Geocoder Plugin
Step 1: Project Setup
Create a new project and add the dependency:
Create the directory structure:
Step 2: Bootstrap Configuration
Create bootstrap.php in the project root. This file configures all plugin components:
Key geocoder-specific configuration points:
PluginType::GEOCODER-- identifies this plugin as a Geocoder typecountries-- array of ISO 3166-1 alpha-2 country codes that this geocoder supports (e.g.,['RU'],['RU', 'KZ'])GeocoderContainer::config()-- registers yourGeocoderInterfaceimplementation
Step 3: Implement GeocoderInterface
This is the core of your geocoder plugin. Create a class that implements GeocoderInterface:
The handle() method receives two parameters:
$typing-- free-form text typed by the user (for autocomplete-style address search)$address-- a structuredAddressobject with fields like region, city, address_1, address_2, postcode, countryCode, and location
It must return an array of GeocoderResult objects. Each result contains a resolved Address, an optional Timezone, and an optional info string.
Step 4: Create Web Entry Point
Create public/index.php:
Create public/.htaccess:
Step 5: Create Console Entry Point
Create console.php:
Step 6: Create Settings Form
Create src/SettingsForm.php:
Step 7: Create .env
Create example.env (copy to .env for local development):
Step 8: Initialize & Deploy
HTTP Routes
Routes added by \SalesRender\Plugin\Core\Geocoder\Factories\WebAppFactory:
| Method | Path | Description | Source |
|---|---|---|---|
POST |
/protected/geocoder/handle |
Receives geocoding requests. Parses the request body into typing (string) and address (Address), invokes GeocoderInterface::handle(), and returns a JSON array of GeocoderResult objects. Protected by middleware. |
GeocoderAction |
Additionally, all base plugin-core routes are inherited:
| Method | Path | Description |
|---|---|---|
GET |
/info |
Plugin information |
PUT |
/registration |
Plugin registration |
GET |
/protected/forms/settings |
Settings form definition |
PUT |
/protected/data/settings |
Save settings |
GET |
/protected/data/settings |
Get settings data |
GET |
/protected/autocomplete/{name} |
Autocomplete handler |
GET |
/robots.txt |
Robots.txt |
Request Format
POST /protected/geocoder/handle expects the following JSON body:
Response Format
Returns a JSON array of geocoder results:
Error Responses
| Code | Description |
|---|---|
400 |
Invalid address data in the request |
417 |
GeocoderHandleException -- geocoder-specific error during processing |
501 |
Geocoder not configured (GeocoderContainer has no handler) |
CLI Commands
The geocoder core does not add any new CLI commands beyond those inherited from the base plugin-core:
| Command | Description |
|---|---|
db:create |
Create database tables |
db:clean |
Clean database tables |
specialRequest:queue |
Process special request queue |
specialRequest:handle |
Handle a special request |
cron |
Run all scheduled cron tasks |
lang:add |
Add a translation language |
lang:update |
Update translations |
directory:clean |
Clean temporary directories |
Key Classes & Interfaces
GeocoderInterface
Namespace: SalesRender\Plugin\Core\Geocoder\Components\Geocoder\GeocoderInterface
The primary interface that every geocoder plugin must implement:
GeocoderResult
Namespace: SalesRender\Plugin\Core\Geocoder\Components\Geocoder\GeocoderResult
A value object that represents a single geocoding result. Implements JsonSerializable.
| Method | Return Type | Description |
|---|---|---|
__construct(Address $address, ?Timezone $timezone, ?string $info = null) |
Create a result with address, optional timezone, and optional info | |
getAddress() |
Address |
The resolved/enhanced address |
getTimezone() |
?Timezone |
The resolved timezone (if available) |
getInfo() |
?string |
Additional informational text about this result |
GeocoderContainer
Namespace: SalesRender\Plugin\Core\Geocoder\Components\Geocoder\GeocoderContainer
Static container for registering and retrieving the GeocoderInterface implementation.
| Method | Return Type | Description |
|---|---|---|
config(GeocoderInterface $geocoder) |
void |
Register the geocoder implementation |
getHandler() |
GeocoderInterface |
Retrieve the registered geocoder. Throws GeocoderContainerException if not configured. |
Timezone
Namespace: SalesRender\Plugin\Core\Geocoder\Components\Geocoder\Timezone
Represents a timezone, accepting either a named timezone or a UTC offset. Implements JsonSerializable.
| Method | Return Type | Description |
|---|---|---|
__construct(string $timezoneOrOffset) |
Create from a timezone name (e.g., "Europe/Moscow") or UTC offset (e.g., "UTC+03:00"). Throws InvalidTimezoneException if invalid. |
|
getName() |
?string |
The timezone name (e.g., "Europe/Moscow") or null if constructed from offset |
getOffset() |
?string |
The UTC offset (e.g., "UTC+03:00") or null if constructed from name |
Examples:
The offset format must match the pattern UTC[+-]\d{2}:\d{2} (e.g., UTC+03:00, UTC-05:00). Named timezones must be valid PHP DateTimeZone identifiers.
GeocoderAction
Namespace: SalesRender\Plugin\Core\Geocoder\GeocoderAction
HTTP action that handles POST /protected/geocoder/handle. Implements ActionInterface. Parses the request body using dot notation (via Adbar\Dot), constructs an Address object with optional Location, and invokes the geocoder.
The action:
- Retrieves the geocoder from
GeocoderContainer::getHandler() - Extracts
typingfrom the request body - Constructs an
Addressfrom theaddress.*fields, including optionalLocation(latitude/longitude) - Calls
GeocoderInterface::handle($typing, $address) - Returns the result array as JSON
Exceptions
| Exception | Namespace | Description |
|---|---|---|
GeocoderContainerException |
SalesRender\Plugin\Core\Geocoder\Exceptions |
Thrown when GeocoderContainer::getHandler() is called before configuration |
GeocoderHandleException |
SalesRender\Plugin\Core\Geocoder\Exceptions |
Should be thrown by the geocoder implementation when an expected error occurs during geocoding. Results in a 417 HTTP response. |
InvalidTimezoneException |
SalesRender\Plugin\Core\Geocoder\Exceptions |
Thrown when constructing a Timezone with an invalid name or offset |
Example Plugin
See the reference implementation: plugin-example-geocoder
Dependencies
| Package | Version | Purpose |
|---|---|---|
salesrender/plugin-core |
^0.4.0 | Base plugin framework |
salesrender/component-address |
^1.0.0 | Address and Location value objects |
adbario/php-dot-notation |
^2.2 | Dot notation access for nested request data |
See Also
- salesrender/plugin-core -- Base plugin framework
- salesrender/component-address -- Address component
- plugin-example-geocoder -- Example geocoder plugin implementation
All versions of plugin-core-geocoder with dependencies
ext-json Version *
salesrender/plugin-core Version ^0.4.0
salesrender/component-address Version ^1.0.0
adbario/php-dot-notation Version ^2.2