datafactory/ezobjectwrapperbundle
Installation:
composer require datafactory/ezobjectwrapperbundle
Add to config/bundles.php:
Datafactory\EzObjectWrapperBundle\DatafactoryEzObjectWrapperBundle::class => ['all' => true],
First Use Case: Wrap a content object for easier access to fields:
use Datafactory\EzObjectWrapperBundle\Wrapper\ContentWrapper;
$content = $repository->getContentById($contentId);
$wrapper = new ContentWrapper($content);
// Access fields by name (case-insensitive)
$title = $wrapper->getField('title')->value;
$image = $wrapper->getField('image')->value->getFileUri();
Key Files:
src/Wrapper/ContentWrapper.php (core wrapper logic)src/Wrapper/LocationWrapper.php (location-specific methods)src/Service/EzObjectWrapperService.php (service container integration)// Basic field retrieval
$wrapper->getField('field_identifier')->value;
// With fallback
$wrapper->getField('optional_field')->value ?? 'default';
// Field metadata
$field = $wrapper->getField('field_name');
$field->identifier; // 'field_name'
$field->typeString; // 'ezstring'
$field->isRequired; // bool
$locationWrapper = new LocationWrapper($location);
$parent = $locationWrapper->getParent();
$children = $locationWrapper->getChildren();
// Get path as array of locations
$path = $locationWrapper->getPath();
# services.yaml
services:
App\Service\ContentService:
arguments:
$wrapperService: '@datafactory_ez_object_wrapper.service'
// In your service
public function __construct(
private EzObjectWrapperService $wrapperService
) {}
public function processContent($content) {
$wrapper = $this->wrapperService->wrapContent($content);
// ...
}
Extend for custom field types (e.g., ezrichtext):
use Datafactory\EzObjectWrapperBundle\Wrapper\FieldWrapper;
class RichTextWrapper extends FieldWrapper {
public function getHtml() {
return $this->value->html;
}
}
Register in services.yaml:
services:
Datafactory\EzObjectWrapperBundle\Wrapper\FieldWrapper:
arguments:
$customTypes:
ezrichtext: App\Wrapper\RichTextWrapper
Deprecated eZ Platform 5:
Field Identifier Sensitivity:
$wrapper->getFieldNames(); // List all available field identifiers
Circular References:
ezobjectrelation) may cause infinite loops.$wrapper->setMaxDepth(3); // Limit recursion
Service Container Overhead:
EzObjectWrapperService adds minimal overhead but may conflict with existing eZ services.new ContentWrapper($content)) for performance-critical paths.Enable Debug Mode:
$wrapper->setDebug(true);
// Logs field access to Symfony's logger
Field Validation:
if (!$wrapper->hasField('field_name')) {
throw new \RuntimeException("Field 'field_name' not found");
}
Performance Profiling: Wrap only the fields you need:
$wrapper = new ContentWrapper($content, ['title', 'image']);
Custom Wrappers:
Extend Datafactory\EzObjectWrapperBundle\Wrapper\AbstractWrapper for domain-specific logic.
Field Type Overrides:
Override default field type handlers in services.yaml (see Implementation Patterns).
Event Listeners:
Hook into ezpublish.api.service.content to auto-wrap content in repositories:
// config/services.yaml
App\EventListener\ContentWrapperListener:
tags:
- { name: kernel.event_listener, event: ezpublish.api.service.content.get, method: onContentGet }
Default Field Types:
The bundle ships with basic type handlers (ezstring, ezrichtext, ezimage). Add custom types via DI.
Language Handling: Wrappers default to the current siteaccess language. Override with:
$wrapper = new ContentWrapper($content, [], 'eng-GB');
Legacy eZ Platform:
If using eZ Platform Enterprise, ensure ezpublish-kernel is pinned to ^5.4 to avoid conflicts.
How can I help you explore Laravel packages today?