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

Doctrine Mirror Bundle Laravel Package

desarrolla2/doctrine-mirror-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the package via Composer (if available in a private repo or fork):

    composer require desarrolla2/doctrine-mirror-bundle
    

    Note: Since the last release was in 2017, verify compatibility with your Laravel/Doctrine versions (e.g., Doctrine ORM 2.x).

  2. Bundle Registration In config/app.php, add the bundle to the extra.bundles array under framework:

    'framework' => [
        'bundles' => [
            // ...
            Desarrolla2\DoctrineMirrorBundle\Desarrolla2DoctrineMirrorBundle::class,
        ],
    ],
    
  3. Basic Configuration Check config/packages/desarrolla2_doctrine_mirror.yaml (if auto-generated) or define a custom config:

    desarrolla2_doctrine_mirror:
        enabled: true
        mirror_entity: App\Entity\MirrorEntity  # Your custom entity to mirror data
        sync_interval: 3600                     # Sync interval in seconds (e.g., hourly)
    
  4. First Use Case: Mirroring Data Define a Doctrine entity annotated for mirroring (example):

    // src/Entity/MirrorEntity.php
    use Desarrolla2\DoctrineMirrorBundle\Annotation\Mirror;
    
    /**
     * @Mirror(table="original_table", fields={"id", "name", "created_at"})
     */
    class MirrorEntity {}
    

    Run a manual sync via CLI (if supported):

    php bin/console desarrolla2:doctrine-mirror:sync
    

Implementation Patterns

Common Workflows

  1. Entity Mirroring

    • Use the @Mirror annotation to define which tables/fields to mirror.
    • Example: Mirror a User table to a UserArchive table with selective fields.
    /**
     * @Mirror(
     *     table="users",
     *     fields={"id", "email", "status"},
     *     where="deleted_at IS NULL"
     * )
     */
    class UserArchive {}
    
  2. Event-Driven Sync

    • Listen to Doctrine lifecycle events (e.g., postPersist, postUpdate) to trigger mirror updates:
    // src/EventListener/MirrorSyncListener.php
    use Desarrolla2\DoctrineMirrorBundle\Event\MirrorSyncEvent;
    
    class MirrorSyncListener
    {
        public function onMirrorSync(MirrorSyncEvent $event)
        {
            // Custom logic (e.g., log, validate, or transform data)
        }
    }
    

    Register the listener in services.yaml:

    servicios:
        Desarrolla2\DoctrineMirrorBundle\EventListener\MirrorSyncListener:
            tags:
                - { name: doctrine.event_listener, event: postPersist }
    
  3. Scheduled Syncs

    • Use Laravel’s task scheduling (app/Console/Kernel.php) to run periodic syncs:
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('desarrolla2:doctrine-mirror:sync')->hourly();
    }
    
  4. Bulk Operations

    • For large datasets, implement chunked queries to avoid memory issues:
    $em = $this->getEntityManager();
    $query = $em->createQuery('SELECT u FROM App\Entity\User u WHERE u.status = :status')
        ->setParameter('status', 'active');
    $query->setMaxResults(100); // Process in batches
    

Gotchas and Tips

Pitfalls

  1. Doctrine Version Mismatch

    • The bundle was last updated for Doctrine ORM 2.x. Test with your version (e.g., 2.5+).
    • Workaround: Fork the repo and update dependencies if needed.
  2. Annotation Parsing Issues

    • Ensure annotations are loaded by Doctrine’s annotation reader. Add this to config/packages/doctrine.yaml:
      doctrine:
          orm:
              mappings:
                  Desarrolla2DoctrineMirrorBundle:
                      type: annotation
                      dir: "%kernel.project_dir%/vendor/desarrolla2/doctrine-mirror-bundle/Resources/config/doctrine"
                      prefix: 'Desarrolla2\DoctrineMirrorBundle\Entity'
                      alias: Desarrolla2DoctrineMirrorBundle
      
  3. Missing CLI Commands

    • The bundle may lack documented commands. Check src/Command/ for available commands or implement custom ones:
      php bin/console list
      
  4. Performance with Large Tables

    • Mirroring large tables (e.g., >1M rows) may cause timeouts. Optimize with:
      • Database indexes on mirrored fields.
      • Async processing (e.g., Laravel Queues).

Debugging Tips

  1. Enable SQL Logging Add to config/packages/doctrine.yaml:

    doctrine:
        dbal:
            logging: true
            profiling: true
    

    Check logs in var/log/doctrine.log.

  2. Verify Entity Metadata Dump Doctrine metadata to debug mirroring setup:

    $metadata = $em->getMetadataFactory()->getAllMetadata();
    print_r($metadata);
    
  3. Check Event Dispatching Ensure events are fired by adding a debug listener:

    public function onKernelRequest(GetResponseEvent $event)
    {
        \Log::info('Mirror events enabled:', ['events' => $event->getRequest()->attributes->get('_doctrine')]);
    }
    

Extension Points

  1. Custom Mirror Strategies Override the default mirroring logic by extending the bundle’s services:

    # config/services.yaml
    servicios:
        Desarrolla2\DoctrineMirrorBundle\Service\MirrorService:
            class: App\Service\CustomMirrorService
            arguments:
                - '@doctrine.orm.entity_manager'
    
  2. Add Pre/Post Sync Hooks Extend the MirrorSyncEvent to inject custom logic:

    class CustomMirrorSyncListener
    {
        public function onPreSync(MirrorSyncEvent $event)
        {
            // Pre-sync validation/transformation
        }
    
        public function onPostSync(MirrorSyncEvent $event)
        {
            // Post-sync actions (e.g., send notifications)
        }
    }
    
  3. Support for Soft Deletes If using Gedmo\SoftDeleteable, exclude deleted records in the @Mirror annotation:

    /**
     * @Mirror(where="deletedAt IS NULL")
     */
    
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony