black/common
Common utilities for Black projects: an abstract Doctrine Manager helper with convenience methods plus simple specification classes (and/or/not). Install via Composer and reuse across apps needing lightweight Doctrine-oriented shared code.
and/or/not) aligns with domain-driven design (DDD) but may feel overkill for simple queries. Conflicts arise if the project already uses Laravel’s repository pattern or API Platform’s query system.DoctrineManager abstract class enforces a repository-like structure, which could duplicate Laravel’s existing service container if not carefully scoped.// Current (Query Builder)
User::where('active', true)->where('role', 'admin');
// Target (DQL via Specifications)
$spec = new AndSpecification(
new FieldEquals('active', true),
new FieldEquals('role', 'admin')
);
$results = $doctrineManager->findBy($spec, User::class);
<2.10). If the project uses Doctrine 3.x, integration may fail without patches.findBy() parameters).bind() examples).<2.10)?Doctrine\ORM\EntityRepository extensions).where() clauses.ApiPlatform\Doctrine\Orm\Filter).@stable):
"require": {
"black/common": "1.0.0" // Replace with actual version
}
composer require doctrine/orm "^2.10"
DoctrineManager:
// app/Providers/BlackCommonServiceProvider.php
namespace App\Providers;
use Black\Common\Doctrine\DoctrineManager;
use Doctrine\ORM\EntityManagerInterface;
use Illuminate\Support\ServiceProvider;
class BlackCommonServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(DoctrineManager::class, function ($app) {
return new class($app[EntityManagerInterface::class]) extends DoctrineManager {};
});
}
}
config/app.php.use Black\Common\Doctrine\Specification\AndSpecification;
use Black\Common\Doctrine\Specification\FieldEquals;
$spec = new AndSpecification(
new FieldEquals('status', 'active'),
new FieldEquals('role', 'admin')
);
$users = app(DoctrineManager::class)->findBy($spec, User::class);
AndSpecification with NotSpecification).doctrine/orm:query-stats).composer why-not black/common
to check constraints. If using Doctrine 3.x, expect breaking changes.DoctrineManager may need updates for Doctrine ORM changes.Specification::toDql()).->toSql()).Specification::debug()).How can I help you explore Laravel packages today?