johnkrovitch/orm-pack
Composer metapackage that bundles common Symfony/Doctrine ORM dependencies, including symfony/orm-pack, Pagerfanta adapters, and Doctrine Extensions (Gedmo + Stof bundle). Use it to standardize and mutualize ORM-related requirements across projects.
Installation:
composer require johnkrovitch/orm-pack
Add to composer.json under require-dev if only for testing:
"require-dev": {
"johnkrovitch/orm-pack": "^3.0"
}
First Use Case:
doctrine/orm, eloquent, cycle/orm) with a single johnkrovitch/orm-pack dependency.composer require pagerfanta/twig
eloquent in composer.json:
"require": {
"-illuminate/database": "*",
"johnkrovitch/orm-pack": "^3.0",
"pagerfanta/twig": "^3.0" # Optional, if using Twig
}
composer update.Verify:
vendor/composer/installed.json to confirm mutualized dependencies.{% pagerfanta results %}
Dependency Replacement:
doctrine/orm, eloquent, cycle/orm, yii2, cakephp/orm) with johnkrovitch/orm-pack.composer why-not to identify conflicts before replacement.Version Alignment:
composer.json of the pack for version constraints:
"extra": {
"orm-pack": {
"doctrine/orm": "2.10.*",
"eloquent": "8.0",
"pagerfanta/twig": "3.0"
}
}
Integration with Laravel:
illuminate/database and add the pack.config/database.php to use the mutualized ORM (e.g., Eloquent) as usual.config/app.php:
'providers' => [
JohnKrovitch\OrmPack\Providers\OrmServiceProvider::class,
JohnKrovitch\OrmPack\Providers\PagerfantaTwigProvider::class, // New
],
'aliases' => [
'pagerfanta.twig' => JohnKrovitch\OrmPack\Twig\PagerfantaExtension::class, // New
],
Multi-ORM Projects with Pagination:
// config/orm.php
'default' => env('ORM_DRIVER', 'eloquent'),
'drivers' => [
'eloquent' => \JohnKrovitch\OrmPack\Eloquent\Manager::class,
'doctrine' => \JohnKrovitch\OrmPack\Doctrine\Manager::class,
],
'pagination' => [
'enabled' => true,
'adapter' => \Pagerfanta\Adapter\DoctrineORMAdapter::class, // Example for Doctrine
],
Testing:
composer test
phpunit --filter=PagerfantaTest
Version Conflicts:
johnkrovitch/orm-pack's composer.json for supported versions before upgrading Laravel/Eloquent.Missing Providers:
spatie/laravel-activitylog) assume direct eloquent or doctrine dependencies.composer require johnkrovitch/orm-pack --with-all-dependencies or manually alias classes.PagerfantaTwigProvider is registered if using Twig pagination.Doctrine Cache Issues:
config/doctrine.php:
'metadata_cache' => 'file://' . storage_path('framework/cache/doctrine'),
'query_cache' => 'array',
Pagerfanta Twig Integration:
pagerfanta/twig package is installed and the provider is registered.PagerfantaTwigProvider to config/app.php and verify Twig templates render pagination correctly.Eloquent Global Scopes:
public function boot()
{
\JohnKrovitch\OrmPack\Eloquent\Model::preventGlobalScopes();
// Re-add your scopes
}
Dependency Tree:
Use composer why johnkrovitch/orm-pack to inspect mutualized dependencies, including Pagerfanta.
Class Loading: Check if classes are loaded from the pack:
composer dump-autoload --optimize --classmap-authoritative
Logging: Enable Doctrine logging to debug queries:
$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
New: Debug Pagerfanta adapter issues:
$adapter = new \Pagerfanta\Adapter\DoctrineORMAdapter($query);
$pagerfanta = new \Pagerfanta\Pagerfanta($adapter);
Twig Pagination Debugging: Ensure Twig templates render Pagerfanta correctly:
{% if pagerfanta is iterable %}
{% for item in pagerfanta %}
{{ item }}
{% endfor %}
{{ pagerfanta|pagerfanta_twig }}
{% endif %}
Custom ORM Support: Extend the pack by adding a new ORM manager:
// app/Providers/OrmPackServiceProvider.php
public function register()
{
$this->app->singleton('orm.cycle', function () {
return new \JohnKrovitch\OrmPack\Cycle\Manager();
});
}
Configuration Overrides:
Override pack configurations via config/orm-pack.php:
'doctrine' => [
'entity_paths' => [
'App\\Entities',
'Vendor\\Entities',
],
],
'pagination' => [
'default_per_page' => 15,
'adapters' => [
'eloquent' => \Pagerfanta\Adapter\DoctrineORMAdapter::class,
'query_builder' => \Pagerfanta\Adapter\DoctrineORMAdapter::class,
],
],
Testing Mutualized Dependencies: Mock the ORM pack in tests:
$this->partialMock(
\JohnKrovitch\OrmPack\Eloquent\Model::class,
['newQuery']
);
New: Test Pagerfanta integration:
$adapter = $this->createMock(\Pagerfanta\Adapter\AdapterInterface::class);
$adapter->method('getItems')->willReturn([1, 2, 3]);
$pagerfanta = new \Pagerfanta\Pagerfanta($adapter);
$this->assertCount(3, $pagerfanta->getCurrentPageResults());
How can I help you explore Laravel packages today?