Skip to content

Commit db99591

Browse files
committed
ACL 1.3.0
1 parent 67d76d9 commit db99591

16 files changed

+182
-140
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.3.0"></a>
2+
# [1.3.0](https://github.com/flextype-plugins/acl) (2020-08-19)
3+
4+
### Features
5+
6+
* **core** update code base for new Flextype 0.9.10
7+
18
<a name="1.2.1"></a>
29
# [1.2.1](https://github.com/flextype-plugins/acl) (2020-08-05)
310

README.md

Lines changed: 20 additions & 20 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.9-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.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>
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.9 | [download](https://github.com/flextype/flextype/releases) |
18+
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [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,7 +56,7 @@ The following dependencies need to be downloaded and installed for ACL Plugin.
5656

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

7575
#### Example
7676
```
77-
$app->get('/my-route', 'MyController:method()')
77+
$flextype->get('/my-route', 'MyController:method()')
7878
->setName('my.route.name')
7979
->add(new AclAccountsIsUserLoggedInRolesInMiddleware(['container' => $flextype,
8080
'roles' => 'admin, moderator'
@@ -93,7 +93,7 @@ $app->get('/my-route', 'MyController:method()')
9393

9494
#### Example
9595
```
96-
$app->get('/my-route', 'MyController:method()')
96+
$flextype->get('/my-route', 'MyController:method()')
9797
->setName('my.route.name')
9898
->add(new AclIsUserLoggedInEmailsInMiddleware(['container' => $flextype,
9999
@@ -112,7 +112,7 @@ $app->get('/my-route', 'MyController:method()')
112112

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

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

148148
#### Example
149149
```
150-
$app->get('/my-route', 'MyController:method()')
150+
$flextype->get('/my-route', 'MyController:method()')
151151
->setName('my.route.name')
152152
->add(new AclAccountsIsUserLoggedInRolesNotInMiddleware(['container' => $flextype,
153153
'roles' => 'admin, moderator'
@@ -166,7 +166,7 @@ $app->get('/my-route', 'MyController:method()')
166166

167167
#### Example
168168
```
169-
$app->get('/my-route', 'MyController:method()')
169+
$flextype->get('/my-route', 'MyController:method()')
170170
->setName('my.route.name')
171171
->add(new AclIsUserLoggedInEmailsNotInMiddleware(['container' => $flextype,
172172
@@ -185,7 +185,7 @@ $app->get('/my-route', 'MyController:method()')
185185

186186
#### Example
187187
```
188-
$app->get('/my-route', 'MyController:method()')
188+
$flextype->get('/my-route', 'MyController:method()')
189189
->setName('my.route.name')
190190
->add(new AclIsUserLoggedInUuidNotInMiddleware(['container' => $flextype,
191191
'uuids' => 'ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2'
@@ -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->acl->isUserLoggedIn()) {
516+
if ($flextype->container('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->acl->isUserLoggedInRolesIn('admin, student')) {
524+
if ($flextype->container('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->acl->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2') {
532+
if ($flextype->container('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->acl->isUserLoggedInEmailIn('[email protected], [email protected]')) {
540+
if ($flextype->container('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->acl->getUserLoggedInEmail();
548+
echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail();
549549
```
550550

551551
#### Show logged in uuid
552552

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

558558
#### Show logged in roles
559559

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

566566
## LICENSE

app/Models/Acl.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@
1212
namespace Flextype\Plugin\Acl\Models;
1313

1414
use Flextype\Component\Session\Session;
15-
use Flextype\App\Foundation\Container;
1615
use function array_intersect;
1716
use function array_map;
1817
use function explode;
1918
use function in_array;
2019

21-
22-
class Acl extends Container
20+
class Acl
2321
{
22+
/**
23+
* Flextype Application
24+
*/
25+
protected $flextype;
26+
27+
/**
28+
* __construct
29+
*/
30+
public function __construct($flextype)
31+
{
32+
$this->flextype = $flextype;
33+
}
34+
2435
/**
2536
* Check is user logged in
2637
*

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['acl'] = static function ($container) {
21-
return new Acl($container);
20+
$flextype->container()['acl'] = static function () use ($flextype) {
21+
return new Acl($flextype);
2222
};
2323

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

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->emitter->addListener('onEntryAfterInitialized', function() use ($flextype) {
7+
$flextype->container('emitter')->addListener('onEntryAfterInitialized', function() use ($flextype) {
88

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

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

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

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

middlewares/AclIsUserLoggedInEmailInMiddleware.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99

1010
namespace Flextype\Plugin\Acl\Middlewares;
1111

12-
use Flextype\App\Foundation\Container;
1312
use Psr\Http\Message\ResponseInterface as Response;
1413
use Psr\Http\Message\ServerRequestInterface as Request;
1514

16-
class AclIsUserLoggedInEmailInMiddleware extends Container
15+
class AclIsUserLoggedInEmailInMiddleware
1716
{
17+
/**
18+
* Flextype Application
19+
*/
20+
protected $flextype;
21+
1822
/**
1923
* Middleware Settings
2024
*/
@@ -23,11 +27,10 @@ class AclIsUserLoggedInEmailInMiddleware extends Container
2327
/**
2428
* __construct
2529
*/
26-
public function __construct($settings)
30+
public function __construct($flextype, $settings)
2731
{
28-
parent::__construct($settings['container']);
29-
30-
$this->settings = $settings;
32+
$this->flextype = $flextype;
33+
$this->settings = $settings;
3134
}
3235

3336
/**
@@ -39,10 +42,10 @@ public function __construct($settings)
3942
*/
4043
public function __invoke(Request $request, Response $response, callable $next) : Response
4144
{
42-
if ($this->acl->isUserLoggedInEmailIn($this->settings['emails'])) {
45+
if ($this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
4346
$response = $next($request, $response);
4447
} else {
45-
$response = $response->withRedirect($this->router->pathFor($this->settings['redirect']));
48+
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
4649
}
4750

4851
return $response;

middlewares/AclIsUserLoggedInEmailNotInMiddleware.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,29 @@
99

1010
namespace Flextype\Plugin\Acl\Middlewares;
1111

12-
use Flextype\App\Foundation\Container;
1312
use Psr\Http\Message\ResponseInterface as Response;
1413
use Psr\Http\Message\ServerRequestInterface as Request;
1514

16-
class AclIsUserLoggedInEmailNotInMiddleware extends Container
15+
class AclIsUserLoggedInEmailNotInMiddleware
1716
{
1817
/**
19-
* Middleware Settings
18+
* Flextype Application
2019
*/
21-
protected $settings;
20+
protected $flextype;
2221

2322
/**
24-
* __construct
23+
* Middleware Settings
2524
*/
26-
public function __construct($settings)
27-
{
28-
parent::__construct($settings['container']);
25+
protected $settings;
2926

30-
$this->settings = $settings;
31-
}
27+
/**
28+
* __construct
29+
*/
30+
public function __construct($flextype, $settings)
31+
{
32+
$this->flextype = $flextype;
33+
$this->settings = $settings;
34+
}
3235

3336
/**
3437
* __invoke
@@ -39,10 +42,10 @@ public function __construct($settings)
3942
*/
4043
public function __invoke(Request $request, Response $response, callable $next) : Response
4144
{
42-
if (!$this->acl->isUserLoggedInEmailIn($this->settings['emails'])) {
45+
if (!$this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
4346
$response = $next($request, $response);
4447
} else {
45-
$response = $response->withRedirect($this->router->pathFor($this->settings['redirect']));
48+
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
4649
}
4750

4851
return $response;

middlewares/AclIsUserLoggedInMiddleware.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99

1010
namespace Flextype\Plugin\Acl\Middlewares;
1111

12-
use Flextype\App\Foundation\Container;
1312
use Psr\Http\Message\ResponseInterface as Response;
1413
use Psr\Http\Message\ServerRequestInterface as Request;
1514

16-
class AclIsUserLoggedInMiddleware extends Container
15+
class AclIsUserLoggedInMiddleware
1716
{
17+
/**
18+
* Flextype Application
19+
*/
20+
protected $flextype;
21+
1822
/**
1923
* Middleware Settings
2024
*/
@@ -23,11 +27,10 @@ class AclIsUserLoggedInMiddleware extends Container
2327
/**
2428
* __construct
2529
*/
26-
public function __construct($settings)
30+
public function __construct($flextype, $settings)
2731
{
28-
parent::__construct($settings['container']);
29-
30-
$this->settings = $settings;
32+
$this->flextype = $flextype;
33+
$this->settings = $settings;
3134
}
3235

3336
/**
@@ -39,10 +42,10 @@ public function __construct($settings)
3942
*/
4043
public function __invoke(Request $request, Response $response, callable $next) : Response
4144
{
42-
if ($this->acl->isUserLoggedIn()) {
45+
if ($this->flextype->container('acl')->isUserLoggedIn()) {
4346
$response = $next($request, $response);
4447
} else {
45-
$response = $response->withRedirect($this->router->pathFor($this->settings['redirect']));
48+
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
4649
}
4750

4851
return $response;

0 commit comments

Comments
 (0)