ACL module relies on vegas-cmf-core lib. Requires php 5.4+ with
phalcon 1.3.x installed as well.
Library provides adapters based on Mongo & MySQL. Current implementation assumes use of only one at once.
Configuration should be provided on DI
Add vegas-cmf-acl to your composer.json. Run:
php composer.phar update
First we need to enter ACL module inside dependency injection container.
Add following code into app/config/config.php
file:
return array(
// ...
'plugins' => array(
'acl' => array(
'class' => 'AclPlugin',
'attach' => 'dispatch'
),
// more plugins...
),
'acl' => array(
\Vegas\Security\Acl\Resource::WILDCARD => array(
'description' => 'All privileges (for super admin)',
'accessList' => array(
array(
'name' => \Vegas\Security\Acl\Resource::ACCESS_WILDCARD,
'description' => 'All',
'inherit' => ''
)
)
)
),
);
app/plugins/AclPlugin.php
. The extended class already contains required event handlers.
class AclPlugin extends \Vegas\Security\Acl\EventsListener\Plugin
{
}
Create a service which uses adapter appropriate for your database. Currently we provide adapters for MongoDB & MySQL. This part assumes connection to DB is already set. See MongoDB or MySQL configuration for more information.
use Phalcon\DiInterface;
use Vegas\DI\ServiceProviderInterface;
class AclMongoServiceProvider implements ServiceProviderInterface
{
const SERVICE_NAME = 'acl';
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function() {
$aclAdapter = new \Vegas\Security\Acl\Adapter\Mongo();
$acl = new \Vegas\Security\Acl($aclAdapter);
return $acl;
});
}
/**
* {@inheritdoc}
*/
public function getDependencies()
{
return [
MongoServiceProvider::SERVICE_NAME
];
}
}
use Phalcon\DiInterface;
use Vegas\DI\ServiceProviderInterface;
class AclMysqlServiceProvider implements ServiceProviderInterface
{
const SERVICE_NAME = 'acl';
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function() {
$aclAdapter = new \Vegas\Security\Acl\Adapter\Mysql();
$acl = new \Vegas\Security\Acl($aclAdapter);
return $acl;
});
}
/**
* {@inheritdoc}
*/
public function getDependencies()
{
return [
MysqlServiceProvider::SERVICE_NAME
];
}
}
tests/fixtures
as current working directory.
vendor/vegas-cmf/acl/tests/fixtures
directory in the terminal
PHINX_DBHOST
, PHINX_DBNAME
, PHINX_DBUSER
, PHINX_DBPASS
../../vendor/bin/phinx migrate -e<ENVIRONMENT>
using your application environment.
Lastly, fire setup task to populate database with default roles
php /path/to/cli.php vegas:security_acl:role setup
For more information about ACL tasks, refer to CLI reference section