Skip to content

Instantly share code, notes, and snippets.

@andevsoftware
Last active February 28, 2016 20:44
Show Gist options
  • Save andevsoftware/c10997074ac209085684 to your computer and use it in GitHub Desktop.
Save andevsoftware/c10997074ac209085684 to your computer and use it in GitHub Desktop.
Phalcon REST - Create Roles
<?php
/** @var \PhalconRest\Acl\MountingEnabledAdapterInterface $acl */
$acl = $di->get(Services::ACL);
// These are our main roles
$unauthorizedRole = new Acl\Role(AclRoles::UNAUTHORIZED);
$authorizedRole = new Acl\Role(AclRoles::AUTHORIZED);
// We register them on the acl
$acl->addRole($unauthorizedRole);
$acl->addRole($authorizedRole);
// All the following roles extend either from the authorizedRole or the
// unauthorized role.
$acl->addRole(new Acl\Role(AclRoles::ADMINISTRATOR), $authorizedRole);
$acl->addRole(new Acl\Role(AclRoles::MANAGER), $authorizedRole);
$acl->addRole(new Acl\Role(AclRoles::USER), $authorizedRole);
// Because the acl we use implements the `MountingEnabledAdapterInterface`
// we are allowed to mount our Resources on it.
$acl->mountMany($api->getResources());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment