Download the PHP package gcgov/arcgisphpsdk without Composer
On this page you can find all versions of the php package gcgov/arcgisphpsdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gcgov/arcgisphpsdk
More information about gcgov/arcgisphpsdk
Files in gcgov/arcgisphpsdk
Package arcgisphpsdk
Short Description Open source framework for PHP interactions with Garrett County, Maryland's ArcGIS implementation
License MIT
Informations about the package arcgisphpsdk
arcgisphpsdk
An open source PHP SDK for interacting with Garrett County, Maryland's ArcGIS Enterprise implementation. It wraps the ArcGIS REST API with strongly typed PHP classes so server-side applications can authenticate, query, create, update, and delete features on hosted feature services, manage layer schemas (fields and coded-value domains), and geocode addresses.
The SDK is the server-side half of Garrett County's GIS integrations: PHP applications use it to keep their own databases in sync with hosted ArcGIS feature layers, while browser applications render those same layers with the ArcGIS Maps SDK for JavaScript (@arcgis/core). The county's bridges application (gcgov/bridge-api + gcgov/bridge-app) is the reference implementation and the source of the examples in this document.
Requirements
- PHP >= 8.1
- guzzlehttp/guzzle ^7.8 (HTTP client)
- andrewsauder/json-deserialize ^3.0 (typed JSON hydration/serialization — every model in this SDK extends it)
Installation
Production applications pin a tagged release (for example "gcgov/arcgisphpsdk": "^2.0"). During local development, consuming applications typically require dev-main and register the SDK as a symlinked path repository so edits take effect immediately:
Architecture at a glance
Classes autoload from src/ with PSR-4 prefix gcgov\arcgis\. The code is split into two layers:
| Namespace | Purpose |
|---|---|
gcgov\arcgis\sdk\* |
Generic ArcGIS REST machinery: configuration, token generation, the FeatureService base class (query/add/update/delete/schema operations), the LocatorService base class (geocoding), typed models for service and layer metadata, and typed response models. |
gcgov\arcgis\* (root) |
Garrett County–specific service wrappers bound to specific published services. Each wrapper pairs with a sub-namespace of typed Feature / FeatureProperties / FeatureQuery classes that mirror that layer's schema. |
Prebuilt service wrappers:
| Class | ArcGIS service | Layer | Notes |
|---|---|---|---|
\gcgov\arcgis\MajorMinorFeatureService |
Hosted/Major_and_Minor_Structures/FeatureServer |
0 | The bridges application's system-of-record layer. When config has development=true, targets Hosted/DEVELOPMENT_Major_and_Minor_Structures instead. |
\gcgov\arcgis\BridgesCulvertsFeatureService |
Hosted/Bridges_and_Culverts/FeatureServer |
0 | Legacy bridges/culverts inventory layer; used for one-time imports into the bridges application. |
\gcgov\arcgis\CenterLinesCulvertsFeatureService |
Addresses/Garrett_Centerlines/FeatureServer |
1 | County road centerlines (Maryland SHA schema, uppercase field names). Includes getAllRoadNames(). |
\gcgov\arcgis\DPUWaterSystemEditorFeatureService |
Hosted/DPU_Water_System_Editor/FeatureServer |
21 layers + 5 tables | Department of Public Utilities water system assets (hydrants, valves, meters, mains, boundaries, inspection tables). One typed getAll…Features() method and a LAYER_*/TABLE_* id constant per sublayer and table. When config has development=true, targets Hosted/DEVELOPMENT_DPU_Water_System_Editor instead and transparently translates the LAYER_*/TABLE_* constants to that service's re-sequenced layer ids (0–25). |
\gcgov\arcgis\AddressLocator |
Addresses/Garrett_Address_Locator/GeocodeServer |
— | Address geocoding via findAddressCandidates. |
Every model extends andrewsauder\jsonDeserialize\jsonDeserialize, which gives it:
ClassName::jsonDeserialize( $json )— build a typed instance graph from a JSON string or Guzzle response body. Array properties are hydrated to the class named in the property's/** @var Type[] */docblock.- Serialization back to JSON via
json_encode(), with#[excludeJsonSerialize]/#[excludeJsonDeserialize]attributes and_afterJsonSerialize()/_afterJsonDeserialize()hooks to shape the payload.
Quick start
All SDK methods throw \GuzzleHttp\Exception\GuzzleException (transport failures) and \andrewsauder\jsonDeserialize\exceptions\jsonDeserializeException (unexpected response shape); wrap calls accordingly:
Configuration and authentication
\gcgov\arcgis\config carries the portal base URL, credentials, and a development flag:
config::getToken()lazily requests a token from{baseUrl}portal/sharing/rest/generateTokenthe first time it is needed, caches it on the config instance, and automatically requests a fresh one when the cached token expires. Every request the SDK makes appends this token, so you never handle tokens directly — just share oneconfiginstance across the services you construct.- The token request is made with
client=refererand a referer ofhttps://apps.garrettcountymd.gov(seesdk\Token::get()). development: trueswitches wrappers that support it (currentlyMajorMinorFeatureService) to theirDEVELOPMENT_-prefixed service so you can exercise edits without touching production data. Consuming applications typically pass their own "is local environment" flag here.
Real-world construction from bridge-api, where connection settings live in the app's environment config:
Reading features
Each service wrapper provides getAllFeatures() — or, for multi-layer services, one getAll…Features() method per sublayer — which queries the layer with f=geojson, where=1=1, and outFields=*, requesting 1,000 records per call and recursing with resultOffset while the response reports exceededTransferLimit. The merged result is an array of typed Feature objects:
Multi-layer services expose one typed method and one layer id constant per sublayer and table. The constants are also how you target a sublayer in edit and schema operations. The constants always hold the production layer ids — in development mode the service translates them to the development copy's ids on every request, so consuming code never branches on environment:
Layers that are searched by attribute also expose a where-filtered variant that pages exactly like getAll…Features() but sends your ArcGIS SQL where clause instead of 1=1 (escape embedded single quotes by doubling them):
A Feature follows the GeoJSON shape:
$feature->properties— aFeaturePropertiessubclass with one typed public property per layer field. Property names match the layer's field names exactly (lowercase snake_case on the county's hosted layers, e.g.county_number; uppercase on the SHA centerlines schema, e.g.RDNAMELOCAL). Date fields arrive as epoch milliseconds.$feature->geometry—sdk\Feature\Geometrywithtypeand acoordinatesarray. Coordinate order is GeoJSON[ longitude, latitude ], spatial reference WGS84 (wkid 4326). Line features carry nested coordinate arrays.$feature->getObjectId()/$feature->getGlobalId()— the ESRI identifiers, read from the layer's objectid/globalid fields.
Editing features
sdk\FeatureService exposes addFeatures(), updateFeatures(), and deleteFeatures(), each accepting an array of Feature objects and an optional layer id (default 0). Internally the SDK converts each GeoJSON-shaped Feature into the ESRI edit format ({ attributes: {...}, geometry: { x, y, spatialReference: { wkid: 4326 } } }) via sdk\AddFeature::fromFeature() / sdk\UpdateFeature::fromFeature(). Features without coordinates serialize with no geometry, making an attribute-only edit.
Add
Check both the response-level error and each per-feature result — this is the pattern bridge-api uses, including capturing the new ESRI ids back onto its own record so future syncs can match:
Update
Fetch existing features, mutate their typed properties, and send them back. updateFeatures() matches on the feature's objectid:
$updateResponse->updateResults contains a per-feature success flag and optional error, exactly like add results.
Delete
Deletion is by object id — each passed feature must have its objectid populated (getObjectId()); features without one are skipped.
Attachments
For layers published with hasAttachments, files can be attached to a feature by object id (POST {layer}/{objectId}/addAttachment) and listed back (GET {layer}/{objectId}/attachments):
addAttachment() streams the file as a multipart upload; the attachment name defaults to the file's base name and the mime type part is omitted when $contentType is null. ArcGIS does not deduplicate attachments — upload with deterministic names and check getAttachmentInfos() first when an operation may run more than once (see the utility-account-lookup-api meter replacement sync).
Managing layer schema (fields and domains)
The FeatureService base class can administer the layer definition through the ArcGIS admin REST endpoint. bridge-api uses this to project its application model onto the GIS layer: it reflects over its own classes and creates/updates one ESRI field per property, including coded-value domains for dropdown-style fields.
Inspect the current schema:
Add or update fields:
Both return a response with success and error. addFeatureLayerFields() additionally returns domainMap entries — when ArcGIS has to rename a requested domain (name collision), createdDomainName differs from originalDomainName, and the caller should persist the created name for future lookups (see bridge-api's gisIntegration::updateFeatureLayerDefinition()).
Service metadata
Both calls cache their result on the service instance; pass forceFetch: true to re-request (for example after changing the schema — updateFeatureLayerFields() does this automatically).
FeatureServerLayer also provides lookup helpers for translating human readable values into stored codes (all name matching is case-insensitive):
Geocoding
\gcgov\arcgis\AddressLocator wraps the county's geocode service. Set any of the standard findAddressCandidates parameters as public properties, then call findAddressCandidates() — every non-null property becomes a query string parameter:
How the bridges application uses this SDK (reference integration)
The bridges asset-management system demonstrates the intended full-stack pattern.
Server side (bridge-api, PHP): MongoDB is the system of record for structure documents; the Major_and_Minor_Structures hosted layer is the GIS projection of that data. Scheduled CLI endpoints keep the two in sync:
- Schema sync (
/cli/updateFeatureLayerDefinition) — reflects over the application'sstructuremodel. Properties tagged with an#[esriField]attribute map to ESRI fields (deriving field name, type, and alias from the PHP property); properties tagged with a category attribute get coded-value domains built from the application's category/type tables. Fields are then created or updated on layer 0 viaaddFeatureLayerFields()/updateFeatureLayerFields(). - Feature sync (
/cli/updateGisFeatures) — pulls all features withgetAllFeatures(), matches them to Mongo documents by storedesriGlobalId, then: updates matched features (copying application values onto$feature->propertiesand rounding coordinates to 5 decimals), adds features for unmatched documents (persisting the returnedobjectId/globalIdback to Mongo), and deletes features that no longer have a matching document. - Reference-data pulls — road names and extents are imported from the centerlines layer (
CenterLinesCulvertsFeatureService::getAllFeatures()), and the legacyBridges_and_Culvertslayer was imported one-time into Mongo the same way.
Client side (bridge-app, Vue 3 + @arcgis/core ^4.29): the browser never talks to the PHP SDK — it renders the same ArcGIS services directly with the ArcGIS Maps SDK for JavaScript, and plots application data (structure coordinates served by bridge-api from Mongo) as graphics:
The contract that makes the two halves line up:
- Same services — the JS
FeatureLayerURLs are the sameFeatureServerendpoints the PHP wrappers are bound to. - Same coordinates — both sides use WGS84 (wkid 4326) with GeoJSON
[ longitude, latitude ]ordering; the PHP SDK writes point geometry asx = longitude,y = latitude. - Stable identifiers —
esriObjectId/esriGlobalIdcaptured at add time let either side correlate a GIS feature with an application record. - Domains as dropdowns — coded-value domains written by the schema sync drive both ArcGIS pop-ups/editors and the application's own select lists (the app stores each type's
esriCode).
Adding support for a new feature service
Wrapping another published service is a four-file pattern (see src/MajorMinorFeatureService* for the canonical example):
-
Service wrapper —
src/MyServiceFeatureService.php, extendingsdk\FeatureServiceand hard-coding the service and admin URLs (branch on$config->isDevelopment()if a development copy of the service exists): -
Properties —
src/MyServiceFeatureService/FeatureProperties.phpextendingsdk\FeatureProperties, with one nullable typed public property per layer field, named exactly as the field is named on the layer (checkgetFeatureServerLayer()->fields). -
Feature —
src/MyServiceFeatureService/Feature.phpextendingsdk\Feature; type the$propertiesproperty to yourFeatureProperties, instantiate it in the constructor, and implementgetProperties(),getObjectId(), andgetGlobalId()against the layer's id fields. - Query —
src/MyServiceFeatureService/FeatureQuery.phpextendingsdk\FeatureQuery, re-declaring$featuresso the docblock hydrates elements to yourFeatureclass:
The /** @var ... */ docblock on $features is what tells the deserializer which class to hydrate — without it (or with the wrong class name) features will not be typed correctly.
License
MIT — see LICENSE.
All versions of arcgisphpsdk with dependencies
guzzlehttp/guzzle Version ^7.8
andrewsauder/json-deserialize Version ^3.0