Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/laravel blade component #63

Merged
merged 34 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
db24185
feature/add_blade_component: creating package structure; adding facto…
2amjsouza Oct 27, 2023
7c08913
feature/add_blade_component: creating package structure; adding facto…
2amjsouza Oct 27, 2023
f46a41b
remove require lib dependencies on laravel component
2amjsouza Oct 27, 2023
610ccfc
fix provider autodiscovery
2amjsouza Nov 23, 2023
a6bb94b
setting up codeception/laravel module and laravel package testings
2amjsouza Dec 5, 2023
dff3870
setting up codeception/laravel module and laravel package testings
2amjsouza Dec 5, 2023
946e06c
setting up codeception/laravel module and laravel package testings
2amjsouza Dec 5, 2023
8ce5b7d
adding label accessor to blade component
2amjsouza Dec 5, 2023
420d5aa
adding label to rsource endpoint
2amjsouza Dec 5, 2023
b2f344c
adding default label styles to package config file
2amjsouza Dec 5, 2023
814c4eb
assess unit and functional tests for laravel package
2amjsouza Dec 7, 2023
36ad0ac
normalizing test unicodes
2amjsouza Dec 7, 2023
fdf264b
revert string normalized
2amjsouza Dec 7, 2023
0d42b90
assert equals instead of containing in html
2amjsouza Dec 8, 2023
4c0bbcf
Update BladeComponentCest.php
2amjsouza Dec 8, 2023
0864dd8
using on page instead of route for blade test
2amjsouza Dec 8, 2023
fed1841
adding log to error page
2amjsouza Dec 8, 2023
cbbcaf4
update ci flow
2amjsouza Dec 8, 2023
68f7867
Update ci.yml
2amjsouza Dec 8, 2023
b875a88
Update ci.yml
2amjsouza Dec 8, 2023
833c5d1
normalizing binaries on gradfiet tests, revert debug on blade tes
2amjsouza Dec 8, 2023
1cf57a5
moves gradient test
2amjsouza Dec 8, 2023
3b47b13
recreate test images
2amjsouza Dec 8, 2023
88e58de
fix ci
2amjsouza Dec 8, 2023
2184ebe
fix ci
2amjsouza Dec 8, 2023
572e092
fix ci
2amjsouza Dec 8, 2023
5a1bbee
fixing cs
2amjsouza Dec 8, 2023
0b0402f
fixing cs
2amjsouza Dec 8, 2023
620556e
fixing cs
2amjsouza Dec 8, 2023
7cd9b82
fixing cs
2amjsouza Dec 11, 2023
33b8b92
fixing cs
2amjsouza Dec 11, 2023
50654ea
fixing cs
2amjsouza Dec 11, 2023
dcb2909
updating docs; clearing buffer on file route; fix typo
2amjsouza Dec 12, 2023
a55c18e
cover laravel qrcode factory formats creation
2amjsouza Dec 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yii console command
/yii

/laravel
# phpstorm project files
.idea

Expand Down
5 changes: 5 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
```
Loading