Skip to content

Commit

Permalink
Update compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Oct 21, 2024
1 parent 74cf5db commit a7605f0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']
php-versions: ['8.2', '8.3', '8.4']
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 (c) Jeroen van den Enden
Copyright 2024 (c) Jeroen van den Enden

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"endroid/installer": "^1.2.2",
"endroid/qr-code": "^5.0",
"endroid/qr-code": "^6.0.1",
"symfony/framework-bundle": "^5.4||^6.4||^7.0",
"symfony/twig-bundle": "^5.4||^6.4||^7.0",
"symfony/yaml": "^5.4||^6.4||^7.0"
Expand All @@ -37,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "4.x-dev"
"dev-main": "5.x-dev"
}
},
"config": {
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/GenerateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
use Endroid\QrCodeBundle\Response\QrCodeResponse;
use Symfony\Component\HttpFoundation\Response;

final class GenerateController
final readonly class GenerateController
{
public function __construct(
private readonly BuilderRegistryInterface $builderRegistry
private BuilderRegistryInterface $builderRegistry,
) {
}

public function __invoke(string $builder, string $data): Response
{
$builder = $this->builderRegistry->getBuilder($builder);
$builder = $this->builderRegistry->get($builder);

if (!$builder instanceof Builder) {
throw new \Exception('This controller only handles Builder instances');
}

return new QrCodeResponse($builder->data($data)->build());
return new QrCodeResponse($builder->build(data: $data));
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

final class Configuration implements ConfigurationInterface
final readonly class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
Expand Down
27 changes: 13 additions & 14 deletions src/DependencyInjection/EndroidQrCodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function load(array $configs, ContainerBuilder $container): void

foreach ($config as $builderName => $builderConfig) {
$builderDefinition = $this->createBuilderDefinition($builderName, $builderConfig, $container);
$registryDefinition->addMethodCall('addBuilder', [$builderName, $builderDefinition]);
$registryDefinition->addMethodCall('set', [$builderName, $builderDefinition]);
}
}

Expand All @@ -55,47 +55,46 @@ private function createBuilderDefinition(string $builderName, array $builderConf

$builderDefinition = new ChildDefinition(BuilderInterface::class);

$options = [];
$arguments = [];
foreach ($builderConfig as $name => $value) {
$name = $this->toCamelCase($name);
switch ($name) {
case 'writer':
$options[$name] = new Reference($value);
$arguments[$name] = new Reference($value);
break;
case 'encoding':
$options[$name] = new Definition(Encoding::class, [$value]);
$arguments[$name] = new Definition(Encoding::class, [$value]);
break;
case 'errorCorrectionLevel':
$options[$name] = ErrorCorrectionLevel::from($value);
$arguments[$name] = ErrorCorrectionLevel::from($value);
break;
case 'roundBlockSizeMode':
$options[$name] = RoundBlockSizeMode::from($value);
$arguments[$name] = RoundBlockSizeMode::from($value);
break;
case 'foregroundColor':
case 'backgroundColor':
case 'labelTextColor':
$options[$name] = new Definition(Color::class, $value);
$arguments[$name] = new Definition(Color::class, $value);
break;
case 'labelFontPath':
$labelFontSize = $builderConfig['labelFontSize'] ?? 16;
$options['labelFont'] = new Definition(Font::class, [$value, $labelFontSize]);
$arguments['labelFont'] = new Definition(Font::class, [$value, $labelFontSize]);
break;
case 'labelFontSize':
$labelFontPath = $builderConfig['labelFontPath'] ?? (new NotoSans())->getPath();
$options['labelFont'] = new Definition(Font::class, [$labelFontPath, $value]);
$arguments['labelFont'] = new Definition(Font::class, [$labelFontPath, $value]);
break;
case 'labelAlignment':
$options[$name] = LabelAlignment::from($value);
$arguments[$name] = LabelAlignment::from($value);
break;
default:
$options[$name] = $value;
$arguments[$name] = $value;
break;
}
}

foreach ($options as $name => $value) {
$builderDefinition->addMethodCall($name, [$value]);
$builderDefinition->setPublic(true);
foreach ($arguments as $name => $value) {
$builderDefinition->setArgument('$'.$name, $value);
}

$container->setDefinition($id, $builderDefinition);
Expand Down
10 changes: 5 additions & 5 deletions src/Twig/QrCodeRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Extension\RuntimeExtensionInterface;

final class QrCodeRuntime implements RuntimeExtensionInterface
final readonly class QrCodeRuntime implements RuntimeExtensionInterface
{
public function __construct(
private readonly BuilderRegistryInterface $builderRegistry,
private readonly UrlGeneratorInterface $urlGenerator
private BuilderRegistryInterface $builderRegistry,
private UrlGeneratorInterface $urlGenerator,
) {
}

Expand Down Expand Up @@ -46,7 +46,7 @@ public function qrCodeDataUriFunction(string $data, string $builder = 'default',
/** @param array<mixed> $options */
public function qrCodeResultFunction(string $data, string $builder = 'default', array $options = []): ResultInterface
{
$builder = $this->builderRegistry->getBuilder($builder);
$builder = $this->builderRegistry->get($builder);

foreach ($options as $option => $value) {
if (!method_exists($builder, $option)) {
Expand All @@ -59,6 +59,6 @@ public function qrCodeResultFunction(string $data, string $builder = 'default',
throw new \Exception('This twig extension only handles Builder instances');
}

return $builder->data($data)->build();
return $builder->build(data: $data);
}
}

0 comments on commit a7605f0

Please sign in to comment.