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

Uuid Argument Resolver Bundle Laravel Package

alexlisenkov/uuid-argument-resolver-bundle

View on GitHub
Deep Wiki
Context7

UUID Argument Resolver Bundle

ramsey/uuid argument resolver bundle for Symfony

Coverage Status CI Packagist Downloads PHP Versions

Install

composer require alexlisenkov/uuid-argument-resolver-bundle

Usage

namespace App\Controllers;

use Psr\Http\Message\ResponseInterface;
use Ramsey\Uuid\UuidInterface;

class ResourceController
    /**
     * @Route("/{uuid}", name="show_resource", methods="GET")
     */
    public function show(UuidInterface $resourceUuid, ResourceRepository $resourceRepository): ResponseInterface
    {
        $resource = $resourceRepository->findOneByUuid($resourceUuid);

        if ($resource === null) {
            return new ResourceNotFoundResponse();
        }

        return new ResourceResponse($resource);
    }

Handling invalid uuid

By default, it will respond with 400 Bad Request with body Invalid UUID. But you can configure this by creating a service.

Custom response

Create a factory that creates a Psr\Http\Message\ResponseInterface.

namespace App\Factory;

use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Response;

class InvalidUuidResponseFactory
{
    public static function create(): ResponseInterface
    {
        return new Response(400, [], 'Invalid UUID');
    }
}

Override the alexlisenkov.uuid_argument_resolver_bundle.uuid_invalid_response service with your factory.

alexlisenkov.uuid_argument_resolver_bundle.uuid_invalid_response:
    class: '@Psr\Http\Message\ResponseInterface'
    factory: [ 'App\Factory\InvalidUuidResponseFactory', create ]

Now an invalid UUID will return your response.

Testing

composer test

Contributing

Contributions are welcome.

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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
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