LocationService

Reference for the LocationService module: every class and function, with its full signature, parameters and return type. Real-time entity positions are served by a separate location server; this PHP module resolves and talks to that server, signs the tokens clients use to connect, and archives submitted paths to storage and the database.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes

LocationServiceApi

Registers the module's API endpoints into the ApiConfig registry and handles them: an authentication-token endpoint for the logged-in member, and a guarded admin endpoint that archives a submitted path.

AuthenticationToken

LocationServiceApi::AuthenticationToken(): mixed

Build the location server URL and a signed authentication token for the logged-in member. Returns null when no member is logged in.

Returns mixed An object with the location server URL and authentication token, or null.

AuthoriseAdmin

LocationServiceApi::AuthoriseAdmin(string $authorization): void

Shared-secret guard for the admin Path endpoint. Throws when the supplied token does not match the configured admin token.

NameTypeDescription
$authorizationstringThe authorization token supplied by the caller.

Returns void

Endpoints

LocationServiceApi::Endpoints(): void

Register the module's API endpoints into the ApiConfig registry. Called once at module load.

Returns void

Path

LocationServiceApi::Path(object $input, ApiContext $ctx): mixed

Store a submitted path chunk to storage, insert its archive row, then notify path listeners and handlers. Authorisation and input validation are handled by the endpoint config.

NameTypeDescription
$inputobjectThe validated endpoint input, including the entity permalink, channel hash, timestamps, point count and chunk.
$ctxApiContextThe API request context.

Returns mixed An object with the new path id.

LocationServiceApiConfig

Reads the API configuration values the application provides for the module.

GetTokenExpirySeconds

LocationServiceApiConfig::GetTokenExpirySeconds(): int

The configured token expiry, in seconds.

Returns int The token expiry in seconds.

LocationServiceAuth

Channel hashing, member permalinks and signed entity token payloads. Hashes are derived from the shared secret read through LocationServiceConfig.

Constants

ConstantValueDescription
LocationServiceAuth::MEMBER_ITEM_TYPE'member'The permalink item type used for members.

BuildTokenData

LocationServiceAuth::BuildTokenData(string $entityPermalinkString, string $channelCode, int $tokenExpirySeconds, string $moduleName = 'LocationService', string $entityType = 'member'): object

Build a signed token payload for an entity on a channel, with an expiry derived from the given number of seconds.

NameTypeDescription
$entityPermalinkStringstringThe permalink string identifying the entity.
$channelCodestringThe channel code the token grants access to.
$tokenExpirySecondsintThe number of seconds until the token expires.
$moduleNamestringThe owning module name.
$entityTypestringThe entity type.

Returns object The token payload, including the channel hash, expiry timestamp and signature hash.

ChannelHash

LocationServiceAuth::ChannelHash(string $channelCode): string

The 32-character hash identifying a channel code, derived from the code and the shared secret.

NameTypeDescription
$channelCodestringThe channel code to hash.

Returns string The channel hash.

KnownChannelCodes

LocationServiceAuth::KnownChannelCodes(): array

The list of channel codes the module recognises.

Returns array A list of channel code strings.

LocationServiceAuth::MemberPermalink(int $memberId): PermalinkData

The permalink for a member id, creating one if none exists yet.

NameTypeDescription
$memberIdintThe member id to resolve a permalink for.

Returns PermalinkData The member's permalink.

OptionalChannelCodeFromHash

LocationServiceAuth::OptionalChannelCodeFromHash(string $channelHash): ?string

The known channel code whose hash matches the given hash, or null when none matches.

NameTypeDescription
$channelHashstringThe channel hash to look up.

Returns ?string The matching channel code, or null.

LocationServiceBoundary

Builds an approximate axis-aligned bounding box around a point, in meters, using a local degree-per-meter approximation suitable for search radii.

RectangleAroundMeters

LocationServiceBoundary::RectangleAroundMeters(LocationCoordinateData $center, float $sizeMeters): array

An approximate bounding box of the given size, in meters, centred on a coordinate. Throws when the resulting box is degenerate.

NameTypeDescription
$centerLocationCoordinateDataThe coordinate at the centre of the box.
$sizeMetersfloatThe box edge length in meters.

Returns array A map with startLat, startLong, endLat and endLong.

LocationServiceClient

Talks to a running location server over HTTP to query entities within a rectangle and to read a single entity's raw record.

OptionalGetEntityRaw

LocationServiceClient::OptionalGetEntityRaw(string $serverUrl, string $adminToken, string $entityPermalinkString): ?object

Fetch the raw entity record from the server, or null when the entity is absent. Throws on a non-200 response.

NameTypeDescription
$serverUrlstringThe base URL of the location server.
$adminTokenstringThe admin token sent as the authorization header.
$entityPermalinkStringstringThe permalink string of the entity to fetch.

Returns ?object The raw entity object, or null.

QueryRectangle

LocationServiceClient::QueryRectangle(string $serverUrl, string $adminToken, string $channelHash, float $startLat, float $startLong, float $endLat, float $endLong): array

Query the server for entities on a channel within a rectangle. Throws on a non-200 response.

NameTypeDescription
$serverUrlstringThe base URL of the location server.
$adminTokenstringThe admin token sent as the authorization header.
$channelHashstringThe channel hash to query.
$startLatfloatThe southern latitude edge.
$startLongfloatThe western longitude edge.
$endLatfloatThe northern latitude edge.
$endLongfloatThe eastern longitude edge.

Returns array A list of entities, each with a permalink string and coordinate.

LocationServiceConfig

Reads the admin token and shared secret the module needs, and registers and triggers the handlers called when a path is created.

GetAdminToken

LocationServiceConfig::GetAdminToken(): string

The admin token used to authorise calls to the location server.

Returns string The admin token.

GetAdminTokenFromConfig

LocationServiceConfig::GetAdminTokenFromConfig(): string

The admin token read directly from application config; must match the location server's own token.

Returns string The admin token.

GetSharedSecret

LocationServiceConfig::GetSharedSecret(): string

The shared secret used to sign channel and entity token hashes.

Returns string The shared secret.

OnPath

LocationServiceConfig::OnPath(string $moduleName, string $entityType, callable $handler): void

Register a handler called when a path is created, filtered by module name and entity type. An empty filter matches all modules or all types.

NameTypeDescription
$moduleNamestringFilter by module name; empty matches all modules.
$entityTypestringFilter by entity type; empty matches all types.
$handlercallableA function receiving the path id and the path data.

Returns void

TriggerPath

LocationServiceConfig::TriggerPath(int $pathId, LocationServicePathData $pathData): void

Run the registered path handlers for an inserted path. Each handler is wrapped so one failure does not disrupt the others.

NameTypeDescription
$pathIdintThe id of the inserted path.
$pathDataLocationServicePathDataThe inserted path's data.

Returns void

LocationServiceContainerData

The resolved URLs and admin token for a running location server.

Properties

NameTypeDescription
$urlstringThe HTTP base URL of the server.
$websocketUrlstringThe WebSocket URL of the server.
$adminTokenstringThe admin token for the server.
Functions

__construct

LocationServiceContainerData::__construct(string $url, string $websocketUrl, string $adminToken)

Create the container data.

NameTypeDescription
$urlstringThe HTTP base URL of the server.
$websocketUrlstringThe WebSocket URL of the server.
$adminTokenstringThe admin token for the server.

LocationServiceDatabase

Resolves a running location server and searches or reads entity positions through it.

GetServiceData

LocationServiceDatabase::GetServiceData(): LocationServiceContainerData

Resolve a running location server and return its URLs and admin token. Throws when no server is running.

Returns LocationServiceContainerData The resolved server details.

OptionalGetEntity

LocationServiceDatabase::OptionalGetEntity(string $entityPermalinkString): ?LocationServiceEntityLocationData

Read one entity's position through the server, or null when the entity is absent or has no coordinate.

NameTypeDescription
$entityPermalinkStringstringThe permalink string of the entity to read.

Returns ?LocationServiceEntityLocationData The entity location, or null.

SearchChannel

LocationServiceDatabase::SearchChannel(string $channelCode, LocationCoordinateData $location, float $sizeMeters): array

Search a channel for entities within a radius, in meters, of a coordinate.

NameTypeDescription
$channelCodestringThe channel code to search.
$locationLocationCoordinateDataThe coordinate at the centre of the search.
$sizeMetersfloatThe search box edge length in meters.

Returns array A list of LocationServiceSearchResultData.

LocationServiceEntityLocationData

One entity's permalink, channel code and coordinate.

Properties

NameTypeDescription
$entityPermalinkStringstringThe permalink string identifying the entity.
$channelCodestringThe channel code the entity is on.
$coordinateLocationCoordinateDataThe entity's coordinate.
Functions

__construct

LocationServiceEntityLocationData::__construct(string $entityPermalinkString, string $channelCode, LocationCoordinateData $coordinate)

Create the entity location data.

NameTypeDescription
$entityPermalinkStringstringThe permalink string identifying the entity.
$channelCodestringThe channel code the entity is on.
$coordinateLocationCoordinateDataThe entity's coordinate.

LocationServicePath

Registers and notifies listeners called when a path is created.

NotifyPathListeners

LocationServicePath::NotifyPathListeners(int $pathId, string $entityCode, string $channelHash): void

Call every registered path-created listener with the given path details.

NameTypeDescription
$pathIdintThe id of the created path.
$entityCodestringThe entity code the path belongs to.
$channelHashstringThe channel hash the path was recorded on.

Returns void

OnPathCreated

LocationServicePath::OnPathCreated(callable $callback): void

Register a callback invoked when a path is created.

NameTypeDescription
$callbackcallableA function receiving the path id, entity code and channel hash.

Returns void

LocationServicePathData

One archived path row, with its endpoints, bounds and point count.

Properties

NameTypeDescription
$pathIdintThe path id.
$moduleNamestringThe owning module name.
$entityTypestringThe entity type.
$entityCodestringThe entity code.
$channelHashstringThe channel hash the path was recorded on.
$storageIdintThe storage id of the path chunk.
$startTimestampintThe start timestamp of the path.
$endTimestampintThe end timestamp of the path.
$startLatitudeMillionintThe start latitude, in millionths of a degree.
$startLongitudeMillionintThe start longitude, in millionths of a degree.
$endLatitudeMillionintThe end latitude, in millionths of a degree.
$endLongitudeMillionintThe end longitude, in millionths of a degree.
$pointCountintThe number of points in the path.
$timestampintThe timestamp the row was recorded.
$datestringThe recorded date.
Functions

__construct

LocationServicePathData::__construct(int $pathId, string $moduleName, string $entityType, string $entityCode, string $channelHash, int $storageId, int $startTimestamp, int $endTimestamp, int $startLatitudeMillion, int $startLongitudeMillion, int $endLatitudeMillion, int $endLongitudeMillion, int $pointCount, int $timestamp, string $date)

Create the path data.

NameTypeDescription
$pathIdintThe path id.
$moduleNamestringThe owning module name.
$entityTypestringThe entity type.
$entityCodestringThe entity code.
$channelHashstringThe channel hash the path was recorded on.
$storageIdintThe storage id of the path chunk.
$startTimestampintThe start timestamp of the path.
$endTimestampintThe end timestamp of the path.
$startLatitudeMillionintThe start latitude, in millionths of a degree.
$startLongitudeMillionintThe start longitude, in millionths of a degree.
$endLatitudeMillionintThe end latitude, in millionths of a degree.
$endLongitudeMillionintThe end longitude, in millionths of a degree.
$pointCountintThe number of points in the path.
$timestampintThe timestamp the row was recorded.
$datestringThe recorded date.

LocationServicePathDatabase

Reads and writes archived path rows in the location_service_path table.

Count

LocationServicePathDatabase::Count(?string $moduleName = null, ?string $entityType = null, ?string $entityCode = null): int

Count archived paths, optionally filtered by module name, entity type and entity code.

NameTypeDescription
$moduleName?stringThe module name to filter by, or null.
$entityType?stringThe entity type to filter by, or null.
$entityCode?stringThe entity code to filter by, or null.

Returns int The number of matching paths.

CountByEntityCodes

LocationServicePathDatabase::CountByEntityCodes(string $moduleName, string $entityType, array $entityCodes): array

Path counts keyed by entity code, for a given module and entity type.

NameTypeDescription
$moduleNamestringThe module name to count within.
$entityTypestringThe entity type to count within.
$entityCodesarrayThe entity codes to count for.

Returns array A map of entity code to path count.

fromRow

LocationServicePathDatabase::fromRow(object $row): LocationServicePathData

Map a database row to a LocationServicePathData object.

NameTypeDescription
$rowobjectThe database row to map.

Returns LocationServicePathData The mapped path data.

GetById

LocationServicePathDatabase::GetById(int $pathId): LocationServicePathData

Read one archived path row by id. Throws when there is no matching row.

NameTypeDescription
$pathIdintThe id of the path to read.

Returns LocationServicePathData The path data.

GetMaxId

LocationServicePathDatabase::GetMaxId(): int

The highest path id, or zero when the table is empty.

Returns int The highest path id, or zero.

Insert

LocationServicePathDatabase::Insert(string $moduleName, string $entityType, string $entityCode, string $channelHash, int $storageId, int $startTimestamp, int $endTimestamp, int $startLatitudeMillion, int $startLongitudeMillion, int $endLatitudeMillion, int $endLongitudeMillion, int $pointCount): int

Insert one archived path row and return its new id.

NameTypeDescription
$moduleNamestringThe owning module name.
$entityTypestringThe entity type.
$entityCodestringThe entity code.
$channelHashstringThe channel hash the path was recorded on.
$storageIdintThe storage id of the path chunk.
$startTimestampintThe start timestamp of the path.
$endTimestampintThe end timestamp of the path.
$startLatitudeMillionintThe start latitude, in millionths of a degree.
$startLongitudeMillionintThe start longitude, in millionths of a degree.
$endLatitudeMillionintThe end latitude, in millionths of a degree.
$endLongitudeMillionintThe end longitude, in millionths of a degree.
$pointCountintThe number of points in the path.

Returns int The new path id.

ListOrderedByIdDesc

LocationServicePathDatabase::ListOrderedByIdDesc(int $page, int $perPage, ?string $moduleName = null, ?string $entityType = null, ?string $entityCode = null): array

A page of archived paths, newest first, with optional module, type and entity filters.

NameTypeDescription
$pageintThe 1-based page number.
$perPageintThe number of rows per page.
$moduleName?stringThe module name to filter by, or null.
$entityType?stringThe entity type to filter by, or null.
$entityCode?stringThe entity code to filter by, or null.

Returns array A list of LocationServicePathData.

LocationServiceSearchResultData

One search hit: an entity permalink and its coordinate.

Properties

NameTypeDescription
$entityPermalinkStringstringThe permalink string identifying the entity.
$coordinateLocationCoordinateDataThe entity's coordinate.
Functions

__construct

LocationServiceSearchResultData::__construct(string $entityPermalinkString, LocationCoordinateData $coordinate)

Create the search result data.

NameTypeDescription
$entityPermalinkStringstringThe permalink string identifying the entity.
$coordinateLocationCoordinateDataThe entity's coordinate.

LocationServiceTokenError

A location server HTTP or token failure, such as a failed query or entity read. Extends Exception and carries the optional response body.

Properties

NameTypeDescription
$body?stringThe response body from the failed call, or null.
Functions

__construct

LocationServiceTokenError::__construct(string $message = '', int $code = 0, ?Exception $previous = null, ?string $body = null)

Create the error.

NameTypeDescription
$messagestringThe error message.
$codeintThe error code.
$previous?ExceptionThe previous exception, or null.
$body?stringThe response body from the failed call, or null.