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

Subrequestextra Bundle Laravel Package

amp/subrequestextra-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require amp/subrequestextra-bundle:dev-master
    

    Add to AppKernel.php (Symfony 2.x):

    new Amp\SubrequestExtraBundle\AmpSubrequestExtraBundle(),
    

    (Only in dev/test environments.)

  2. Enable Debug Toolbar: Ensure framework.router.request_context.query.string includes ?_debug_toolbar=on or use the toolbar icon in the browser.

  3. First Use Case: Render a subrequest in Twig:

    {% render 'AcmeBundle:Controller:action' %}
    

    Toggle the Subrequests tab in the Web Debug Toolbar to visualize the rendered subrequest.


Implementation Patterns

Core Workflows

  1. Debugging Subrequests:

    • Use the toolbar to inspect nested subrequests (e.g., partials, embedded controllers).
    • Example: Debug a Twig {% render %} call by checking its parameters, execution time, and response.
  2. Ignoring Specific Controllers: Configure amp_subrequest_extra.ignore_controllers in config.yml to exclude non-critical subrequests:

    amp_subrequest_extra:
        ignore_controllers:
            - AcmeBundle:Admin:dashboard  # Exclude admin dashboard subrequests
    
  3. Integration with Custom Templates: Extend Twig templates to include subrequests dynamically:

    {% for item in items %}
        {% render 'AcmeBundle:Item:partial', { item: item } %}
    {% endfor %}
    

    Verify subrequests in the toolbar for each loop iteration.

  4. Performance Profiling: Compare execution times of subrequests to identify bottlenecks. Use the toolbar’s timing metrics.

Advanced Patterns

  • Conditional Rendering: Wrap subrequests in logic to avoid clutter:

    {% if debug %}
        {% render 'AcmeBundle:Debug:metrics' %}
    {% endif %}
    

    Toggle visibility via debug context.

  • Parameter Validation: Pass parameters explicitly to subrequests and validate them in the toolbar:

    {% render 'AcmeBundle:User:profile', { userId: user.id, locale: app.request.locale } %}
    

Gotchas and Tips

Pitfalls

  1. Toolbar Dependency:

    • Subrequests only appear in the toolbar when _debug_toolbar=on is set. Test in dev mode or append ?_debug_toolbar=on to URLs.
  2. Ignored Controllers:

    • Misconfigured ignore_controllers may hide critical subrequests. Verify the exact format (e.g., Bundle:Controller:action).
  3. Empty Responses: Subrequests returning empty responses (e.g., new Response()) may not render in the toolbar. Use {% render %} with non-empty content for visibility.

  4. Symfony 3+/4+ Compatibility:

    • This bundle is Symfony 2.x only. For newer versions, consider alternatives like SensioDebugBundle or custom Profiler extensions.

Debugging Tips

  • Check Subrequest Parameters: The toolbar displays passed parameters. Mismatches (e.g., missing id) can cause silent failures.

  • Template Caching: Clear cache (php bin/console cache:clear) if subrequests disappear after configuration changes.

  • Extension Points: Override the default Twig wrapper by extending the bundle’s template:

    # app/Resources/AmpSubrequestExtraBundle/views/Subrequest/container.html.twig
    {% extends 'AmpSubrequestExtraBundle:Subrequest:container.html.twig' %}
    {% block subrequest_content %}
        {{- parent() -}}
        <div class="custom-metrics">{{ subrequest.metrics }}</div>
    {% endblock %}
    

Performance Quirks

  • Toolbar Overhead: Enabling subrequest debugging adds minor latency. Disable in production (%prod% environments).

  • Memory Usage: Deeply nested subrequests may increase memory usage. Monitor with memory_get_usage().

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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware