Blame view

app/library/App/Bootstrap/AclBootstrap.php 1.15 KB
15479603   Alex Savenko   initialize
1
2
3
4
5
6
7
  <?php
  
  namespace App\Bootstrap;
  
  use App\BootstrapInterface;
  use App\Constants\Services;
  use Phalcon\Acl;
0b8d4ffc   Alex Savenko   Add Roles.
8
9
  use Phalcon\Acl\Resource;
  use Phalcon\Acl\Role;
15479603   Alex Savenko   initialize
10
11
12
13
14
15
16
17
18
19
20
21
  use Phalcon\Config;
  use Phalcon\DiInterface;
  use PhalconRest\Api;
  use App\Constants\AclRoles;
  
  class AclBootstrap implements BootstrapInterface
  {
      public function run(Api $api, DiInterface $di, Config $config)
      {
          /** @var \PhalconApi\Acl\MountingEnabledAdapterInterface $acl */
          $acl = $di->get(Services::ACL);
  
0b8d4ffc   Alex Savenko   Add Roles.
22
23
          $unauthorizedRole   = new Role(AclRoles::UNAUTHORIZED);
          $authorizedRole     = new Role(AclRoles::AUTHORIZED);
15479603   Alex Savenko   initialize
24
25
26
27
  
          $acl->addRole($unauthorizedRole);
          $acl->addRole($authorizedRole);
  
0b8d4ffc   Alex Savenko   Add Roles.
28
29
30
31
32
33
34
35
36
37
          $administrator  = new Role(AclRoles::ADMINISTRATOR);
          $user           = new Role(AclRoles::USER);
          $editor         = new Role(AclRoles::EDITOR);
          $author         = new Role(AclRoles::AUTHOR);
  
  
          $acl->addRole($administrator, $authorizedRole);
          $acl->addRole($user, $authorizedRole);
          $acl->addRole($editor, $authorizedRole);
          $acl->addRole($author, $authorizedRole);
15479603   Alex Savenko   initialize
38
39
40
41
  
          $acl->mountMany($api->getCollections());
      }
  }