Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Common Laravel Package

doctrine/common

Doctrine Common extends core PHP with shared utilities used across Doctrine projects. Includes collections, event management, caching helpers, annotations support (legacy), reflection and class loading tools. A foundational component for Doctrine ORM and related libraries.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by requiring the package via Composer:

composer require doctrine/common

Despite its age (last release 2025-01-01 suggests future-dated), doctrine/common is largely stable and backward-compatible — many of its components are now decoupled or rehomed in newer packages (e.g., doctrine/persistence, doctrine/deprecations).
First use case: if you’re building a Doctrine-based application (e.g., ORM or DBAL), you likely already depend on it transitively, but explicitly requiring it allows you to use its foundational utilities (e.g., Doctrine\Common\Collections\Collection) directly.

Implementation Patterns

  • Collection Handling: Use Doctrine\Common\Collections\Collection and Expr for in-memory filtering:
    use Doctrine\Common\Collections\Collection;
    use Doctrine\Common\Collections\Expr\Expr;
    
    $users = new Collection($userArray);
    $activeAdmins = $users->matching(
      Expr::andX(
        Expr::eq('isActive', true),
        Expr::eq('role', 'admin')
      )
    );
    
  • Event Dispatcher: Integrate Doctrine’s event system (via Doctrine\Common\EventManager) to hook into custom lifecycle events:
    $em = new EventManager();
    $em->addEventListener('user.created', new UserWelcomeListener());
    
  • Metadata Mapping: Leverage Doctrine\Common\Annotations\Reader for custom annotation-driven configuration in your own libraries (e.g., command decorators, config attributes).
  • Proxy Generation: While mostly internal, use Proxy\ProxyFactory only when implementing custom object hydration or lazy-loading strategies.

Gotchas and Tips

  • Deprecation & Decoupling: Since ~v2.13, core features have been split:
    • Annotationsdoctrine/annotations
    • Cachedoctrine/cache (deprecated; use PSR-6/PSR-16 instead)
    • Persistencedoctrine/persistence
      Always verify which package you’re actually using — importing from Doctrine\Common for cache/annotations may cause class-not-found errors.
  • Type Safety: Prefer Doctrine\Common\Collections\ArrayCollection over plain arrays for better IDE inference and typehinting (Collection interface).
  • EventListener Signature: The event system uses Doctrine\Common\EventSubscriber — ensure your subscribers implement getSubscribedEvents() and use consistent naming (e.g., onUserPersist, not onUserPersist()).
  • Proxies & Autoloading: Custom proxy generation requires correct autoloading setup — ensure doctrine/persistence is also present for compatibility.
  • Debugging: Enable doctrine/deprecations via handle() to catch subtle breaking changes in underlying Doctrine APIs.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport