public function install() { if (!$this->input->is_cli_request()) { return; } $this->load->dbforge(); // create acl table $fields = array('key' => array('type' => 'VARCHAR', 'constraint' => '255'), 'value' => array('type' => 'TEXT')); $this->dbforge->drop_table('acl'); $this->dbforge->add_field($fields); $this->dbforge->add_key('key', true); $this->dbforge->create_table('acl'); // create users table $fields = array('id' => array('type' => 'INT', 'constraint' => 11, 'null' => false, 'auto_increment' => true), 'email' => array('type' => 'VARCHAR', 'constraint' => '255', 'null' => false), 'password' => array('type' => 'VARCHAR', 'constraint' => '255', 'null' => false)); $this->dbforge->drop_table('users'); $this->dbforge->add_field($fields); $this->dbforge->add_key('id', true); $this->dbforge->create_table('users'); // default resources to protect $acl = new ACL(); $acl->addResource('administrator'); $acl->addResource('user'); $acl->addResource('role'); $acl->addResource('resource'); // create administrator role and grant all access $acl->addRole('administrator'); $acl->addPermissions('administrator', 'administrator', 'read'); $acl->addPermissions('administrator', 'user', ['create', 'read', 'update', 'delete']); $acl->addPermissions('administrator', 'role', ['create', 'read', 'update', 'delete']); $acl->addPermissions('administrator', 'resource', ['create', 'read', 'update', 'delete']); // custom resources // ... // ... add your custom resources to protect here // ... if (!defined('PHPUNIT_TEST')) { echo "installed\r\n"; } }
public function create($resource) { $acl = new ACL(); $acl->addResource($resource); }