Skip to content

Commit

Permalink
Merge pull request #64 from 2amigos/develop
Browse files Browse the repository at this point in the history
Develop/master
  • Loading branch information
2amjsouza committed Dec 13, 2023
2 parents 5577f73 + 7180680 commit a8b9041
Show file tree
Hide file tree
Showing 142 changed files with 5,331 additions and 42 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -18,6 +18,15 @@ jobs:
- name: Install dependencies
run: composer install

- name: Install laravel dependencies (testings purpose)
run: (cd ./tests/_laravel && composer install)

- name: Create laravel env file
run: (cd ./tests/_laravel && cp .env.example .env)

- name: Create Laravel Tests app Key
run: (cd ./tests/_laravel && php artisan key:generate)

- name: Run unit tests
run: ./vendor/bin/codecept run --coverage --coverage-xml ./coverage.xml

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,6 +1,6 @@
# yii console command
/yii

/laravel
# phpstorm project files
.idea

Expand Down
5 changes: 5 additions & 0 deletions codeception.dist.yml
Expand Up @@ -17,8 +17,13 @@ modules:
Yii2:
configFile: 'tests/_app/config/test.php'
cleanup: false
Laravel:
root: 'tests/_laravel/'
cleanup: false
coverage:
enabled: true
whitelist:
include:
- src/*
exclude:
- src/Providers/*
12 changes: 10 additions & 2 deletions composer.json
Expand Up @@ -36,7 +36,8 @@
"ext-gd": "*",
"ext-simplexml": "*",
"bacon/bacon-qr-code": "^2.0",
"khanamiryan/qrcode-detector-decoder": "^1.0"
"khanamiryan/qrcode-detector-decoder": "^1.0",
"marc-mabe/php-enum": "^4.7"
},
"require-dev": {
"roave/security-advisories": "dev-master",
Expand All @@ -50,7 +51,9 @@
"yiisoft/yii2": "^2.0",
"codeception/module-filesystem": "^1.0",
"codeception/module-yii2": "^1.0",
"codeception/module-asserts": "^1.1"
"codeception/module-asserts": "2.0.1",
"codeception/module-laravel": "^2.1",
"laravel/framework": "^8.83"
},
"autoload": {
"psr-4": {
Expand All @@ -60,6 +63,11 @@
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"laravel": {
"providers": [
"Da\\QrCode\\Providers\\QrCodeServiceProvider"
]
}
},
"config": {
Expand Down
108 changes: 108 additions & 0 deletions config/2am-qrcode.php
@@ -0,0 +1,108 @@

<?php
return [

/*
|--------------------------------------------------------------------------
| Component Prefix
|--------------------------------------------------------------------------
|
| Defines the prefix for the component
|
*/
'prefix' => '2am',

/*
|--------------------------------------------------------------------------
| QR Code Size
|--------------------------------------------------------------------------
|
| Defines the default size for the generated qrcode.
|
*/
'size' => 300,

/*
|--------------------------------------------------------------------------
| QR Code Margin
|--------------------------------------------------------------------------
|
| Defines the default margin for the generated qrcode.
|
*/
'margin' => 15,

/*
|--------------------------------------------------------------------------
| QR Code Logo
|--------------------------------------------------------------------------
|
| Defines the default logo path for the generated qrcode.
| A full path should be provided.
| By default, the logo image will be resized to be square shaped, you can change this
| behavior by setting scaleLogoHeight to true
|
*/
'logoPath' => null,

/*
|--------------------------------------------------------------------------
| QR Scale Logo Height
|--------------------------------------------------------------------------
|
*/
'scaleLogoHeight' => false,

/*
|--------------------------------------------------------------------------
| QR Logo Size
|--------------------------------------------------------------------------
|
| Defines the default logo size for the generated qrcode.
| The suggested size is the 16% of the QR Code width
|
*/
'logoSize' => null,

/*
|--------------------------------------------------------------------------
| QR Code Size
|--------------------------------------------------------------------------
|
| Defines the default size for the generated qrcode.
|
*/
'background' => [
'r' => 255,
'g' => 255,
'b' => 255,
],

/*
|--------------------------------------------------------------------------
| QR Code Size
|--------------------------------------------------------------------------
|
| Defines the default size for the generated qrcode.
|
*/
'foreground' => [
'r' => 0,
'g' => 0,
'b' => 0,
'a' => 100,
],

/*
* ------------------------------------------------------------------------
* QR Code Label Style
*
* Defines the default style for the QR Code label style
* ------------------------------------------------------------------------
*/
'label' => [
'fontPath' => null,
'size' => 16,
'align' => \Da\QrCode\Enums\Label::ALIGN_CENTER,
]
];
28 changes: 24 additions & 4 deletions docs/index.md
Expand Up @@ -15,9 +15,15 @@ it uses a modified version of its code for the writers included on this package.

## Getting Started

### Supported PHP Versions
| Tag | PHP Version |
| :---: |:----------:|
| ^ 3.0.2 | 7.3 - 8.0 |
| 3.1.0 | 7.4 - 8.1 |

### Server Requirements

- PHP >= 7.3
- PHP >= 7.4
- Imagick
- GD
- FreeType
Expand All @@ -27,12 +33,15 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```
php composer.phar require 2amigos/qrcode-library:^3
php composer.phar require 2amigos/qrcode-library:^3.1.0
```
or add

```json
"2amigos/qrcode-library": "^3"
{
...
"2amigos/qrcode-library": "^3.1.0"
}
```

### Usage
Expand Down Expand Up @@ -72,11 +81,13 @@ You can set the foreground color, defining RGBA values, where the alpha is optio
$qrCode = (new QrCode('This is my text'))
->setForeground(0, 0, 0);

// or, setting alpha too
// or, setting alpha as well
$qrCode = (new QrCode('This is my text'))
->setForeground(0, 0, 0, 50);
```

### Formats

In order to ease the task to write different formats into a QrCode, the library comes with a set of classes. These are:

- [BookmarkFormat](formats/bookmark.md)
Expand All @@ -93,6 +104,15 @@ In order to ease the task to write different formats into a QrCode, the library
- [WifiFormat](formats/wifi.md)
- [YoutubeFormat](formats/youtube.md)

Laravel
----

This library bundles a blade component and a file route to easily work with the Laravel framework.

- [LaravelBladeComponent](laravel/blade-component.md)
- [File Route](laravel/file-route.md)
- [Customization](laravel/customization.md)

Yii2
----

Expand Down
89 changes: 89 additions & 0 deletions docs/laravel/blade-component.md
@@ -0,0 +1,89 @@
Laravel Blade Component
----

This library realeases a blade component to make it easy to build qrcode with the Laravel Framework.

Before get started, make sure you have the class `\Da\QrCode\Providers\QrCodeServiceProvider::class`
listed on you config/app.php file, on providers section.

```php
[
...
'providers' => [
...
\Da\QrCode\Providers\QrCodeServiceProvider::class,
],
];
```

With the provider set, we can create a qrcode using the `2am-qrcode` blade component.
It has only `content` as a required field.

```html
<x-2am-qrcode :content="'2am. Technologies'"/>
```

We can also define the qrcode [format](../index.md#Formats). To do so,
you must specify the `format` attribute with a constant from `\Da\QrCode\Enum\Format` and the `content` as an array,
fulfilling the data for the designed format as specified in the format [docs]((../index.md#Formats)).

To work with colors (background, foreground and gradient foreground), you set
the attributes `background`, `foregroud` and `foreground2` (for gradient foreground) as an array
having the keys `r`, `g`, `b` (and `a` to set alpha on foreground, but it's optional).

```php
$background = [
'r' => 200,
'g' => 200,
'b' => 200,
];

$foreground = [
'r' => 0,
'b' => 255,
'g' => 0,
];

$foreground2 = [
'r' => 0,
'b' => 0,
'g' => 255,
];

$content = [
'title' => '2am. Technologies',
'url' => 'https://2am.tech',
];
```

```html
<x-2am-qrcode
:content="$content"
:format="\Da\QrCode\Enums\Format::BOOK_MARK"
:background="$background"
:foreground="$foreground"
:foreground2="$foreground2"
/>
```

All blade component attributes:

| Attribute | Description | Data Type |
|:---------:|:--------------------------------------------------------------------------:|:----------------------------------------------:|
| content | Defines the qrcode's data | string; array |
| format | Defines the qrcode's format | \Da\QrCode\Enum\Format |
| foreground | Defines the qrcode`s foreground base color | array (r, g, b, a) |
| background | Defines the qrcode's background color | array (r, g, b, a) |
| foreground2 | Defines the qrcode's foreground end color (turns to gradient) | array (r, g, b, a) |
| pathStyle | Defines the qrcode's path style | \Da\QrCode\Enum\Path |
| intensity | Defines the path style intensity | float, from 0.1 to 1 |
| margin | Defines the qrcode's margin | int |
| size | Defines the qrcode's size | int |
| logoPath | Set a image to be displayed in the qrcode's center | string; it should be full path |
| logoSize | Set the qrcode's logo size. | int. Recomended size is 16% from qrcode's size |
| scaleLogoHeight | Set if the logo's image should be scaled instead of croped to square shape | bool. Default is false |
| gradientType | Defines the gradient type | \Da\QrCode\Enums\Gradient |
| label | Defines the qrcode's label | string |
| font | Defines the label font | string. It should be full path |
| fontSize | Defines the label font size | int |
| fontAlign | Defines the label alignment | \Da\QrCode\Label |
18 changes: 18 additions & 0 deletions docs/laravel/customization.md
@@ -0,0 +1,18 @@
Laravel Blade Component
----

You can publish the qrcode's config file by executing the given command:

```bash
$ php artisan vendor:publish --tag=2am-qrcode-config
```

This will create a file name 2am-qrcode.php under your config folder, where you can
set the default look of your qrcode and the component prefix.

By the next command, you can publish the component related view, enabling you to perform your
own customization to component structure.

```bash
$ php artisan vendor:publish --tag=2am-qrcode-views
```

0 comments on commit a8b9041

Please sign in to comment.