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

Post Process Bundle Laravel Package

as3/post-process-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require as3/post-process-bundle ^1.0
    

    Add the bundle to AppKernel.php:

    new As3\Bundle\PostProcessBundle\As3PostProcessBundle(),
    
  2. First Use Case: Create a simple task to run after response (e.g., logging, analytics, or async processing):

    // src/Task/MyAsyncTask.php
    namespace App\Task;
    
    use As3\Bundle\PostProcessBundle\TaskInterface;
    
    class MyAsyncTask implements TaskInterface {
        public function run() {
            // Example: Send analytics event
            file_put_contents('analytics.log', 'Event triggered', FILE_APPEND);
        }
    }
    
  3. Register the Task:

    # config/services.yaml
    services:
        App\Task\MyAsyncTask:
            tags:
                - { name: as3_post_process.task, priority: 1 }
    

Implementation Patterns

Task-Based Workflows

  • Async Processing: Use tasks for background jobs (e.g., sending emails, updating caches, or triggering webhooks) after the response is sent.

    // Dynamically add a task in a controller
    $manager = $this->get('as3_post_process.task.manager');
    $manager->addTask(new MyAsyncTask(), 1); // Priority 1
    
  • Priority Management: Lower-priority tasks (e.g., analytics) run before higher-priority ones (e.g., critical cleanup). Default priority is 0.

  • Service Integration: Tag services for automatic registration:

    # config/services.yaml
    services:
        App\Task\CacheCleanupTask:
            tags:
                - { name: as3_post_process.task, priority: 10 }
    

Plugin-Based Workflows

  • Response Modification: Use plugins to inject scripts, headers, or modify content before sending the response.

    // src/Plugin/ResponseModifierPlugin.php
    use As3\Bundle\PostProcessBundle\PluginInterface;
    use Symfony\Component\HttpFoundation\Response;
    
    class ResponseModifierPlugin implements PluginInterface {
        public function filterResponse(Response $response) {
            $response->headers->set('X-Custom-Header', 'value');
            return $response;
        }
    }
    
  • Conditional Logic: Plugins can conditionally alter responses (e.g., inject tracking only for specific routes):

    public function filterResponse(Response $response) {
        if ($this->isTrackingEnabled()) {
            $response->setContent($this->injectTracking($response->getContent()));
        }
        return $response;
    }
    
  • Service Registration:

    # config/services.yaml
    services:
        App\Plugin\ResponseModifierPlugin:
            tags:
                - { name: as3_post_process.plugin }
    

Gotchas and Tips

Pitfalls

  1. Symfony 3+ Compatibility: The bundle supports Symfony 3.x but may require adjustments for newer versions (e.g., AppKernelKernel). Test thoroughly.

  2. Task Execution Order: Tasks run in ascending priority order (lower numbers first). Misconfigured priorities can cause delays or race conditions.

  3. Response Modification Side Effects: Plugins modify the response before it’s sent. Avoid heavy operations (e.g., DOM parsing) that could block the HTTP connection.

  4. No Guaranteed Execution: Tasks/plugins may fail silently if exceptions aren’t caught. Wrap logic in try-catch blocks:

    public function run() {
        try {
            // Risky operations
        } catch (\Exception $e) {
            error_log('Task failed: ' . $e->getMessage());
        }
    }
    

Debugging Tips

  • Log Task Execution: Override TaskInterface::run() to log start/end times:

    public function run() {
        \Log::info('Task started: ' . __CLASS__);
        // Task logic
        \Log::info('Task ended: ' . __CLASS__);
    }
    
  • Check Service Tags: Verify tags are correctly defined in services.yaml:

    tags:
        - { name: as3_post_process.task, priority: 5 }  # Correct syntax
    
  • Disable Tasks Temporarily: Comment out service tags to isolate issues:

    # services:
    #     App\Task\MyAsyncTask: ~
    

Extension Points

  1. Custom Task Managers: Extend the bundle’s TaskManager to add features like:

    • Rate limiting.
    • Retry logic for failed tasks.
    class CustomTaskManager extends \As3\Bundle\PostProcessBundle\Task\TaskManager {
        public function addTaskWithRetry(TaskInterface $task, int $priority, int $retries) {
            // Custom logic
        }
    }
    
  2. Plugin Chaining: Combine multiple plugins for layered response modifications:

    services:
        app.plugin.chain:
            class: App\Plugin\ChainPlugin
            arguments: ['@as3_post_process.plugin.manager']
            tags:
                - { name: as3_post_process.plugin }
    
  3. Event Integration: Trigger tasks/plugins via Symfony events (e.g., kernel.terminate):

    // src/EventListener/TaskListener.php
    use Symfony\Component\HttpKernel\Event\TerminateEvent;
    
    class TaskListener {
        public function onTerminate(TerminateEvent $event) {
            $manager = $this->container->get('as3_post_process.task.manager');
            $manager->addTask(new MyTask(), 1);
        }
    }
    
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor