Skip to content

Commit 4a4437e

Browse files
committed
Merge branch 'master' into dev
2 parents db99591 + 45559b3 commit 4a4437e

17 files changed

+124
-167
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
<a name="1.4.0"></a>
2+
# [1.4.0](https://github.com/flextype-plugins/acl) (2020-08-25)
3+
4+
### Features
5+
6+
* **core** update code base for new Flextype 0.9.11
7+
18
<a name="1.3.0"></a>
29
# [1.3.0](https://github.com/flextype-plugins/acl) (2020-08-19)
310

README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h1 align="center">ACL Plugin for <a href="http://flextype.org/">Flextype</a></h1>
22

33
<p align="center">
4-
<a href="https://github.com/flextype-plugins/acl/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/acl.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/github/downloads/flextype-plugins/acl/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.10-green.svg" alt="Flextype"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
4+
<a href="https://github.com/flextype-plugins/acl/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/acl.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/github/downloads/flextype-plugins/acl/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.11-green.svg" alt="Flextype"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
55
</p>
66

77
## Features
@@ -15,7 +15,7 @@ The following dependencies need to be downloaded and installed for ACL Plugin.
1515

1616
| Item | Version | Download |
1717
|---|---|---|
18-
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |
18+
| [flextype](https://github.com/flextype/flextype) | 0.9.11 | [download](https://github.com/flextype/flextype/releases) |
1919
| [site](https://github.com/flextype-plugins/site) | >=1.0.0 | [download](https://github.com/flextype-plugins/site/releases) |
2020
| [twig](https://github.com/flextype-plugins/twig) | >=1.0.0 | [download](https://github.com/flextype-plugins/twig/releases) |
2121

@@ -56,9 +56,9 @@ The following dependencies need to be downloaded and installed for ACL Plugin.
5656

5757
#### Example
5858
```
59-
$flextype->get('/my-route', 'MyController:method()')
59+
flextype()->get('/my-route', 'MyController:method()')
6060
->setName('my.route.name')
61-
->add(new AclIsUserLoggedInMiddleware(['container' => $flextype,
61+
->add(new AclIsUserLoggedInMiddleware([
6262
'redirect' => 'another.route.name']));
6363
```
6464

@@ -74,9 +74,9 @@ $flextype->get('/my-route', 'MyController:method()')
7474

7575
#### Example
7676
```
77-
$flextype->get('/my-route', 'MyController:method()')
77+
flextype()->get('/my-route', 'MyController:method()')
7878
->setName('my.route.name')
79-
->add(new AclAccountsIsUserLoggedInRolesInMiddleware(['container' => $flextype,
79+
->add(new AclAccountsIsUserLoggedInRolesInMiddleware([
8080
'roles' => 'admin, moderator'
8181
'redirect' => 'another.route.name']));
8282
```
@@ -93,9 +93,9 @@ $flextype->get('/my-route', 'MyController:method()')
9393

9494
#### Example
9595
```
96-
$flextype->get('/my-route', 'MyController:method()')
96+
flextype()->get('/my-route', 'MyController:method()')
9797
->setName('my.route.name')
98-
->add(new AclIsUserLoggedInEmailsInMiddleware(['container' => $flextype,
98+
->add(new AclIsUserLoggedInEmailsInMiddleware([
9999
100100
'redirect' => 'another.route.name']));
101101
```
@@ -112,9 +112,9 @@ $flextype->get('/my-route', 'MyController:method()')
112112

113113
#### Example
114114
```
115-
$flextype->get('/my-route', 'MyController:method()')
115+
flextype()->get('/my-route', 'MyController:method()')
116116
->setName('my.route.name')
117-
->add(new AclIsUserLoggedInUuidInMiddleware(['container' => $flextype,
117+
->add(new AclIsUserLoggedInUuidInMiddleware([
118118
'uuids' => 'ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2'
119119
'redirect' => 'another.route.name']));
120120
```
@@ -129,9 +129,9 @@ $flextype->get('/my-route', 'MyController:method()')
129129

130130
#### Example
131131
```
132-
$flextype->get('/my-route', 'MyController:method()')
132+
flextype()->get('/my-route', 'MyController:method()')
133133
->setName('my.route.name')
134-
->add(new AclIsUserNotLoggedInMiddleware(['container' => $flextype,
134+
->add(new AclIsUserNotLoggedInMiddleware([
135135
'redirect' => 'another.route.name']));
136136
```
137137

@@ -147,9 +147,9 @@ $flextype->get('/my-route', 'MyController:method()')
147147

148148
#### Example
149149
```
150-
$flextype->get('/my-route', 'MyController:method()')
150+
flextype()->get('/my-route', 'MyController:method()')
151151
->setName('my.route.name')
152-
->add(new AclAccountsIsUserLoggedInRolesNotInMiddleware(['container' => $flextype,
152+
->add(new AclAccountsIsUserLoggedInRolesNotInMiddleware([
153153
'roles' => 'admin, moderator'
154154
'redirect' => 'another.route.name']));
155155
```
@@ -166,9 +166,9 @@ $flextype->get('/my-route', 'MyController:method()')
166166

167167
#### Example
168168
```
169-
$flextype->get('/my-route', 'MyController:method()')
169+
flextype()->get('/my-route', 'MyController:method()')
170170
->setName('my.route.name')
171-
->add(new AclIsUserLoggedInEmailsNotInMiddleware(['container' => $flextype,
171+
->add(new AclIsUserLoggedInEmailsNotInMiddleware([
172172
173173
'redirect' => 'another.route.name']));
174174
```
@@ -185,9 +185,9 @@ $flextype->get('/my-route', 'MyController:method()')
185185

186186
#### Example
187187
```
188-
$flextype->get('/my-route', 'MyController:method()')
188+
flextype()->get('/my-route', 'MyController:method()')
189189
->setName('my.route.name')
190-
->add(new AclIsUserLoggedInUuidNotInMiddleware(['container' => $flextype,
190+
->add(new AclIsUserLoggedInUuidNotInMiddleware([
191191
'uuids' => 'ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2'
192192
'redirect' => 'another.route.name']));
193193
```
@@ -513,54 +513,54 @@ You may restrict access for specific users to your specific code in the PHP.
513513
#### Run private code for logged in users
514514

515515
```php
516-
if ($flextype->container('acl')->isUserLoggedIn()) {
516+
if (flextype('acl')->isUserLoggedIn()) {
517517
// Private code here..
518518
}
519519
```
520520

521521
#### Run private content for users with roles: admin and student
522522

523523
```php
524-
if ($flextype->container('acl')->isUserLoggedInRolesIn('admin, student')) {
524+
if (flextype('acl')->isUserLoggedInRolesIn('admin, student')) {
525525
// Private code here..
526526
}
527527
```
528528

529529
#### Run private code for users with uuids ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2 and d549af27-79a0-44f2-b9b1-e82b47bf87e2
530530

531531
```php
532-
if ($flextype->container('acl')->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2') {
532+
if (flextype('acl')->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2') {
533533
// Private content here..
534534
}
535535
```
536536

537537
#### Run private code for users with emails [email protected], [email protected]
538538

539539
```php
540-
if ($flextype->container('acl')->isUserLoggedInEmailIn('[email protected], [email protected]')) {
540+
if (flextype('acl')->isUserLoggedInEmailIn('[email protected], [email protected]')) {
541541
// Private content here..
542542
}
543543
```
544544

545545
#### Show logged in email
546546

547547
```php
548-
echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail();
548+
echo 'Hello ' . flextype('acl')->getUserLoggedInEmail();
549549
```
550550

551551
#### Show logged in uuid
552552

553553
```php
554-
echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail();
555-
echo 'your uuid: ' . $flextype->container('acl')->getUserLoggedInUuid();
554+
echo 'Hello ' . flextype('acl')->getUserLoggedInEmail();
555+
echo 'your uuid: ' . flextype('acl')->getUserLoggedInUuid();
556556
```
557557

558558
#### Show logged in roles
559559

560560
```php
561-
echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail();
562-
echo 'your uuid: ' . $flextype->container('acl')->getUserLoggedInUuid();
563-
echo 'and your roles: ' . $flextype->container('acl')->getUserLoggedInRoles();
561+
echo 'Hello ' . flextype('acl')->getUserLoggedInEmail();
562+
echo 'your uuid: ' . flextype('acl')->getUserLoggedInUuid();
563+
echo 'and your roles: ' . flextype('acl')->getUserLoggedInRoles();
564564
```
565565

566566
## LICENSE

app/Models/Acl.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@
1919

2020
class Acl
2121
{
22-
/**
23-
* Flextype Application
24-
*/
25-
protected $flextype;
26-
2722
/**
2823
* __construct
2924
*/
30-
public function __construct($flextype)
31-
{
32-
$this->flextype = $flextype;
33-
}
25+
public function __construct()
26+
{
27+
28+
}
3429

3530
/**
3631
* Check is user logged in

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"issues": "https://github.com/flextype-plugins/acl/issues"
1717
},
1818
"require": {
19-
"php": ">=7.2.5",
19+
"php": ">=7.3.0",
2020
"ext-json": "*"
2121
},
2222
"config": {
2323
"apcu-autoloader": true,
2424
"optimize-autoloader": true,
2525
"platform": {
26-
"php": "7.2.5"
26+
"php": "7.3.0"
2727
}
2828
},
2929
"autoload": {

dependencies.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
/**
1818
* Add ACL Model to Flextype container
1919
*/
20-
$flextype->container()['acl'] = static function () use ($flextype) {
21-
return new Acl($flextype);
20+
flextype()->container()['acl'] = static function () {
21+
return new Acl();
2222
};
2323

2424
/**
2525
* Add ACL Twig Extension to Flextype container
2626
*/
27-
$flextype->container('twig')->addExtension(new AclTwigExtension($flextype));
27+
flextype('twig')->addExtension(new AclTwigExtension());

entries_acl.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44

55
use Flextype\Component\Session\Session;
66

7-
$flextype->container('emitter')->addListener('onEntryAfterInitialized', function() use ($flextype) {
7+
flextype('emitter')->addListener('onEntryAfterInitialized', function() {
88

99
// Get current entry
10-
$entry = $flextype->container('entries')->entry;
10+
$entry = flextype('entries')->entry;
1111

1212
// Set ACL rules based on accounts uuids
1313
if (isset($entry['acl']['accounts']['uuids'])) {
14-
if (!$flextype->container('acl')->isUserLoggedInUuidsIn($entry['acl']['accounts']['uuids'])) {
15-
$flextype->container('entries')->entry = [];
14+
if (!flextype('acl')->isUserLoggedInUuidsIn($entry['acl']['accounts']['uuids'])) {
15+
flextype('entries')->entry = [];
1616
}
1717
}
1818

1919
// Set ACL rules based on accounts emails
2020
if (isset($entry['acl']['accounts']['emails'])) {
21-
if (!$flextype->container('acl')->isUserLoggedInEmailsIn($entry['acl']['accounts']['emails'])) {
22-
$flextype->container('entries')->entry = [];
21+
if (!flextype('acl')->isUserLoggedInEmailsIn($entry['acl']['accounts']['emails'])) {
22+
flextype('entries')->entry = [];
2323
}
2424
}
2525

2626
// Set ACL rules based on accounts roles
2727
if (isset($entry['acl']['accounts']['roles'])) {
28-
if (!$flextype->container('acl')->isUserLoggedInRolesIn($entry['acl']['accounts']['roles'])) {
29-
$flextype->container('entries')->entry = [];
28+
if (!flextype('acl')->isUserLoggedInRolesIn($entry['acl']['accounts']['roles'])) {
29+
flextype('entries')->entry = [];
3030
}
3131
}
3232
});

middlewares/AclIsUserLoggedInEmailInMiddleware.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414

1515
class AclIsUserLoggedInEmailInMiddleware
1616
{
17-
/**
18-
* Flextype Application
19-
*/
20-
protected $flextype;
21-
2217
/**
2318
* Middleware Settings
2419
*/
@@ -27,9 +22,9 @@ class AclIsUserLoggedInEmailInMiddleware
2722
/**
2823
* __construct
2924
*/
30-
public function __construct($flextype, $settings)
25+
public function __construct($settings)
3126
{
32-
$this->flextype = $flextype;
27+
3328
$this->settings = $settings;
3429
}
3530

@@ -42,10 +37,10 @@ public function __construct($flextype, $settings)
4237
*/
4338
public function __invoke(Request $request, Response $response, callable $next) : Response
4439
{
45-
if ($this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
40+
if (flextype('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
4641
$response = $next($request, $response);
4742
} else {
48-
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
43+
$response = $response->withRedirect(flextype('router')->pathFor($this->settings['redirect']));
4944
}
5045

5146
return $response;

middlewares/AclIsUserLoggedInEmailNotInMiddleware.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414

1515
class AclIsUserLoggedInEmailNotInMiddleware
1616
{
17-
/**
18-
* Flextype Application
19-
*/
20-
protected $flextype;
21-
2217
/**
2318
* Middleware Settings
2419
*/
@@ -27,9 +22,9 @@ class AclIsUserLoggedInEmailNotInMiddleware
2722
/**
2823
* __construct
2924
*/
30-
public function __construct($flextype, $settings)
25+
public function __construct($settings)
3126
{
32-
$this->flextype = $flextype;
27+
3328
$this->settings = $settings;
3429
}
3530

@@ -42,10 +37,10 @@ public function __construct($flextype, $settings)
4237
*/
4338
public function __invoke(Request $request, Response $response, callable $next) : Response
4439
{
45-
if (!$this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
40+
if (!flextype('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
4641
$response = $next($request, $response);
4742
} else {
48-
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
43+
$response = $response->withRedirect(flextype('router')->pathFor($this->settings['redirect']));
4944
}
5045

5146
return $response;

middlewares/AclIsUserLoggedInMiddleware.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414

1515
class AclIsUserLoggedInMiddleware
1616
{
17-
/**
18-
* Flextype Application
19-
*/
20-
protected $flextype;
21-
2217
/**
2318
* Middleware Settings
2419
*/
@@ -27,9 +22,9 @@ class AclIsUserLoggedInMiddleware
2722
/**
2823
* __construct
2924
*/
30-
public function __construct($flextype, $settings)
25+
public function __construct($settings)
3126
{
32-
$this->flextype = $flextype;
27+
3328
$this->settings = $settings;
3429
}
3530

@@ -42,10 +37,10 @@ public function __construct($flextype, $settings)
4237
*/
4338
public function __invoke(Request $request, Response $response, callable $next) : Response
4439
{
45-
if ($this->flextype->container('acl')->isUserLoggedIn()) {
40+
if (flextype('acl')->isUserLoggedIn()) {
4641
$response = $next($request, $response);
4742
} else {
48-
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
43+
$response = $response->withRedirect(flextype('router')->pathFor($this->settings['redirect']));
4944
}
5045

5146
return $response;

0 commit comments

Comments
 (0)