contenir / contenir-asset
Asset records, storage, image derivatives and view helpers for laminas-mvc and Mezzio, on contenir-db-model
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
- contenir/contenir-db-model: ^2.0@RC
- laminas/laminas-escaper: ^2.13
- laminas/laminas-permissions-acl: ^2.16
- laminas/laminas-servicemanager: ^3.22 || ^4.0
- laminas/laminas-view: ^2.35
- psr/container: ^1.1 || ^2.0
- psr/log: ^2.0 || ^3.0
Requires (Dev)
- contenir/contenir-qa-tools: 0.1.x-dev
- infection/infection: ^0.34.1
- php-db/phpdb-sqlite: ^0.2.0
- phpunit/phpunit: ^11.5.42
Suggests
- ext-intl: Transliterates accented characters in stored asset file names
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-23 02:08:12 UTC
README
Asset records, file storage, image derivatives and view helpers for
laminas-mvc and Mezzio applications, built on
contenir-db-model 2.x.
The package itself needs no framework: it registers through a
ConfigProvider (Mezzio) or Module (laminas-mvc), and the resize route
for the legacy .WxH scheme comes from the matching adapter,
contenir-asset-laminas-mvc
or contenir-asset-mezzio.
AssetManager. Create, store, update, sequence and delete asset records and their files.- Image derivatives. A large copy and a thumbnail are generated through ImageMagick on upload.
- View helpers:
asset(),assetUrl(),assetSize(),assetAspect()andassetSizes();- the legacy
assetSrcSet(), with its on-demand resizer.
Status: 2.0 pre-release. 2.0 is not compatible with 1.x. See UPGRADE-2.0.md.
Requirements
- PHP 8.3, 8.4 or 8.5
contenir/contenir-db-model2.x and aphp-db/phpdbplatform package- laminas-view 2 (which Mezzio's laminas-view renderer and laminas-mvc both bring)
- ImageMagick (
convert) for image derivatives ext-intl(recommended) for transliterating accented file names
Installation
composer require contenir/contenir-asset:^2.0@RC
The consuming project needs "minimum-stability": "dev" and
"prefer-stable": true until php-db/phpdb 0.6.0 is tagged. With the
laminas component installer the package registers itself: as the
Contenir\Asset module in laminas-mvc, as Contenir\Asset\ConfigProvider
in Mezzio. Add the adapter for your framework to get the legacy resize
route: contenir/contenir-asset-laminas-mvc or
contenir/contenir-asset-mezzio.
At a glance
// Your asset entity: the standard columns come from BaseAssetEntity. #[Table('asset')] final class Asset extends BaseAssetEntity { #[Column('entry_id')] public ?int $entryId = null; } // config/autoload/asset.global.php return ['asset' => ['entity' => Asset::class]]; // In a controller or service: $asset = $assetManager->addAsset($entry, $currentUser); // links entry_id and user_id $assetManager->storeAsset($asset, $entry, 'image', $_FILES['photo'], '1200x800');
<!-- In a view --> <img src="<?= $this->escapeHtmlAttr($this->asset($id)?->imageLg ?? "") ?>" width="<?= $this->assetSize($asset)['width'] ?? '' ?>">
Documentation
- Configuration: every
assetoption and the reference table schema - AssetManager: creating, storing, updating, sequencing and deleting assets
- View helpers:
asset,assetUrl,assetSize,assetAspect,assetSizes - Legacy resizer: the deprecated
.WxHscheme,assetSrcSetand its resize route
Upgrading from 1.x: UPGRADE-2.0.md. Changes:
CHANGELOG.md. llms.txt indexes the docs for
LLM tooling.
Development
Mago is required (brew install mago).
composer install composer check # format check, lint, static analysis, unit + integration tests composer cs-fix composer test # unit suite composer test-integration # SQLite + temporary directory suite (needs gd)
License
BSD-3-Clause. See LICENSE.md.