Skip to content

Commit

Permalink
Create QR code response
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Jan 13, 2018
1 parent c49d5ab commit e7aaa88
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ echo $qrCode->writeString();
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode;
use Symfony\Component\HttpFoundation\Response;
use Endroid\QrCode\Response\QrCodeResponse;

// Create a basic QR code
$qrCode = new QrCode('Life is too short to be generating QR codes');
Expand All @@ -63,7 +63,7 @@ echo $qrCode->writeString();
$qrCode->writeFile(__DIR__.'/qrcode.png');

// Create a response object
$response = new Response($qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]);
$response = new QrCodeResponse($qrCode);
```

![QR Code](https://endroid.nl/qr-code/Life%20is%20too%20short%20to%20be%20generating%20QR%20codes.png)
Expand Down
2 changes: 2 additions & 0 deletions src/QrCodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function getLabelMargin(): ?array;

public function getValidateResult(): bool;

public function getContentType(): string;

public function setWriterRegistry(WriterRegistryInterface $writerRegistry): void;

public function writeString(): string;
Expand Down
21 changes: 21 additions & 0 deletions src/Response/QrCodeResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* (c) Jeroen van den Enden <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Endroid\QrCode\Response;

use Endroid\QrCode\QrCodeInterface;
use Symfony\Component\HttpFoundation\Response;

class QrCodeResponse extends Response
{
public function __construct(QrCodeInterface $qrCode)
{
parent::__construct($qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]);
}
}

0 comments on commit e7aaa88

Please sign in to comment.