oihana / php-magento
Composable PHP client for the Magento 2 REST API. Bundles an OAuth1-signed HTTP client (Guzzle), typed Magento entity schemas (Product, ProductImage, MediaGalleryEntry, ...), composable client traits, and a fluent SearchCriteria builder.
Requires
- php: >=8.4
- guzzlehttp/guzzle: ^7.10
- oihana/php-commands: dev-main
- oihana/php-core: dev-main
- oihana/php-enums: dev-main
- oihana/php-exceptions: dev-main
- oihana/php-files: dev-main
- oihana/php-reflect: dev-main
- oihana/php-system: dev-main
- php-di/php-di: ^7.0
- psr/container: ^2.0
Requires (Dev)
- nunomaduro/collision: ^8.8
- phpdocumentor/shim: ^3.8
- phpunit/phpunit: ^12
This package is auto-updated.
Last update: 2026-05-25 16:57:39 UTC
README
Composable PHP client for the Magento 2 REST API. Part of the Oihana PHP ecosystem, this package bundles an OAuth1-signed HTTP client (Guzzle), typed Magento entity schemas, composable client traits, and a fluent SearchCriteria builder โ the building blocks to query the Magento 2 REST API from PHP.
๐ Documentation
Full API reference (generated with phpDocumentor): https://bcommebois.github.io/oihana-php-magento
User guides (FR + EN) live under wiki/.
๐ฆ Installation
Requires PHP 8.4+ and a Magento 2 instance with REST API access. Install via Composer:
composer require oihana/php-magento
โจ What you can do
- Talk to Magento 2 over REST through a ready-to-use HTTP client built on Guzzle โ OAuth1 signed requests (consumer key + secret + access token + secret) with automatic nonce + timestamp generation, HMAC-SHA1 / HMAC-SHA256 signatures, and proper RFC 5849 query/body parameter handling.
- Build search criteria fluently โ the
SearchCriteriahelper turns(field, value, condition, group, sortOrder, pageSize, currentPage)tuples into the verbosesearchCriteria[filter_groups][...]query parameters Magento expects. - Hydrate typed entities โ
Product,ProductImage,MediaGalleryEntry,ProductVideo,ProductMediaGalleryEntriesContentand friends, with field-awareHydrateWithattributes for nested objects. - Access product media gallery โ composable
MagentoProductsTraitexposes products and media-gallery operations on top of the client; theMediaTypeandProductImageThumbnailenums make image-role logic explicit.
Under the hood
- A consistent set of value objects and enums โ
Magento,MagentoOption,MagentoParam,SearchCriteriaParam,ConditionTypeโ no magic strings. - Pure-PHP transport based on GuzzleHttp v7. OAuth1 signing is implemented from scratch in
OAuthSignerโ no third-party OAuth library required. - Hydration delegated to
oihana/php-reflectโ Magento response payloads map directly to typed objects via theHydrateWithattribute. - Schema constants split into trait-composed
ProductTrait,ThingTrait,MediaGalleryInterfaceTrait,MediaGalleryEntryTraitโ composable in your own DTOs.
โ Running tests
Run all tests:
composer test
Run a specific test file:
composer test ./tests/oihana/magento/http/OAuthSignerTest.php
The unit tests cover the OAuth1 signer, the search criteria builder, and the field utility helpers โ they run without a live Magento instance.
๐ ๏ธ Generate the documentation
We use phpDocumentor to generate documentation into the ./docs folder.
composer doc
๐งพ License
Licensed under the Mozilla Public License 2.0 (MPLโ2.0).
๐ค About the author
- Author: Marc ALCARAZ (aka eKameleon)
- Email:
marc@ooop.fr - Website:
https://www.ooop.fr
๐ Related packages
| Package | Description |
|---|---|
| oihana/php-auth | Casbin RBAC + JWT/OIDC authorization toolkit. |
| oihana/php-core | Core helpers and utilities shared across the ecosystem. |
| oihana/php-enums | Typed constants and enums โ no more magic strings. |
| oihana/php-exceptions | Framework exceptions with consistent semantics. |
| oihana/php-files | File system helpers (paths, readers, writers). |
| oihana/php-http | HTTP helpers โ client IP, cookies, route patterns. |
| oihana/php-openedge | Progress OpenEdge SQL toolkit (ODBC, query builder, models). |
| oihana/php-reflect | Reflection and object hydration utilities. |
| oihana/php-system | Framework helpers โ controllers, models, request handling. |
