From db9959111050a1d9f5dc808337e6a30e20f60451 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 19 Aug 2020 13:20:27 +0300 Subject: [PATCH] ACL 1.3.0 --- CHANGELOG.md | 7 +++ README.md | 40 +++++++-------- app/Models/Acl.php | 17 +++++-- dependencies.php | 6 +-- entries_acl.php | 16 +++--- .../AclIsUserLoggedInEmailInMiddleware.php | 19 ++++--- .../AclIsUserLoggedInEmailNotInMiddleware.php | 27 +++++----- middlewares/AclIsUserLoggedInMiddleware.php | 19 ++++--- .../AclIsUserLoggedInRolesInMiddleware.php | 19 ++++--- .../AclIsUserLoggedInRolesNotInMiddleware.php | 19 ++++--- .../AclIsUserLoggedInUuidInMiddleware.php | 19 ++++--- .../AclIsUserLoggedInUuidNotInMiddleware.php | 19 ++++--- .../AclIsUserNotLoggedInMiddleware.php | 19 ++++--- plugin.yaml | 4 +- shortcodes/AclShortcodesExtension.php | 50 +++++++++---------- twig/AclTwigExtension.php | 22 ++++---- 16 files changed, 182 insertions(+), 140 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0501c52..23812ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [1.3.0](https://github.com/flextype-plugins/acl) (2020-08-19) + +### Features + +* **core** update code base for new Flextype 0.9.10 + # [1.2.1](https://github.com/flextype-plugins/acl) (2020-08-05) diff --git a/README.md b/README.md index 50c8668..7bb0571 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

ACL Plugin for Flextype

-Version License Total downloads Flextype Discord +Version License Total downloads Flextype Discord

## Features @@ -15,7 +15,7 @@ The following dependencies need to be downloaded and installed for ACL Plugin. | Item | Version | Download | |---|---|---| -| [flextype](https://github.com/flextype/flextype) | 0.9.9 | [download](https://github.com/flextype/flextype/releases) | +| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) | | [site](https://github.com/flextype-plugins/site) | >=1.0.0 | [download](https://github.com/flextype-plugins/site/releases) | | [twig](https://github.com/flextype-plugins/twig) | >=1.0.0 | [download](https://github.com/flextype-plugins/twig/releases) | @@ -56,7 +56,7 @@ The following dependencies need to be downloaded and installed for ACL Plugin. #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclIsUserLoggedInMiddleware(['container' => $flextype, 'redirect' => 'another.route.name'])); @@ -74,7 +74,7 @@ $app->get('/my-route', 'MyController:method()') #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclAccountsIsUserLoggedInRolesInMiddleware(['container' => $flextype, 'roles' => 'admin, moderator' @@ -93,7 +93,7 @@ $app->get('/my-route', 'MyController:method()') #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclIsUserLoggedInEmailsInMiddleware(['container' => $flextype, 'emails' => 'jack@flextype.org, jack@flextype.org' @@ -112,7 +112,7 @@ $app->get('/my-route', 'MyController:method()') #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclIsUserLoggedInUuidInMiddleware(['container' => $flextype, 'uuids' => 'ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2' @@ -129,7 +129,7 @@ $app->get('/my-route', 'MyController:method()') #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclIsUserNotLoggedInMiddleware(['container' => $flextype, 'redirect' => 'another.route.name'])); @@ -147,7 +147,7 @@ $app->get('/my-route', 'MyController:method()') #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclAccountsIsUserLoggedInRolesNotInMiddleware(['container' => $flextype, 'roles' => 'admin, moderator' @@ -166,7 +166,7 @@ $app->get('/my-route', 'MyController:method()') #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclIsUserLoggedInEmailsNotInMiddleware(['container' => $flextype, 'emails' => 'jack@flextype.org, sam@flextype.org' @@ -185,7 +185,7 @@ $app->get('/my-route', 'MyController:method()') #### Example ``` -$app->get('/my-route', 'MyController:method()') +$flextype->get('/my-route', 'MyController:method()') ->setName('my.route.name') ->add(new AclIsUserLoggedInUuidNotInMiddleware(['container' => $flextype, 'uuids' => 'ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2' @@ -513,7 +513,7 @@ You may restrict access for specific users to your specific code in the PHP. #### Run private code for logged in users ```php -if ($flextype->acl->isUserLoggedIn()) { +if ($flextype->container('acl')->isUserLoggedIn()) { // Private code here.. } ``` @@ -521,7 +521,7 @@ if ($flextype->acl->isUserLoggedIn()) { #### Run private content for users with roles: admin and student ```php -if ($flextype->acl->isUserLoggedInRolesIn('admin, student')) { +if ($flextype->container('acl')->isUserLoggedInRolesIn('admin, student')) { // Private code here.. } ``` @@ -529,7 +529,7 @@ if ($flextype->acl->isUserLoggedInRolesIn('admin, student')) { #### Run private code for users with uuids ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2 and d549af27-79a0-44f2-b9b1-e82b47bf87e2 ```php -if ($flextype->acl->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2') { +if ($flextype->container('acl')->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2') { // Private content here.. } ``` @@ -537,7 +537,7 @@ if ($flextype->acl->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, #### Run private code for users with emails jack@flextype.org, sam@flextype.org ```php -if ($flextype->acl->isUserLoggedInEmailIn('jack@flextype.org, sam@flextype.org')) { +if ($flextype->container('acl')->isUserLoggedInEmailIn('jack@flextype.org, sam@flextype.org')) { // Private content here.. } ``` @@ -545,22 +545,22 @@ if ($flextype->acl->isUserLoggedInEmailIn('jack@flextype.org, sam@flextype.org') #### Show logged in email ```php -echo 'Hello ' . $flextype->acl->getUserLoggedInEmail(); +echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail(); ``` #### Show logged in uuid ```php -echo 'Hello ' . $flextype->acl->getUserLoggedInEmail(); -echo 'your uuid: ' . $flextype->acl->getUserLoggedInUuid(); +echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail(); +echo 'your uuid: ' . $flextype->container('acl')->getUserLoggedInUuid(); ``` #### Show logged in roles ```php -echo 'Hello ' . $flextype->acl->getUserLoggedInEmail(); -echo 'your uuid: ' . $flextype->acl->getUserLoggedInUuid(); -echo 'and your roles: ' . $flextype->acl->getUserLoggedInRoles(); +echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail(); +echo 'your uuid: ' . $flextype->container('acl')->getUserLoggedInUuid(); +echo 'and your roles: ' . $flextype->container('acl')->getUserLoggedInRoles(); ``` ## LICENSE diff --git a/app/Models/Acl.php b/app/Models/Acl.php index 809b67d..964c613 100644 --- a/app/Models/Acl.php +++ b/app/Models/Acl.php @@ -12,15 +12,26 @@ namespace Flextype\Plugin\Acl\Models; use Flextype\Component\Session\Session; -use Flextype\App\Foundation\Container; use function array_intersect; use function array_map; use function explode; use function in_array; - -class Acl extends Container +class Acl { + /** + * Flextype Application + */ + protected $flextype; + + /** + * __construct + */ + public function __construct($flextype) + { + $this->flextype = $flextype; + } + /** * Check is user logged in * diff --git a/dependencies.php b/dependencies.php index 2372e1d..2604254 100644 --- a/dependencies.php +++ b/dependencies.php @@ -17,11 +17,11 @@ /** * Add ACL Model to Flextype container */ -$flextype['acl'] = static function ($container) { - return new Acl($container); +$flextype->container()['acl'] = static function () use ($flextype) { + return new Acl($flextype); }; /** * Add ACL Twig Extension to Flextype container */ -$flextype->twig->addExtension(new AclTwigExtension($flextype)); +$flextype->container('twig')->addExtension(new AclTwigExtension($flextype)); diff --git a/entries_acl.php b/entries_acl.php index 55a4a6f..7159531 100644 --- a/entries_acl.php +++ b/entries_acl.php @@ -4,29 +4,29 @@ use Flextype\Component\Session\Session; -$flextype->emitter->addListener('onEntryAfterInitialized', function() use ($flextype) { +$flextype->container('emitter')->addListener('onEntryAfterInitialized', function() use ($flextype) { // Get current entry - $entry = $flextype->entries->entry; + $entry = $flextype->container('entries')->entry; // Set ACL rules based on accounts uuids if (isset($entry['acl']['accounts']['uuids'])) { - if (!$flextype->acl->isUserLoggedInUuidsIn($entry['acl']['accounts']['uuids'])) { - $flextype->entries->entry = []; + if (!$flextype->container('acl')->isUserLoggedInUuidsIn($entry['acl']['accounts']['uuids'])) { + $flextype->container('entries')->entry = []; } } // Set ACL rules based on accounts emails if (isset($entry['acl']['accounts']['emails'])) { - if (!$flextype->acl->isUserLoggedInEmailsIn($entry['acl']['accounts']['emails'])) { - $flextype->entries->entry = []; + if (!$flextype->container('acl')->isUserLoggedInEmailsIn($entry['acl']['accounts']['emails'])) { + $flextype->container('entries')->entry = []; } } // Set ACL rules based on accounts roles if (isset($entry['acl']['accounts']['roles'])) { - if (!$flextype->acl->isUserLoggedInRolesIn($entry['acl']['accounts']['roles'])) { - $flextype->entries->entry = []; + if (!$flextype->container('acl')->isUserLoggedInRolesIn($entry['acl']['accounts']['roles'])) { + $flextype->container('entries')->entry = []; } } }); diff --git a/middlewares/AclIsUserLoggedInEmailInMiddleware.php b/middlewares/AclIsUserLoggedInEmailInMiddleware.php index 783d877..2a1050e 100644 --- a/middlewares/AclIsUserLoggedInEmailInMiddleware.php +++ b/middlewares/AclIsUserLoggedInEmailInMiddleware.php @@ -9,12 +9,16 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserLoggedInEmailInMiddleware extends Container +class AclIsUserLoggedInEmailInMiddleware { + /** + * Flextype Application + */ + protected $flextype; + /** * Middleware Settings */ @@ -23,11 +27,10 @@ class AclIsUserLoggedInEmailInMiddleware extends Container /** * __construct */ - public function __construct($settings) + public function __construct($flextype, $settings) { - parent::__construct($settings['container']); - - $this->settings = $settings; + $this->flextype = $flextype; + $this->settings = $settings; } /** @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if ($this->acl->isUserLoggedInEmailIn($this->settings['emails'])) { + if ($this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/middlewares/AclIsUserLoggedInEmailNotInMiddleware.php b/middlewares/AclIsUserLoggedInEmailNotInMiddleware.php index 55bd114..a19354b 100644 --- a/middlewares/AclIsUserLoggedInEmailNotInMiddleware.php +++ b/middlewares/AclIsUserLoggedInEmailNotInMiddleware.php @@ -9,26 +9,29 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserLoggedInEmailNotInMiddleware extends Container +class AclIsUserLoggedInEmailNotInMiddleware { /** - * Middleware Settings + * Flextype Application */ - protected $settings; + protected $flextype; /** - * __construct + * Middleware Settings */ - public function __construct($settings) - { - parent::__construct($settings['container']); + protected $settings; - $this->settings = $settings; - } + /** + * __construct + */ + public function __construct($flextype, $settings) + { + $this->flextype = $flextype; + $this->settings = $settings; + } /** * __invoke @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if (!$this->acl->isUserLoggedInEmailIn($this->settings['emails'])) { + if (!$this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/middlewares/AclIsUserLoggedInMiddleware.php b/middlewares/AclIsUserLoggedInMiddleware.php index 8d1c027..6390c05 100644 --- a/middlewares/AclIsUserLoggedInMiddleware.php +++ b/middlewares/AclIsUserLoggedInMiddleware.php @@ -9,12 +9,16 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserLoggedInMiddleware extends Container +class AclIsUserLoggedInMiddleware { + /** + * Flextype Application + */ + protected $flextype; + /** * Middleware Settings */ @@ -23,11 +27,10 @@ class AclIsUserLoggedInMiddleware extends Container /** * __construct */ - public function __construct($settings) + public function __construct($flextype, $settings) { - parent::__construct($settings['container']); - - $this->settings = $settings; + $this->flextype = $flextype; + $this->settings = $settings; } /** @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if ($this->acl->isUserLoggedIn()) { + if ($this->flextype->container('acl')->isUserLoggedIn()) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/middlewares/AclIsUserLoggedInRolesInMiddleware.php b/middlewares/AclIsUserLoggedInRolesInMiddleware.php index d4fe917..7dbfa71 100644 --- a/middlewares/AclIsUserLoggedInRolesInMiddleware.php +++ b/middlewares/AclIsUserLoggedInRolesInMiddleware.php @@ -9,12 +9,16 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserLoggedInRolesInMiddleware extends Container +class AclIsUserLoggedInRolesInMiddleware { + /** + * Flextype Application + */ + protected $flextype; + /** * Middleware Settings */ @@ -23,11 +27,10 @@ class AclIsUserLoggedInRolesInMiddleware extends Container /** * __construct */ - public function __construct($settings) + public function __construct($flextype, $settings) { - parent::__construct($settings['container']); - - $this->settings = $settings; + $this->flextype = $flextype; + $this->settings = $settings; } /** @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if ($this->acl->isUserLoggedInRolesIn($this->settings['roles'])) { + if ($this->flextype->container('acl')->isUserLoggedInRolesIn($this->settings['roles'])) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/middlewares/AclIsUserLoggedInRolesNotInMiddleware.php b/middlewares/AclIsUserLoggedInRolesNotInMiddleware.php index 3ec6c95..76fa80f 100644 --- a/middlewares/AclIsUserLoggedInRolesNotInMiddleware.php +++ b/middlewares/AclIsUserLoggedInRolesNotInMiddleware.php @@ -9,12 +9,16 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserLoggedInRolesNotInfMiddleware extends Container +class AclIsUserLoggedInRolesNotInfMiddleware { + /** + * Flextype Application + */ + protected $flextype; + /** * Middleware Settings */ @@ -23,11 +27,10 @@ class AclIsUserLoggedInRolesNotInfMiddleware extends Container /** * __construct */ - public function __construct($settings) + public function __construct($flextype, $settings) { - parent::__construct($settings['container']); - - $this->settings = $settings; + $this->flextype = $flextype; + $this->settings = $settings; } /** @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if (!$this->acl->isUserLoggedInRolesIn($this->settings['roles'])) { + if (!$this->flextype->container('acl')->isUserLoggedInRolesIn($this->settings['roles'])) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/middlewares/AclIsUserLoggedInUuidInMiddleware.php b/middlewares/AclIsUserLoggedInUuidInMiddleware.php index 1501863..cfe2717 100644 --- a/middlewares/AclIsUserLoggedInUuidInMiddleware.php +++ b/middlewares/AclIsUserLoggedInUuidInMiddleware.php @@ -9,12 +9,16 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserLoggedInUuidInMiddleware extends Container +class AclIsUserLoggedInUuidInMiddleware { + /** + * Flextype Application + */ + protected $flextype; + /** * Middleware Settings */ @@ -23,11 +27,10 @@ class AclIsUserLoggedInUuidInMiddleware extends Container /** * __construct */ - public function __construct($settings) + public function __construct($flextype, $settings) { - parent::__construct($settings['container']); - - $this->settings = $settings; + $this->flextype = $flextype; + $this->settings = $settings; } /** @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if ($this->acl->isUserLoggedInUuidIn($this->settings['uuids'])) { + if ($this->flextype->container('acl')->isUserLoggedInUuidIn($this->settings['uuids'])) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/middlewares/AclIsUserLoggedInUuidNotInMiddleware.php b/middlewares/AclIsUserLoggedInUuidNotInMiddleware.php index d618d33..48693a6 100644 --- a/middlewares/AclIsUserLoggedInUuidNotInMiddleware.php +++ b/middlewares/AclIsUserLoggedInUuidNotInMiddleware.php @@ -9,12 +9,16 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserLoggedInUuidNotInMiddleware extends Container +class AclIsUserLoggedInUuidNotInMiddleware { + /** + * Flextype Application + */ + protected $flextype; + /** * Middleware Settings */ @@ -23,11 +27,10 @@ class AclIsUserLoggedInUuidNotInMiddleware extends Container /** * __construct */ - public function __construct($settings) + public function __construct($flextype, $settings) { - parent::__construct($settings['container']); - - $this->settings = $settings; + $this->flextype = $flextype; + $this->settings = $settings; } /** @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if (!$this->acl->isUserLoggedInUuidIn($this->settings['uuids'])) { + if (!$this->flextype->container('acl')->isUserLoggedInUuidIn($this->settings['uuids'])) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/middlewares/AclIsUserNotLoggedInMiddleware.php b/middlewares/AclIsUserNotLoggedInMiddleware.php index b25c92e..ec9cb62 100644 --- a/middlewares/AclIsUserNotLoggedInMiddleware.php +++ b/middlewares/AclIsUserNotLoggedInMiddleware.php @@ -9,12 +9,16 @@ namespace Flextype\Plugin\Acl\Middlewares; -use Flextype\App\Foundation\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -class AclIsUserNotLoggedInMiddleware extends Container +class AclIsUserNotLoggedInMiddleware { + /** + * Flextype Application + */ + protected $flextype; + /** * Middleware Settings */ @@ -23,11 +27,10 @@ class AclIsUserNotLoggedInMiddleware extends Container /** * __construct */ - public function __construct($settings) + public function __construct($flextype, $settings) { - parent::__construct($settings['container']); - - $this->settings = $settings; + $this->flextype = $flextype; + $this->settings = $settings; } /** @@ -39,10 +42,10 @@ public function __construct($settings) */ public function __invoke(Request $request, Response $response, callable $next) : Response { - if (!$this->acl->isUserLoggedIn()) { + if (!$this->flextype->container('acl')->isUserLoggedIn()) { $response = $next($request, $response); } else { - $response = $response->withRedirect($this->router->pathFor($this->settings['redirect'])); + $response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect'])); } return $response; diff --git a/plugin.yaml b/plugin.yaml index 0596349..a90b264 100755 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: ACL -version: 1.2.1 +version: 1.3.0 description: ACL plugin for Flextype. icon: fas fa-users-cog author: @@ -11,5 +11,5 @@ bugs: https://github.com/flextype-plugins/acl/issues license: MIT dependencies: - flextype: 0.9.9 + flextype: 0.9.10 twig: '>=1.0.0' diff --git a/shortcodes/AclShortcodesExtension.php b/shortcodes/AclShortcodesExtension.php index 60f3f74..32ee3d6 100644 --- a/shortcodes/AclShortcodesExtension.php +++ b/shortcodes/AclShortcodesExtension.php @@ -12,35 +12,35 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface; // Shortcode: [userLoggedInEmail] -$flextype['shortcode']->add('userLoggedInEmail', static function (ShortcodeInterface $s) use ($flextype) { - if ($flextype->acl->getUserLoggedInEmail()) { - return $flextype->acl->getUserLoggedInEmail(); +$flextype->container('shortcode')->addHandler('userLoggedInEmail', static function (ShortcodeInterface $s) use ($flextype) { + if ($flextype->container('acl')->getUserLoggedInEmail()) { + return $flextype->container('acl')->getUserLoggedInEmail(); } return ''; }); // Shortcode: [userLoggedInUuid] -$flextype['shortcode']->add('userLoggedInUuid', static function (ShortcodeInterface $s) use ($flextype) { - if ($flextype->acl->getUserLoggedInUuid()) { - return $flextype->acl->getUserLoggedInUuid(); +$flextype->container('shortcode')->addHandler('userLoggedInUuid', static function (ShortcodeInterface $s) use ($flextype) { + if ($flextype->container('acl')->getUserLoggedInUuid()) { + return $flextype->container('acl')->getUserLoggedInUuid(); } return ''; }); // Shortcode: [userLoggedInRoles] -$flextype['shortcode']->add('userLoggedInRoles', static function (ShortcodeInterface $s) use ($flextype) { - if ($flextype->acl->getUserLoggedInRoles()) { - return $flextype->acl->getUserLoggedInRoles(); +$flextype->container('shortcode')->addHandler('userLoggedInRoles', static function (ShortcodeInterface $s) use ($flextype) { + if ($flextype->container('acl')->getUserLoggedInRoles()) { + return $flextype->container('acl')->getUserLoggedInRoles(); } return ''; }); // Shortcode: [userLoggedIn]Private content here..[/userLoggedIn] -$flextype['shortcode']->add('userLoggedIn', static function (ShortcodeInterface $s) use ($flextype) { - if ($flextype->acl->isUserLoggedIn()) { +$flextype->container('shortcode')->addHandler('userLoggedIn', static function (ShortcodeInterface $s) use ($flextype) { + if ($flextype->container('acl')->isUserLoggedIn()) { return $s->getContent(); } @@ -48,8 +48,8 @@ }); // Shortcode: [userLoggedInRolesIn roles="admin, student"]Private content here..[/userLoggedInRolesIn] -$flextype['shortcode']->add('userLoggedInRolesIn', static function (ShortcodeInterface $s) use ($flextype) { - if ($flextype->acl->isUserLoggedInRolesIn($s->getParameter('roles'))) { +$flextype->container('shortcode')->addHandler('userLoggedInRolesIn', static function (ShortcodeInterface $s) use ($flextype) { + if ($flextype->container('acl')->isUserLoggedInRolesIn($s->getParameter('roles'))) { return $s->getContent(); } @@ -57,8 +57,8 @@ }); // Shortcode: [userLoggedInUuidIn uuids="ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2"]Private content here..[/userLoggedInUuidOneOf] -$flextype['shortcode']->add('userLoggedInUuidIn', static function (ShortcodeInterface $s) use ($flextype) { - if ($flextype->acl->isUserLoggedInUuidIn($s->getParameter('uuids'))) { +$flextype->container('shortcode')->addHandler('userLoggedInUuidIn', static function (ShortcodeInterface $s) use ($flextype) { + if ($flextype->container('acl')->isUserLoggedInUuidIn($s->getParameter('uuids'))) { return $s->getContent(); } @@ -66,8 +66,8 @@ }); // Shortcode: [userLoggedInEmailIn emails="jack@flexype.org, sam@flextype.org"]Private content here..[/userLoggedInUsernameOneOf] -$flextype['shortcode']->add('userLoggedInEmailIn', static function (ShortcodeInterface $s) use ($flextype) { - if ($flextype->acl->isUserLoggedInEmailIn($s->getParameter('emails'))) { +$flextype->container('shortcode')->addHandler('userLoggedInEmailIn', static function (ShortcodeInterface $s) use ($flextype) { + if ($flextype->container('acl')->isUserLoggedInEmailIn($s->getParameter('emails'))) { return $s->getContent(); } @@ -75,8 +75,8 @@ }); // Shortcode: [userNotLoggedIn]Content for not logged in user here..[/userNotLoggedIn] -$flextype['shortcode']->add('userNotLoggedIn', static function (ShortcodeInterface $s) use ($flextype) { - if (! $flextype->acl->isUserLoggedIn()) { +$flextype->container('shortcode')->addHandler('userNotLoggedIn', static function (ShortcodeInterface $s) use ($flextype) { + if (! $flextype->container('acl')->isUserLoggedIn()) { return $s->getContent(); } @@ -84,8 +84,8 @@ }); // Shortcode: [userLoggedInRolesNotIn roles="admin, student"]Private content here..[/userLoggedInRolesNotIn] -$flextype['shortcode']->add('userLoggedInRolesNotIn', static function (ShortcodeInterface $s) use ($flextype) { - if (! $flextype->acl->isUserLoggedInRolesNotIn($s->getParameter('roles'))) { +$flextype->container('shortcode')->addHandler('userLoggedInRolesNotIn', static function (ShortcodeInterface $s) use ($flextype) { + if (! $flextype->container('acl')->isUserLoggedInRolesNotIn($s->getParameter('roles'))) { return $s->getContent(); } @@ -93,8 +93,8 @@ }); // Shortcode: [userLoggedInUuidNotIn uuids="ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2"]Private content here..[/userLoggedInUuidNotIn] -$flextype['shortcode']->add('userLoggedInUuidNotIn', static function (ShortcodeInterface $s) use ($flextype) { - if (! $flextype->acl->isUserLoggedInUuidNotIn($s->getParameter('uuids'))) { +$flextype->container('shortcode')->addHandler('userLoggedInUuidNotIn', static function (ShortcodeInterface $s) use ($flextype) { + if (! $flextype->container('acl')->isUserLoggedInUuidNotIn($s->getParameter('uuids'))) { return $s->getContent(); } @@ -102,8 +102,8 @@ }); // Shortcode: [userLoggedInEmailNotIn emails="jack@flexype.org, sam@flextype.org"]Private content here..[/userLoggedInEmailNotIn] -$flextype['shortcode']->add('userLoggedInEmailNotIn', static function (ShortcodeInterface $s) use ($flextype) { - if (! $flextype->acl->isUserLoggedInEmailsNotIn($s->getParameter('emails'))) { +$flextype->container('shortcode')->addHandler('userLoggedInEmailNotIn', static function (ShortcodeInterface $s) use ($flextype) { + if (! $flextype->container('acl')->isUserLoggedInEmailsNotIn($s->getParameter('emails'))) { return $s->getContent(); } diff --git a/twig/AclTwigExtension.php b/twig/AclTwigExtension.php index 36422ba..9f7ebfe 100644 --- a/twig/AclTwigExtension.php +++ b/twig/AclTwigExtension.php @@ -15,9 +15,9 @@ class AclTwigExtension extends AbstractExtension implements GlobalsInterface { /** - * Flextype Dependency Container + * Flextype Application */ - private $flextype; + protected $flextype; /** * Constructor @@ -41,9 +41,9 @@ public function getGlobals() : array class AclTwig { /** - * Flextype Dependency Container + * Flextype Application */ - private $flextype; + protected $flextype; /** * Constructor @@ -62,7 +62,7 @@ public function __construct($flextype) */ public function isUserLoggedIn() : bool { - return $this->flextype->acl->isUserLoggedIn(); + return $this->flextype->container('acl')->isUserLoggedIn(); } /** @@ -74,7 +74,7 @@ public function isUserLoggedIn() : bool */ public function getUserLoggedInEmail() : string { - return $this->flextype->acl->getUserLoggedInEmail(); + return $this->flextype->container('acl')->getUserLoggedInEmail(); } /** @@ -86,7 +86,7 @@ public function getUserLoggedInEmail() : string */ public function getUserLoggedInRoles() : string { - return $this->flextype->acl->getUserLoggedInRoles(); + return $this->flextype->container('acl')->getUserLoggedInRoles(); } /** @@ -98,7 +98,7 @@ public function getUserLoggedInRoles() : string */ public function getUserLoggedInUuid() : string { - return $this->flextype->acl->getUserLoggedInUuid(); + return $this->flextype->container('acl')->getUserLoggedInUuid(); } /** @@ -112,7 +112,7 @@ public function getUserLoggedInUuid() : string */ public function isUserLoggedInRolesIn($roles) : bool { - return $this->flextype->acl->isUserLoggedInRolesIn($roles); + return $this->flextype->container('acl')->isUserLoggedInRolesIn($roles); } /** @@ -126,7 +126,7 @@ public function isUserLoggedInRolesIn($roles) : bool */ public function isUserLoggedInEmailIn(string $emails) : bool { - return $this->flextype->acl->isUserLoggedInEmailIn($emails); + return $this->flextype->container('acl')->isUserLoggedInEmailIn($emails); } /** @@ -140,6 +140,6 @@ public function isUserLoggedInEmailIn(string $emails) : bool */ public function isUserLoggedInUuidIn(string $uuids) : bool { - return $this->flextype->acl->isUserLoggedInUuidIn($uuids); + return $this->flextype->container('acl')->isUserLoggedInUuidIn($uuids); } }