qr-code-bundle icon indicating copy to clipboard operation
qr-code-bundle copied to clipboard

Suggestion: Support Symfony's PHP configuration

Open ThomasLandauer opened this issue 5 years ago • 1 comments

Symfony is moving from YAML configuration to PHP, see https://github.com/symfony/symfony/issues/37186

With this being my config/routes/endroid_qr_code.php:

<?php declare(strict_types=1);

use function Symfony\Component\DependencyInjection\Loader\Configurator\ref;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routingConfigurator): void {
    $routingConfigurator->import(ref('EndroidQrCodeBundle/Resources/config/routes.yaml'))
        ->prefix('/qr-code');
};

... I'm getting this error:

Cannot load resource "EndroidQrCodeBundle/Resources/config/routes.yaml".

So it looks like this file is blocking it: https://github.com/endroid/qr-code-bundle/blob/master/src/Resources/config/routes.yaml

Suggestion: Provide an alternative src/Resources/config/routes.php

ThomasLandauer avatar Oct 13 '20 20:10 ThomasLandauer

This works for me:

// /config/routes/endroid_qr_code.php
<?php

declare(strict_types=1);

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes): void {
    $routes = $routes->collection('endroid_qr_code_')->prefix('qr-code');
    $routes->add('qr_code_generate', '/{text}.{extension}')
        ->controller('Endroid\QrCodeBundle\Controller\GenerateController')
        ->requirements([
            'text' => '[\\w\\W]+'
        ]);
};

Locally the \\w\\W regex does not stop &,,,.png, and it is able to generate a QR code for it. That's why I use 'text' => '[a-zA-Z0-9.-]+', which does enforce a more strict set of characters to use.

belgianguy avatar Nov 16 '20 18:11 belgianguy

I'm closing this as I decided to keep the .yaml as the default.

endroid avatar Oct 04 '22 14:10 endroid