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

Extra Param Converter Bundle Laravel Package

bu/extra-param-converter-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require bu/extra-param-converter-bundle dev-master
    

    Ensure SensioFrameworkExtraBundle is installed and enabled (sensio_framework_extra.request.converters: true in config).

  2. Register Bundle: Add to AppKernel.php:

    new Bu\ExtraParamConverterBundle\BuExtraParamConverterBundle(),
    
  3. First Use Case: Convert a GET parameter (?id=1) to an entity in a controller:

    use App\Entity\User;
    
    public function showAction(User $user) { ... }
    

    The bundle auto-resolves User from the id GET parameter.


Implementation Patterns

GET Parameter Conversion

  • Simple Types: Automatically converts ?name=John to $name = "John".
  • Entities: Resolves ?user=123 to User entity via find() (throws NotFoundHttpException if missing).
  • Collections: Supports ?users[]=1&users[]=2Collection<User> (requires Doctrine\Common\Collections\Collection type-hint).

Example:

public function listAction(Collection $users) { ... } // Converts ?users[]=1&users[]=2

POST/JSON Conversion

  • Form Data: Converts POST arrays to entities (e.g., User from POST['name']).
  • JSON Payloads: Decodes application/json requests into objects/arrays.
    public function createAction(User $user) { ... } // $user populated from JSON POST body
    

Integration Tips

  1. Custom Converters: Extend Bu\ExtraParamConverterBundle\Converter\ConverterInterface for domain-specific logic.
  2. Validation: Pair with Symfony Validator for POST data:
    use Symfony\Component\Validator\Constraints as Assert;
    
    public function updateAction(
        #[Assert\Type(type: User::class)]
        User $user
    ) { ... }
    
  3. Nested Objects: Works with nested JSON (e.g., POST['address']Address entity).

Gotchas and Tips

Pitfalls

  1. Missing SensioFrameworkExtraBundle:

    • Error: No converter found for argument.
    • Fix: Ensure sensio_framework_extra.request.converters: true in config.yml.
  2. Entity Not Found:

    • Throws NotFoundHttpException for missing entities (e.g., ?user=999999).
    • Debug: Check UserRepository::find() logic.
  3. JSON Parsing:

    • Fails silently if Content-Type: application/json is missing.
    • Fix: Add #[ParamConverter("json")] annotation or ensure headers are set.

Debugging

  • Enable Debug Mode: Symfony’s debug:router or debug:container to inspect converters.
  • Log Converter Events: Override Bu\ExtraParamConverterBundle\EventListener\ParamConverterListener to log conversions.

Extension Points

  1. Custom Naming Strategies: Override Bu\ExtraParamConverterBundle\Converter\GetConverter to change how parameters map to entity methods (e.g., ?username=johnfindByUsername()).

  2. Strip Tags: Enable HTML stripping for GET/POST via config:

    bu_extra_param_converter:
        strip_tags: true
    
  3. Performance: Cache entity lookups for high-traffic endpoints (e.g., find() with @Cache in Doctrine).

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