aaron-apelt / akeneo-php-lib
An extension of the Akeneo PHP API client for easier Akeneo service development.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 2
pkg:composer/aaron-apelt/akeneo-php-lib
Requires
- php: ^8.4
- akeneo/api-php-client: ^11.4
- symfony/property-access: ^7.3
- symfony/serializer: ^7.3
Requires (Dev)
- laravel/pint: ^1.22
- mockery/mockery: ^1.6
- pestphp/pest: ^3.8
- phpstan/phpstan: ^2.1
This package is auto-updated.
Last update: 2026-01-24 18:12:26 UTC
README
A modern, type-safe PHP library for interacting with the Akeneo PIM API. Designed for clean domain models, batch processing, and flexible (de)serialization.
Features
- Akeneo Object Abstractions: Simple entity models for Akeneo objects.
- Adapters: Easy-to-use adapters for batch import/export with Akeneo.
- Fluent Collections: Powerful, lazy-evaluated collection operations.
- Flexible Serialization: Customizable serialization/denormalization.
- Querying: Query builder for advanced product searches.
- Batch Upserts: Efficient upsert and callback handling for large-scale imports.
- Strict Types & Modern PHP: Uses PHP 8+ features and strict typing throughout.
Installation
composer require aaron-apelt/akeneo-php-lib
Basic Usage
Instantiate the Adapter
use Akeneo\Pim\ApiClient\AkeneoPimClientBuilder; use AkeneoLib\Adapter\ProductAdapter; use AkeneoLib\Serializer\Serializer; $clientBuilder = new AkeneoPimClientBuilder('https://your-akeneo-url.example.com'); $client = $clientBuilder ->buildAuthenticatedByPassword('client_id', 'secret', 'user', 'password'); $productApi = $client->getProductApi(); $serializer = new Serializer(); $adapter = new ProductAdapter($productApi, $serializer);
Fetch Products
foreach ($adapter->all() as $product) { // $product is an instance of AkeneoLib\Entity\Product echo $product->getIdentifier(); }
Working with Fluent Collections
The all() method returns a FluentAdapterResult that supports lazy-evaluated collection operations:
use AkeneoLib\Search\QueryParameter; // Chain operations - only processes items as needed $adapter->all() ->filter(fn($product) => $product->isEnabled()) ->map(fn($product) => $product->getIdentifier()) ->take(100) ->toArray(); // Pagination $page2 = $adapter->all() ->skip(50) ->take(50) ->toArray(); // Execute side effects while maintaining chain ability $adapter->all() ->each(fn($product) => logger()->info("Processing {$product->getIdentifier()}")) ->filter(fn($product) => $product->getFamily() === 'electronics') ->toArray(); // Terminal operations $firstEnabled = $adapter->all()->first(fn($p) => $p->getEnabled()); $lastProduct = $adapter->all()->last(); // Practical reduce example - collect all identifiers $identifiers = $adapter->all()->reduce( fn($acc, $product) => [...$acc, $product->getIdentifier()], [] );
Available Methods
Lazy Operations (maintain lazy evaluation):
filter(callable $callback)- Filter itemsmap(callable $callback)- Transform itemseach(callable $callback)- Execute side effectstake(int $limit)- Limit to first N itemsskip(int $count)- Skip first N itemschunk(int $size)- Split into chunks
Terminal Operations (materialize the collection):
toArray()- Convert to arrayfirst(?callable $callback = null)- Get first itemlast(?callable $callback = null)- Get last itemreduce(callable $callback, $initial)- Reduce to single valuesort(callable $callback)- Sort items (⚠️ loads all into memory)unique(?callable $callback = null)- Filter duplicates (⚠️ loads all into memory)
Note: Operations marked with ⚠️ materialize the entire collection into memory. Use with caution on large datasets from API cursors.
Upsert Products in Batches
$product = new AkeneoLib\Entity\Product('my-sku'); // ...set properties, values, etc. $adapter->stage($product); // Will push automatically when batch size is reached $adapter->push(); // Manually push any remaining staged products
Custom Response Callback
$adapter->onResponse(function ($response, $products, $dateTime) { // Handle API response or log batch import results here });
Advanced
- Querying: Use
AkeneoLib\Search\QueryParameterto filter, sort, and paginate. - Custom Serialization: Swap out or configure the serializer.
Testing
This library is tested with Pest.
To run tests:
composer install
composer test