Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit eb7a19f

Browse files
committed
Merge branch 'develop' into feature/replaceTravisWithGithubActions
2 parents d5fcc2c + 6d9b738 commit eb7a19f

File tree

11 files changed

+237
-144
lines changed

11 files changed

+237
-144
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ We solely use [Laravel](https://www.laravel.com) for our applications, so this p
1414
| Branch | Status | Coverage | Code Quality |
1515
| ------ | :----: | :------: | :----------: |
1616
| Develop | [![Build Status](https://travis-ci.org/spinen/laravel-formio.svg?branch=develop)](https://travis-ci.org/spinen/laravel-formio) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=develop) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=develop) |
17-
| Master | [![Build Status](https://travis-ci.org/spinen/laravel-formio.svg?branch=master)](https://travis-ci.org/spinen/laravel-formio) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=develop) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=master) |
17+
| Master | [![Build Status](https://travis-ci.org/spinen/laravel-formio.svg?branch=master)](https://travis-ci.org/spinen/laravel-formio) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=master) |
1818

1919
## Installation
2020

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
1.0.0

composer.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
"ext-json": "*",
2424
"firebase/php-jwt": "^5.0",
2525
"guzzlehttp/guzzle": "^6.3",
26-
"illuminate/database": "~5.5|~6",
27-
"illuminate/http": "~5.5|~6",
28-
"illuminate/routing": "~5.5|~6",
29-
"nesbot/carbon": "~1.2|2",
30-
"vlucas/phpdotenv": "^3.6"
26+
"illuminate/database": "~5.5|~6|~7",
27+
"illuminate/http": "~5.5|~6|~7",
28+
"illuminate/routing": "~5.5|~6|~7",
29+
"nesbot/carbon": "~1.2|~2",
30+
"vlucas/phpdotenv": "^3.6|^4.0"
3131
},
3232
"require-dev": {
33-
"illuminate/auth": "~5.5|~6",
34-
"mockery/mockery": "^1",
35-
"phpunit/phpunit": "~7.0.1|~8.0",
36-
"psy/psysh": "^0.9.9",
33+
"illuminate/auth": "~5.5|~6|~7",
34+
"mockery/mockery": "^1.3.1",
35+
"phpunit/phpunit": "^8.4|^9.0",
36+
"psy/psysh": "^0.10",
3737
"symfony/thanks": "^1.1"
3838
},
3939
"suggest": {
40-
"illuminate/auth": "Required to sync registered users (~5.5|~6)."
40+
"illuminate/auth": "Required to sync registered users (~5.5|~6|~7)."
4141
},
4242
"autoload": {
4343
"psr-4": {
@@ -52,6 +52,7 @@
5252
"extra": {
5353
"laravel": {
5454
"providers": [
55+
"Spinen\\Formio\\Providers\\ClientServiceProvider",
5556
"Spinen\\Formio\\Providers\\ServiceProvider"
5657
]
5758
}

phpunit.xml.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
convertErrorsToExceptions="true"
1515
convertNoticesToExceptions="true"
1616
convertWarningsToExceptions="true"
17-
processIsolation="true"
17+
processIsolation="false"
1818
stopOnFailure="false"
1919
verbose="true">
2020

@@ -49,7 +49,6 @@
4949
showOnlySummary="true"
5050
showUncoveredFiles="false"/>
5151
<log type="coverage-clover" target="build/phpunit/logs/clover.xml"/>
52-
<log type="json" target="./build/phpunit/logs/logfile.json"/>
5352
<log type="junit" target="./build/phpunit/logs/junit.xml"/>
5453
</logging>
5554
</phpunit>

src/Concerns/HasForms.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Spinen\Formio\Concerns;
44

5+
use Illuminate\Container\Container;
6+
use Illuminate\Contracts\Encryption\Encrypter;
57
use Illuminate\Support\Facades\Crypt;
68

79
/**
@@ -22,7 +24,8 @@ public function getFormioPasswordAttribute()
2224
{
2325
return is_null($this->attributes['formio_password'] ?? null)
2426
? null
25-
: Crypt::decrypt($this->attributes['formio_password']);
27+
: $this->resolveEncrypter()
28+
->decrypt($this->attributes['formio_password']);
2629
}
2730

2831
/**
@@ -62,13 +65,31 @@ public function initializeHasFormsTrait()
6265
$this->hidden[] = 'formio_password';
6366
}
6467

68+
/**
69+
* Resolve the encrypter from the IoC
70+
*
71+
* We are staying away from the Crypt facade, so that we can support PHP 7.4 with Laravel 5.x
72+
*
73+
* TODO: Remove this when dropping support of Laravel 5.5
74+
*
75+
* @return Encrypter
76+
*/
77+
protected function resolveEncrypter()
78+
{
79+
return Container::getInstance()
80+
->make(Encrypter::class);
81+
}
82+
6583
/**
6684
* Mutator for FormioPassword.
6785
*
6886
* @param string $formio_password
6987
*/
7088
public function setFormioPasswordAttribute($formio_password)
7189
{
72-
$this->attributes['formio_password'] = is_null($formio_password) ? null : Crypt::encrypt($formio_password);
90+
$this->attributes['formio_password'] = is_null($formio_password)
91+
? null
92+
: $this->resolveEncrypter()
93+
->encrypt($formio_password);
7394
}
7495
}

src/Http/Resources/FormioJwt.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@
22

33
namespace Spinen\Formio\Http\Resources;
44

5-
// NOTE: Extending "Resource" instead of "JsonResource" to be compatible with Laravel 5.5
6-
use Illuminate\Http\Resources\Json\Resource as JsonResource;
5+
//use Illuminate\Http\Resources\Json\JsonResource;
6+
7+
// TODO: When dropping support of Laravel 5.5, remove this if/else
8+
if (class_exists('Illuminate\Http\Resources\Json\JsonResource')) {
9+
class JsonResource extends \Illuminate\Http\Resources\Json\JsonResource
10+
{
11+
12+
}
13+
} else {
14+
// NOTE: Only here to support Laravel 5.5
15+
class JsonResource extends \Illuminate\Http\Resources\Json\Resource
16+
{
17+
18+
}
19+
}
720

821
class FormioJwt extends JsonResource
922
{

src/Listeners/AddToFormio.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
namespace Spinen\Formio\Listeners;
44

55
use Illuminate\Auth\Events\Registered;
6+
use Illuminate\Contracts\Config\Repository as Config;
67
use Illuminate\Contracts\Queue\ShouldQueue;
7-
use Illuminate\Support\Facades\Config;
88
use Spinen\Formio\Client as Formio;
99
use Spinen\Formio\Exceptions\UserException;
1010

1111
class AddToFormio implements ShouldQueue
1212
{
13+
/**
14+
* @var Config
15+
*/
16+
protected $config;
17+
1318
/**
1419
* Formio client instance
1520
*
@@ -20,10 +25,12 @@ class AddToFormio implements ShouldQueue
2025
/**
2126
* Create the event listener.
2227
*
28+
* @param Config $config
2329
* @param Formio $formio
2430
*/
25-
public function __construct(Formio $formio)
31+
public function __construct(Config $config, Formio $formio)
2632
{
33+
$this->config = $config;
2734
$this->formio = $formio;
2835
}
2936

@@ -37,7 +44,7 @@ public function __construct(Formio $formio)
3744
*/
3845
public function handle(Registered $event)
3946
{
40-
if (Config::get('formio.user.sync')) {
47+
if ($this->config->get('formio.user.sync')) {
4148
$this->formio->addUser($event->user);
4249
}
4350
}
@@ -51,6 +58,6 @@ public function handle(Registered $event)
5158
*/
5259
public function shouldQueue(Registered $event)
5360
{
54-
return Config::get('formio.user.sync');
61+
return $this->config->get('formio.user.sync');
5562
}
5663
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
3+
namespace Spinen\Formio\Providers;
4+
5+
use Carbon\Carbon;
6+
use GuzzleHttp\Client as Guzzle;
7+
use Illuminate\Contracts\Foundation\Application;
8+
use Illuminate\Contracts\Support\DeferrableProvider;
9+
use Illuminate\Support\Facades\Cache;
10+
use Illuminate\Support\Facades\Config;
11+
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
12+
use Spinen\Formio\Client as Formio;
13+
14+
/**
15+
* Class ClientServiceProvider
16+
*
17+
* Since this is deferred, it only needed to deal with code that has to do with the client.
18+
*
19+
* @package Spinen\Formio\Providers
20+
*/
21+
class ClientServiceProvider extends LaravelServiceProvider implements DeferrableProvider
22+
{
23+
/**
24+
* Bootstrap services.
25+
*
26+
* @return void
27+
*/
28+
public function boot()
29+
{
30+
//
31+
}
32+
33+
/**
34+
* Register services.
35+
*
36+
* @return void
37+
*/
38+
public function register()
39+
{
40+
$this->registerClient();
41+
42+
$this->app->alias(Formio::class, 'Formio');
43+
}
44+
45+
/**
46+
* Get the services provided by the provider.
47+
*
48+
* @return array
49+
*/
50+
public function provides()
51+
{
52+
return [
53+
Formio::class,
54+
];
55+
}
56+
57+
/**
58+
* Register the client
59+
*
60+
* If the Formio id or roles are null, then assume sensible values via the API
61+
*/
62+
protected function registerClient(): void
63+
{
64+
$this->app->bind(
65+
Formio::class,
66+
function (Application $app) {
67+
$formio = new Formio(Config::get('formio'), $app->make(Guzzle::class));
68+
69+
$resourceIds = function () use ($formio) {
70+
$id = $formio->login()
71+
->request('form?name=user')[0]['_id'];
72+
73+
$formio->logout();
74+
75+
return $id;
76+
};
77+
78+
// If the formio id is null, then get it or a cached value for the user resource
79+
if (empty(Config::get('formio.user.form'))) {
80+
Config::set(
81+
'formio.user.form',
82+
Cache::remember(
83+
'formio.id',
84+
Carbon::now()
85+
->addDay(),
86+
$resourceIds
87+
)
88+
);
89+
90+
$formio->setConfigs(Config::get('formio'));
91+
}
92+
93+
$roleIds = function () use ($formio) {
94+
$roles = (array)$formio->login()
95+
->request('role?title=Authenticated')[0]['_id'];
96+
97+
$formio->logout();
98+
99+
return $roles;
100+
};
101+
102+
// If the user roles are null, then get it or a cached value for authenticated user
103+
if (empty(Config::get('formio.user.roles'))) {
104+
Config::set(
105+
'formio.user.roles',
106+
Cache::remember(
107+
'formio.user.roles',
108+
Carbon::now()
109+
->addDay(),
110+
$roleIds
111+
)
112+
);
113+
114+
$formio->setConfigs(Config::get('formio'));
115+
}
116+
117+
return $formio;
118+
}
119+
);
120+
}
121+
}

0 commit comments

Comments
 (0)