ezsystems/ezpublish-kernel
eZ Publish Kernel is the core of the eZ Publish/eZ Platform CMS, providing the content repository, field types, search integration, and services for building and extending PHP-based content applications with a modular, API-driven architecture.
## Getting Started
### Minimal Setup
1. **Installation**
Add the package via Composer in your Laravel project (ensure compatibility with v7.5.31):
```bash
composer require ezsystems/ezpublish-kernel:^7.5.31 ezsystems/ezplatform-repository ezsystems/ezplatform-admin-ui
Service Provider
Register the EzSystems\EzPublishKernel\EzPublishKernelServiceProvider in config/app.php under providers:
'providers' => [
// ...
EzSystems\EzPublishKernel\EzPublishKernelServiceProvider::class,
],
Configuration Publish the default config:
php artisan vendor:publish --provider="EzSystems\EzPublishKernel\EzPublishKernelServiceProvider" --tag="config"
Update config/ezpublish-kernel.php with your eZ Platform credentials (e.g., siteaccess, connection).
Note: Verify upload_blocklist in ezpublish-kernel.php if using file uploads, as v7.5.31 adds more PHP file types to the default blocklist.
First Use Case: Fetching Content
Inject the EzSystems\EzPublishKernel\API\Repository\Repository into a Laravel service:
use EzSystems\EzPublishKernel\API\Repository\Repository;
class ContentService {
protected $repository;
public function __construct(Repository $repository) {
$this->repository = $repository;
}
public function getContentById($contentId) {
return $this->repository->getContentService()->loadContent($contentId);
}
}
Content Management
ContentService for create/read/update/delete:
$contentService = $repository->getContentService();
$content = $contentService->createContent($contentType, $parentLocationId);
$contentService->publishVersion($content->versionInfo);
LocationService:
$locationService = $repository->getLocationService();
$location = $locationService->createLocation($parentLocation, $content);
File Upload Security
New in v7.5.31: The default upload_blocklist now includes additional PHP file types (e.g., .phar, .phtml). If customizing uploads:
// Override blocklist in config/ezpublish-kernel.php
'upload_blocklist' => [
'*.php', '*.phar', '*.phtml', // Default extended list
'*.exe', // Additional custom blocks
],
Validate against this list in Laravel middleware or services:
use EzSystems\EzPublishKernel\API\Repository\Values\Content\FieldValue\Asset;
public function validateUpload(Asset $asset) {
$fileExt = strtolower(pathinfo($asset->getFile()->getUri(), PATHINFO_EXTENSION));
$blocked = in_array("*.{$fileExt}", config('ezpublish-kernel.upload_blocklist'));
if ($blocked) {
throw new \Exception("File type blocked: {$fileExt}");
}
}
Search and Filtering
Leveraging SearchService for advanced queries:
$searchService = $repository->getSearchService();
$query = new \eZ\Publish\API\Repository\Values\Content\Query\Query();
$query->query = new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAnd([
new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentId($contentId),
]);
$searchResults = $searchService->findContent($query);
REST API Integration
Use Rest\Client for external API calls (if enabled):
$restClient = $repository->getRestClient();
$response = $restClient->get('/api/ezp/v2/content/full/{contentId}');
$this->app->bind('custom.content.service', function ($app) {
return new CustomContentService($app->make(Repository::class));
});
Route::middleware(['ezpublish.auth'])->group(function () {
Route::get('/admin', 'AdminController@index');
});
ContentPublishedEvent):
Event::listen('ezpublish.content.published', function ($event) {
// Trigger Laravel logic on content publish
});
Siteaccess Configuration
siteaccess in ezpublish-kernel.php can lead to silent failures or unexpected behavior.siteaccess matches your environment (e.g., dev, prod).Caching Quirks
$repository->getCacheManager()->clearAll();
Or use php artisan ezplatform:clear-cache (if the artisan commands are set up).File Upload Restrictions (New in v7.5.31)
.phar, .phtml) may fail silently if not explicitly allowed in upload_blocklist.config/ezpublish-kernel.php:
'upload_blocklist' => [
// Customize as needed (default now includes more PHP types)
],
\Log::warning("Blocked upload attempt: {$fileExt}", ['blocklist' => config('ezpublish-kernel.upload_blocklist')]);
Field Type Mismatches
ezstring vs. string).$fieldValue = $content->getField('title')->value;
$castValue = is_array($fieldValue) ? $fieldValue['value'] : $fieldValue;
Transaction Handling
$repository->beginTransaction();
try {
// Operations
$repository->commit();
} catch (\Exception $e) {
$repository->rollback();
throw $e;
}
debug: true in ezpublish-kernel.php to log API calls.\Log::info('Content loaded:', ['content' => $content->getId()]);
null or NotFoundException when loading content/locations:
try {
$content = $repository->getContentService()->loadContent($contentId);
} catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) {
\Log::warning("Content not found: {$contentId}");
}
\Log::debug("File extension check", ['extension' => $fileExt, 'blocklist' => config('ezpublish-kernel.upload_blocklist')]);
Custom Content Services
Extend EzSystems\EzPublishKernel\API\Repository\Values\Content\Content to add Laravel-specific methods:
class CustomContent extends \EzSystems\EzPublishKernel\API\Repository\Values\Content\Content {
public function getLaravelMetadata() {
return $this->getField('laravel_meta')->value ?? null;
}
}
Bind it in a service provider:
$this->app->bind(\EzSystems\EzPublishKernel\API\Repository\Values\Content\Content::class, CustomContent::class);
Event Subscribers Create Laravel event listeners for eZ Platform events:
class ContentPublishedListener {
public function handle(\EzSystems\EzPublishKernel\Event\ContentPublishedEvent $event) {
// Trigger Laravel notifications, queues, etc.
event(new \App\Events\ContentPublished($event->getContent()));
}
}
How can I help you explore Laravel packages today?