Download the PHP package oihana/php-schema without Composer
On this page you can find all versions of the php package oihana/php-schema. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oihana/php-schema
More information about oihana/php-schema
Files in oihana/php-schema
Package php-schema
Short Description The Oihana PHP Schema library
License MPL-2.0
Homepage https://github.com/BcommeBois/oihana-php-schema
Informations about the package php-schema
Oihana PHP - Schema

Oihana Schema is a PHP library that provides an object-oriented implementation of the Schema.org vocabulary. It is designed to encapsulate structured data using strongly typed value objects, with automatic serialization and hydration features.
This library is ideal for representing database records or REST API resources in a structured, semantically rich way, compatible with JSON-LD and linked data ecosystems.
โจ Key Features
- โ๏ธ Full modeling of Schema.org entities
- ๐งฉ Automatic JSON-LD serialization (JsonSerializable)
- ๐ช Recursive object hydration (including nested types and union types)
- ๐ง Internal reflection system (oihana\reflections)
- ๐ฏ Safe property access via constants (e.g. Schema::NAME)
- ๐ Extensible architecture for custom ontologies
- ๐ Support for ArangoDB metadata (_id, _key, _rev, _from, _to)
๐ฆ Installation
Requires PHP 8.4+
Install via Composer:
๐ Quick Example
Simple usage
JSON-LD output
๐๏ธ Schemas overview
The library exposes three top-level namespaces. Each row below links to a dedicated wiki guide (English / Franรงais) that lists the classes, gives a code example and points to the source.
| Namespace | What it covers | Classes | Wiki guide |
|---|---|---|---|
org\schema |
Full Schema.org vocabulary โ typed value objects for Thing, Person, Place, Event, Product, Offer, the complete Action hierarchy, creative works, organizations, services, enumerations. |
~400 | ๐ซ๐ท FR |
xyz\oihana\schema\auth |
OAuth2/OIDC clients, sessions, keyfiles, users, roles, permissions, RBAC policies, Casbin helpers, JWT claims registry. | 15 | ๐ซ๐ท FR |
xyz\oihana\schema\business |
Account โ business-world link: BusinessIdentity (typed account/entity link) and UserProfile (creation-time provisioning template). |
2 | ๐ซ๐ท FR |
xyz\oihana\schema\business\documents |
The quote โ purchase order โ invoice cycle (and its neighbors): BusinessDocument (common parent), Quote, PurchaseOrder, Invoice, CreditNote, DebitNote, DeliveryNote, GoodsReceiptConfirmation, Receipt, RemittanceAdvice, Statement/StatementEntry, the BusinessDocumentExporter/JsonLdExporter export layer, plus the cross-cutting value objects TaxDetail, Adjustment, EcoFeeRule/AppliedEcoFee, DocumentTotals, BusinessDocumentLine, PaymentSchedule/PaymentInstallment/PaymentReminder, DeliveryLine/ProofOfDelivery, GoodsReceiptLine, AgingSummary. |
27 | ๐ซ๐ท FR |
xyz\oihana\schema\http |
Structured HTTP request metadata: UserAgentInfo (browser, OS, device class, bot flag). |
1 | ๐ซ๐ท FR |
xyz\oihana\schema\organizations |
Business entities: Company (French SIRET/APE identifiers, address + contact ingestion) and its Customer, Provider, Subsidiary, Affiliate flavors. |
5 | ๐ซ๐ท FR |
xyz\oihana\schema\people |
Business contacts: Person and its typed flavors Seller, CustomerEmployee, Employee, ProviderEmployee, SubsidiaryEmployee. |
6 | ๐ซ๐ท FR |
xyz\oihana\schema\products |
Commerce layer: Product (eligible-quantity tree, unit-of-sale conversions, resolveUnitCode() hook) with StockLevel, TaxRate, PriceSegmentation, scoped PricingCondition/PricingConditionSelector rules, the customer-priced CustomerOffer, payment conditions, provider/warehouse information. |
16 | ๐ซ๐ท FR |
xyz\oihana\schema\places |
Operational locations: Site, Office, Warehouse, JobSite. |
4 | ๐ซ๐ท FR |
xyz\oihana\schema\shipping |
Standing shipping arrangements: DeliveryRouteAssignment โ which delivery route serves an address, on which days, in which order of passage. |
1 | ๐ซ๐ท FR |
xyz\oihana\schema\thesaurus |
SKOS concept trees on top of DefinedTerm: ThesaurusTerm, Concept, ProductCategoryTerm, ProductPriceCategoryTerm, ConceptScheme, Collection, OrderedCollection โ broader/narrower hierarchy, notes, cross-scheme mappings, collections โ the priced DeliveryMethodTerm and the recurring DeliveryRouteTerm, plus the registry layer (ThesaurusScheme, ThesaurusDomain). |
11 | ๐ซ๐ท FR |
xyz\oihana\schema |
Cross-cutting Oihana types: Pagination, Log, AuditAction, audit enumerations. |
3 + enums | ๐ซ๐ท FR |
com\progress\schema |
OpenEdge Progress SQL SYS% system catalog: tables, columns, indexes, views, users, privileges, constraints, sequences, triggers, procedures, data types. |
16 | ๐ซ๐ท FR |
Every entity extends org\schema\Thing, so they all share the same JSON-LD serialization, hydration and ArangoDB metadata. Sub-namespaces override the CONTEXT constant so downstream consumers can tell them apart:
| Namespace | JSON-LD @context |
|---|---|
org\schema |
https://schema.org |
xyz\oihana\schema* |
https://schema.oihana.xyz |
com\progress\schema |
https://schema.progress.com |
๐ง Internal Architecture
Base class: Thing
All entities extend the base class org\schema\Thing, which includes common Schema.org and metadata properties, as well as serialization logic:
The ThingTrait handles:
- Dynamic constructor from arrays or objects
- JSON-LD serialization via jsonSerialize()
- Reflection-based helpers from ReflectionTrait
Recursive Hydration
The internal Reflection::hydrate() method builds full object graphs from associative arrays, including nested value objects and union types:
`
๐ Safe Property Access
The org\schema\constants\Schema class contains constant names for every property in the Schema.org ontology and its extensions:
Properties are grouped by logical trait namespaces (e.g. Thing, Person, Event, etc.) for auto-completion and modularity:
๐ Documentation
Two complementary sets of documentation are available:
- ๐ Auto-generated API reference (every class, property and method) โ published at https://bcommebois.github.io/oihana-php-schema. Regenerate it locally with
composer doc. - โ๏ธ Hand-written wiki (concepts, guides, walkthroughs) โ bilingual EN/FR under
wiki/:- ๐ฌ๐ง Getting started)
- ๐ซ๐ท Dรฉmarrage rapide)
While the wiki grows, you can also explore the following namespaces directly:
org\schema\for value objectsorg\schema\traitsfor logic traitsorg\schema\constantsfor property constants
โ Running Unit Tests
To run all tests:
To run a specific test file:
๐งพ License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
๐ค About the author
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : [email protected]
- Website : http://www.ooop.fr
๐ ๏ธ Generate the Documentation
We use phpDocumentor to generate the documentation into the ./docs folder.
Usage
Run the command :
๐งฉ Advanced Usage
Union-typed properties
Some properties accept multiple types. For instance, publisher may be a string, a Person, or an Organization.
Arrays and nested entities
You can compose objects with arrays of other entities, leveraging the public-typed properties.
JSON-LD metadata for ArangoDB
Base Thing supports ArangoDB-style metadata fields to facilitate graph storage:
_key, _id, _rev, _from, _to.
Deep/recursive hydration
The constructor copies provided values into public properties.
For deep graphs and automatic casting, you can rely on the internal reflection utilities exposed by oihana/php-reflect (see developer docs). A typical approach is to call a reflection-based hydrate() to materialize nested arrays into value objects.
๐งฑ Extending the Library
Define your own types by extending org\schema\Thing or a more specific class, and add your public-typed properties. You can also define constants alongside org\schema\constants\Schema for safer access.
โ๏ธ Installation Notes
- This package requires PHP 8.4+.
- It depends on
oihana/php-coreandoihana/php-reflect. If your project enforces stable versions only, you may need to allow dev versions while these libraries are pre-release:- In your root composer.json: set
"minimum-stability": "dev"and"prefer-stable": trueif needed.
- In your root composer.json: set
๐ค Contributing
Contributions are welcome! Please:
- Open an issue to discuss significant changes before submitting a PR.
- Add tests when fixing a bug or adding a feature.
- Keep code style consistent and types explicit.
Local setup:
๐ Security
If you discover a security vulnerability, please email [email protected]. Do not open a public issue for security reports.
๐ Changelog
See CHANGELOG.md for notable changes.
๐ Related Packages
- oihana/php-core โ core helpers and utilities used by this library
- oihana/php-reflect โ reflection and hydration utilities
โ FAQ
- Why JSON-LD?
Itโs a web-native, schema-friendly format that plays well with linked data and search engines. - Can I output plain arrays?
Yes,jsonSerialize()returns arrays that you can pass to any JSON encoder. - How to ignore nulls?
Serialization automatically removes null values.
๐งฎ JSON Schema Generation
Generate JSON Schemas from the typed public properties of your classes.
Experimental โ local tooling only.
schemas/is gitignored: the generated files are not committed and nothing in the library consumes them. Regenerate on demand. The generator is known to be incomplete (see Known limitations below) and its output should not be relied upon for validation yet.
-
Single class (example: Place):
- All classes under
src/org/schema:
Details:
- Schemas are written to
schemas/*.schema.json. - Union types are represented as
oneOf; class types are emitted as$refinto local$defs. - Requires Composer autoload (run
composer dump-autoload -oif classes are not found).
Output layout and cleanup
- Namespaces map to folders under
schemas/:org\schema\...โschemas/org/schema/.../*.schema.jsonxyz\oihana\schema\...โschemas/xyz/oihana/schema/.../*.schema.json
- Running
composer schemas:allfirst deletes previous*.schema.jsonunderschemas/to avoid stale files, then regenerates everything.
Array unions handling
When a property type includes array plus other types (e.g. string|ImageObject|array<ImageObject|string>|null), the generator emits:
- direct options for
string,ImageObject,null(if present) - and an
arrayvariant whoseitemsuse aoneOfof the non-array types (hereImageObjectandstring).
Known limitations
The generator has not been finished; the following are known and unfixed:
composer schemas:allaborts with a fatal error on the function-only files underhelpers/hydrate/(class_exists()re-includes them). Since the script deletes every*.schema.jsonbefore generating, an aborted run leaves the output directory half-empty.- Generated schemas set
additionalProperties: falsebut omit the@typeand@contextkeys thatjsonSerialize()always emits, so no document produced by this library validates against its own schema. - Union types are emitted as
oneOf, which requires exactly one matching branch. A union containing bothintandfloatyields both anintegerand anumberbranch, and can therefore never be satisfied โanyOfis the correct keyword here. - Simple nullable types (e.g.
?bool) lose theirnulloption through a dead condition, sonullis rejected where the PHP type allows it. $defsentries are untyped stubs, and every$iduseshttps://schema.oihana.xyz/{ShortName}.jsonโ including fororg\schematypes, and with collisions between identical short names in different namespaces.
All versions of php-schema with dependencies
oihana/php-core Version dev-main
oihana/php-enums Version dev-main
oihana/php-reflect Version dev-main
oihana/php-standards Version dev-main