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

Web Profiler Extra Bundle Laravel Package

elao/web-profiler-extra-bundle

Symfony Web Profiler add-on that adds extra panels for Routing, Service Container, Twig (extensions/tests/filters/functions), and Assetic. Enable per collector and optionally show in the web debug toolbar; intended for dev/test environments.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer (if not already included in a legacy Symfony/Laravel project):

    composer require elao/web-profiler-extra-bundle
    

    Register the bundle in config/app.php (Symfony) or via a service provider (Laravel bridge if applicable):

    // Symfony (app/AppKernel.php)
    new Elao\WebProfilerExtraBundle\ElaoWebProfilerExtraBundle(),
    
  2. Enable in Dev Environment Ensure APP_DEBUG=true in .env (or equivalent) and clear cache:

    php artisan cache:clear  # Laravel
    php app/console cache:clear  # Symfony
    
  3. First Use Case

    • Visit any route in development. The Symfony Profiler toolbar will now include additional tabs:
      • Routing (request/response details, matched routes, parameters).
      • Container (service container dumps, including Laravel’s bindings).
      • Assetic/Twig (asset compilation, template rendering stats).
    • Click the "WebProfilerExtra" tab to inspect these sections.

Implementation Patterns

1. Debugging Routes

  • Inspect Matched Routes: Use the Routing tab to verify route resolution, parameters, and middleware execution.

    // Example: Debug a route with dynamic parameters
    Route::get('/user/{id}', [UserController::class, 'show']);
    
    • Profiler shows:
      • Matched route name (user.show).
      • Resolved parameters (id => 42).
      • Middleware stack (e.g., auth, throttle).
  • Reverse Route Dumping: Dump all registered routes to a file for documentation:

    use Symfony\Component\Routing\RouterInterface;
    
    $routes = $this->container->get(RouterInterface::class)->getRouteCollection();
    file_put_contents(storage_path('logs/routes.php'), print_r($routes->all(), true));
    

2. Container Inspection

  • Service Binding Debugging: Use the Container tab to:

    • Verify service bindings (e.g., App\Services\UserService).
    • Check for circular dependencies or missing bindings.
    • Inspect Laravel’s service container aliases:
      $this->app->bind('user.service', UserService::class);
      
    • Profiler shows:
      • Bound services with their concrete classes.
      • Singleton/scoped bindings.
  • Temporary Overrides: Override a service in development for testing:

    $this->app->instance('user.service', new MockUserService());
    
    • Verify the override appears in the Container tab.

3. Asset/Twig Profiling

  • Assetic Debugging:

    • Check if assets are compiled correctly (e.g., CSS/JS bundles).
    • Identify missing files or compilation errors.
    • Compare expected vs. actual file sizes.
  • Twig Template Inspection:

    • View template hierarchy (parent/extends blocks).
    • Debug template variables and rendering time.
    • Spot syntax errors or missing translations.

4. Integration with Laravel

  • Laravel-Specific Workflows:

    • Route Caching: Disable route caching in config/app.php to see real-time route resolution:
      'route.cache' => env('APP_DEBUG') ? false : true,
      
    • Service Container: Use the Container tab to debug Laravel’s service providers and bindings.
    • Blade vs. Twig: Note: This bundle is Symfony-focused. For Blade debugging, use Laravel’s built-in tools (php artisan view:clear or dd()).
  • Custom Profiler Data: Extend the profiler with custom data (Symfony-only):

    use Symfony\Component\HttpKernel\DataCollector\DataCollector;
    
    class CustomDataCollector extends DataCollector {
        public function collect(Request $request, Response $response, \Exception $exception = null) {
            $this->data['custom_key'] = 'value';
        }
    }
    

    Register it in config/packages/elao_web_profiler_extra.yaml:

    elao_web_profiler_extra:
        collectors:
            - App\CustomDataCollector
    

Gotchas and Tips

Pitfalls

  1. Archived Package:

    • Last release in 2019. May not work with modern Symfony/Laravel versions (test thoroughly).
    • Check for forks or alternatives (e.g., Symfony’s built-in profiler).
  2. Laravel Compatibility:

    • Primarily designed for Symfony. Use with Laravel via:
      • Symfony Bridge (e.g., symfony/http-kernel-bundle).
      • Manual integration (e.g., middleware to trigger profiler).
    • Workaround: Use Laravel’s dd() or dump() for quick debugging if integration fails.
  3. Performance Overhead:

    • Profiler adds ~10-50ms per request. Disable in production:
      if (app()->environment('production')) {
          $this->app->register(\Elao\WebProfilerExtraBundle\ElaoWebProfilerExtraBundle::class);
      }
      
  4. Container Tab Limitations:

    • Shows Symfony container by default. For Laravel, manually bind a wrapper:
      $this->app->instance('symfony.container', new class {
          public function get($id) { return app($id); }
      });
      
  5. Assetic/Twig Gaps:

    • Assetic: Requires symfony/assetic-bundle. For Laravel Mix/Vite, use browser dev tools.
    • Twig: Only works if using symfony/twig-bundle. For Blade, use php artisan view:dump or Xdebug.

Debugging Tips

  1. Route Not Showing?

    • Ensure APP_DEBUG=true and cache is cleared.
    • Check for route caching (php artisan route:clear).
  2. Container Empty?

    • Verify the bundle is registered after Laravel’s providers.
    • For Laravel, bind a Symfony container adapter:
      $this->app->singleton('symfony.container', function () {
          return new class {
              public function get($id) { return app($id); }
          };
      });
      
  3. Twig/Assetic Data Missing?

    • Install required bundles:
      composer require symfony/twig-bundle symfony/assetic-bundle
      
    • For Laravel, use symfony/twig-bridge:
      composer require symfony/twig-bridge
      
  4. Custom Data Not Appearing?

    • Ensure the collector implements DataCollectorInterface.
    • Register it in config/packages/elao_web_profiler_extra.yaml:
      elao_web_profiler_extra:
          collectors:
              - App\CustomCollector
      

Extension Points

  1. Add Custom Tabs: Create a new collector (Symfony):

    namespace App\DataCollector;
    
    use Symfony\Component\HttpKernel\DataCollector\DataCollector;
    
    class ApiCollector extends DataCollector {
        public function collect(Request $request, Response $response, \Exception $exception = null) {
            $this->data['api_calls'] = $request->headers->get('X-API-Calls');
        }
    
        public function getName() { return 'api'; }
    }
    

    Register in config/packages/elao_web_profiler_extra.yaml:

    elao_web_profiler_extra:
        collectors:
            - App\DataCollector\ApiCollector
    
  2. Override Existing Data: Extend core collectors (e.g., RoutingDataCollector) to add custom logic:

    use Elao\WebProfilerExtraBundle\DataCollector\RoutingDataCollector;
    
    class CustomRoutingCollector extends RoutingDataCollector {
        protected function collect(Request $request) {
            parent::collect($request);
            $this->data['custom_route_data'] = 'value';
        }
    }
    

    Bind it in a service provider:

    $this->app->extend('data_collector.routing', function () {
        return new CustomRoutingCollector();
    });
    
  3. Laravel Middleware Integration: Trigger profiler manually for specific routes:

    use Elao\WebProfilerExtraBundle\Profiler;
    
    class DebugMiddleware {
        public function handle($request, Closure $next) {
            if (app()->bound('profiler')) {
                app('profiler')->collect($request);
            }
            return $next($request);
        }
    }
    
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.
bugban/symfony
beyonder-capi/workflow-extensions-bundle
beyonder-capi/job-queue-bundle
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
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