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 393fec6 commit 61cc3ef
Show file tree
Hide file tree
Showing 45 changed files with 316 additions and 709 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
71 changes: 39 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,29 @@ use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\Label\LabelAlignment;
use Endroid\QrCode\Label\Font\NotoSans;
use Endroid\QrCode\Label\Font\OpenSans;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;

$result = Builder::create()
->writer(new PngWriter())
->writerOptions([])
->data('Custom QR code contents')
->encoding(new Encoding('UTF-8'))
->errorCorrectionLevel(ErrorCorrectionLevel::High)
->size(300)
->margin(10)
->roundBlockSizeMode(RoundBlockSizeMode::Margin)
->logoPath(__DIR__.'/assets/symfony.png')
->logoResizeToWidth(50)
->logoPunchoutBackground(true)
->labelText('This is the label')
->labelFont(new NotoSans(20))
->labelAlignment(LabelAlignment::Center)
->validateResult(false)
->build();
$builder = new Builder(
writer: new PngWriter(),
writerOptions: [],
validateResult: false,
data: 'Custom QR code contents',
encoding: new Encoding('UTF-8'),
errorCorrectionLevel: ErrorCorrectionLevel::High,
size: 300,
margin: 10,
roundBlockSizeMode: RoundBlockSizeMode::Margin,
logoPath: __DIR__.'/assets/symfony.png',
logoResizeToWidth: 50,
logoPunchoutBackground: true,
labelText: 'This is the label',
labelFont: new OpenSans(20),
labelAlignment: LabelAlignment::Center
);

$result = $builder->build();
```

## Usage: without using the builder
Expand All @@ -73,24 +75,29 @@ use Endroid\QrCode\Writer\ValidationException;
$writer = new PngWriter();

// Create QR code
$qrCode = QrCode::create('Life is too short to be generating QR codes')
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(ErrorCorrectionLevel::Low)
->setSize(300)
->setMargin(10)
->setRoundBlockSizeMode(RoundBlockSizeMode::Margin)
->setForegroundColor(new Color(0, 0, 0))
->setBackgroundColor(new Color(255, 255, 255));
$qrCode = new QrCode(
data: 'Life is too short to be generating QR codes',
encoding: new Encoding('UTF-8'),
errorCorrectionLevel: ErrorCorrectionLevel::Low,
size: 300,
margin: 10,
roundBlockSizeMode: RoundBlockSizeMode::Margin,
foregroundColor: new Color(0, 0, 0),
backgroundColor: new Color(255, 255, 255)
);

// Create generic logo
$logo = Logo::create(__DIR__.'/assets/symfony.png')
->setResizeToWidth(50)
->setPunchoutBackground(true)
;
$logo = new Logo(
path: __DIR__.'/assets/symfony.png',
resizeToWidth: 50,
punchoutBackground: true
);

// Create generic label
$label = Label::create('Label')
->setTextColor(new Color(255, 0, 0));
$label = new Label(
text: 'Label',
textColor: new Color(255, 0, 0)
);

$result = $writer->write($qrCode, $logo, $label);

Expand Down
Binary file removed assets/noto_sans.otf
Binary file not shown.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"bacon/bacon-qr-code": "^3.0"
},
"require-dev": {
Expand Down Expand Up @@ -48,7 +48,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "5.x-dev"
"dev-main": "6.x-dev"
}
}
}
4 changes: 2 additions & 2 deletions src/Bacon/ErrorCorrectionLevelConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use BaconQrCode\Common\ErrorCorrectionLevel as BaconErrorCorrectionLevel;
use Endroid\QrCode\ErrorCorrectionLevel;

final class ErrorCorrectionLevelConverter
final readonly class ErrorCorrectionLevelConverter
{
public static function convertToBaconErrorCorrectionLevel(ErrorCorrectionLevel $errorCorrectionLevel): BaconErrorCorrectionLevel
{
return match ($errorCorrectionLevel) {
ErrorCorrectionLevel::Low => BaconErrorCorrectionLevel::valueOf('L'),
ErrorCorrectionLevel::Medium => BaconErrorCorrectionLevel::valueOf('M'),
ErrorCorrectionLevel::Quartile => BaconErrorCorrectionLevel::valueOf('Q'),
ErrorCorrectionLevel::High => BaconErrorCorrectionLevel::valueOf('H')
ErrorCorrectionLevel::High => BaconErrorCorrectionLevel::valueOf('H'),
};
}
}
2 changes: 1 addition & 1 deletion src/Bacon/MatrixFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Endroid\QrCode\Matrix\MatrixInterface;
use Endroid\QrCode\QrCodeInterface;

final class MatrixFactory implements MatrixFactoryInterface
final readonly class MatrixFactory implements MatrixFactoryInterface
{
public function create(QrCodeInterface $qrCode): MatrixInterface
{
Expand Down
Loading

0 comments on commit 61cc3ef

Please sign in to comment.