Skip to content

Commit

Permalink
Major refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Nov 30, 2017
1 parent a9a57ab commit d34057a
Show file tree
Hide file tree
Showing 40 changed files with 254 additions and 1,317 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/bin
/composer.lock
/composer.phar
/phpunit.xml
/vendor
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2

matrix:
fast_finish: true

before_install:
- phpenv config-rm xdebug.ini
- composer self-update && composer install --no-interaction
- composer install --no-interaction

script: bin/phpunit
script: vendor/bin/phpunit

notifications:
email: [email protected]
117 changes: 31 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ QR Code
[![Monthly Downloads](http://img.shields.io/packagist/dm/endroid/qrcode.svg)](https://packagist.org/packages/endroid/qrcode)
[![License](http://img.shields.io/packagist/l/endroid/qrcode.svg)](https://packagist.org/packages/endroid/qrcode)

This library helps you generate QR codes in an easy way and provides a Symfony
bundle for rapid integration in your project.
This library helps you generate QR codes in a jiffy.

## Installation

Expand Down Expand Up @@ -44,18 +43,16 @@ $qrCode = new QrCode('Life is too short to be generating QR codes');
$qrCode->setSize(300);

// Set advanced options
$qrCode
->setWriterByName('png')
->setMargin(10)
->setEncoding('UTF-8')
->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH)
->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0])
->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255])
->setLabel('Scan the code', 16, __DIR__.'/../assets/noto_sans.otf', LabelAlignment::CENTER)
->setLogoPath(__DIR__.'/../assets/symfony.png')
->setLogoWidth(150)
->setValidateResult(false)
;
$qrCode->setWriterByName('png');
$qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
$qrCode->setLabel('Scan the code', 16, __DIR__.'/../assets/fonts/noto_sans.otf', LabelAlignment::CENTER);
$qrCode->setLogoPath(__DIR__.'/../assets/images/symfony.png');
$qrCode->setLogoWidth(150);
$qrCode->setValidateResult(false);

// Directly output the QR code
header('Content-Type: '.$qrCode->getContentType());
Expand All @@ -68,84 +65,32 @@ $qrCode->writeFile(__DIR__.'/qrcode.png');
$response = new Response($qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]);
```

![QR Code](http://endroid.nl/qrcode/Dit%20is%20een%20test.png)
![QR Code](https://endroid.nl/qrcode/Life%20is%20too%20short%20to%20be%20generating%20QR%20codes.png)

## Symfony integration

When you use Symfony Flex, the bundle is automatically registered and the
configuration and routes are automatically created when you installed the
package. In other scenarios you can register the bundle as follows.

```php
// app/AppKernel.php

public function registerBundles()
{
$bundles = [
// ...
new Endroid\QrCode\Bundle\QrCodeBundle\EndroidQrCodeBundle(),
];
}
```

The bundle makes use of a factory to create QR codes. The default parameters
applied by the factory can optionally be overridden via the configuration.

```yaml
endroid_qr_code:
writer: 'png'
size: 300
margin: 10
foreground_color: { r: 0, g: 0, b: 0 }
background_color: { r: 255, g: 255, b: 255 }
error_correction_level: low # low, medium, quartile or high
encoding: UTF-8
label: Scan the code
label_font_size: 20
label_alignment: left # left, center or right
label_margin: { b: 20 }
logo_path: '%kernel.root_dir%/../vendor/endroid/qrcode/assets/symfony.png'
logo_width: 150
validate_result: false # checks if the result is readable
```
## Built-in validation reader

You can enable the built-in validation reader (disabled by default) by calling
setValidateResult(true). This validation reader does not guarantee that the QR
code will be readable by all readers but it helps you provide a minimum level
of quality.

The readability of a QR code is primarily determined by the size, the input
length, the error correction level and any possible logo over the image. The
`validate_result` option uses a built-in reader to validate the resulting
image. This does not guarantee that the code will be readable by all readers
but this helps you provide a minimum level of quality. Take note that the
validator can consume quite an amount of resources and is disabled by default.
length, the error correction level and any possible logo over the image so you
can tweak these parameters if you are looking for optimal results. Take note
that the validator can consume quite amount of additional resources.

Now you can retrieve the factory from the service container and create a QR
code. For instance in your controller this would look like this.

```php
$qrCode = $this->get('endroid.qrcode.factory')->create('QR Code', ['size' => 200]);
```

Add the following section to your routing to be able to handle QR code URLs.
This step can be skipped if you only use data URIs to display your images.

``` yml
EndroidQrCodeBundle:
resource: "@EndroidQrCodeBundle/Resources/config/routing.yml"
prefix: /qrcode
```

After installation and configuration, QR codes can be generated by appending
the QR code text to the url followed by any of the supported extensions.

## Twig extension
## Symfony integration

The bundle provides a Twig extension for generating a QR code URL, path or data
URI. You can use the second argument of any of these functions to override any
defaults defined by the bundle or set via your configuration.
The [endroid/qrcode-bundle](https://github.com/endroid/EndroidQrCodeBundle)
integrates the QR code library in Symfony for an even better experience.

``` twig
<img src="{{ qrcode_path(message) }}" />
<img src="{{ qrcode_url(message, { writer: 'eps' }) }}" />
<img src="{{ qrcode_data_uri(message, { writer: 'svg', size: 150 }) }}" />
```
* Configure your defaults (like image size, default writer etc.)
* Generate QR codes quickly from anywhere via the factory service
* Generate QR codes directly by typing an URL like /qrcode/\<text>.png?size=300
* Generate QR codes or URLs directly from Twig using dedicated functions

Read the [bundle documentation](https://github.com/endroid/EndroidQrCodeBundle)
for more information.

## Versioning

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
27 changes: 8 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
{
"name": "endroid/qrcode",
"description": "Endroid QR Code",
"keywords": ["endroid", "qrcode", "qr", "code", "bundle", "symfony", "flex"],
"keywords": ["endroid", "qrcode", "qr", "code", "bundle", "php"],
"homepage": "https://github.com/endroid/QrCode",
"type": "symfony-bundle",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Jeroen van den Enden",
"email": "[email protected]",
"homepage": "http://endroid.nl/"
"homepage": "https://endroid.nl/"
}
],
"require": {
"php": ">=5.6",
"php": ">=7.1",
"ext-gd": "*",
"symfony/options-resolver": ">=2.7",
"symfony/options-resolver": "^2.7|^3.0|^4.0",
"bacon/bacon-qr-code": "^1.0.3",
"khanamiryan/qrcode-detector-decoder": "^1.0",
"symfony/property-access": ">=2.7",
"symfony/property-access": "^2.7|^3.0|^4.0",
"myclabs/php-enum": "^1.5"
},
"require-dev": {
"symfony/asset": ">=2.7",
"symfony/browser-kit": ">=2.7",
"symfony/finder": ">=2.7",
"symfony/framework-bundle": ">=2.7",
"symfony/http-kernel": ">=2.7",
"symfony/templating": ">=2.7",
"symfony/twig-bundle": ">=2.7",
"symfony/yaml": ">=2.7",
"phpunit/phpunit": ">=5.7"
"phpunit/phpunit": "^5.7|^6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -42,12 +34,9 @@
"Endroid\\QrCode\\Tests\\": "tests/"
}
},
"config": {
"bin-dir": "bin"
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
"dev-master": "3.x-dev"
}
}
}
5 changes: 1 addition & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/Bundle/app/bootstrap.php" colors="true">
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite>
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<php>
<server name="KERNEL_DIR" value="tests/Bundle/app" />
</php>
</phpunit>
64 changes: 0 additions & 64 deletions src/Bundle/QrCodeBundle/Controller/QrCodeController.php

This file was deleted.

This file was deleted.

Loading

0 comments on commit d34057a

Please sign in to comment.