Skip to content

Commit

Permalink
Merge branch 'storage'
Browse files Browse the repository at this point in the history
Conflicts:
	src/RBAC/Manager/RoleManager.php
  • Loading branch information
toor-totv committed Jul 2, 2013
2 parents bb68fbb + 7dab5e9 commit 19ca5a5
Show file tree
Hide file tree
Showing 28 changed files with 1,350 additions and 575 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ composer.lock
.idea
vendor/*
phpunit.xml
*.sqlite
15 changes: 10 additions & 5 deletions docs/usage.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ use PDO;
use RBAC\Role\Role;
use RBAC\Manager\RoleManager;

$storage_adapter = new PDOSQLiteAdapter(PDO("..."));

// Setup the role manager
$role_mgr = new RoleManager(new PDO("..."));
$role_mgr = new RoleManager($storage_adapter);

// Fetch a permission to attach. This assumes this permission was created earlier successfully.
$admin_view = $role_mgr->permissionFetchByName("admin_view");
Expand Down Expand Up @@ -105,8 +107,10 @@ use RBAC\Subject\Subject;
// The user id of your user that you wish to attach roles to
$user_id = 4;


// Setup the role manager
$role_mgr = new RoleManager(new PDO("..."));
$storage_adapter = new PDOSQLiteAdapter(PDO("..."));
$role_mgr = new RoleManager($storage_adapter);

// Fetch an existing role called admin
$role = $role_mgr->roleFetchByName("admin");
Expand All @@ -132,14 +136,15 @@ to attach roles to your own class. There is a minimal implemented subject exampl
class User extends Subject {
}

$db = new PDO("...");
$db_adapter = new PDO("...");
$storage_adapter = new PDOSQLiteAdapter($db_adapter);

// Assuming your user management class will return a user class which implements SubjectInterface or extends Subject
$user_manager = new UserManager($db);
$user_manager = new UserManager($db_adapter);
$user = $user_manager->fetchUser("Dr.Cool");

// Setup the role manager
$role_mgr = new RoleManager($db);
$role_mgr = new RoleManager($storage_adapter);

// Fetch an existing role called admin
$role = $role_mgr->roleFetchByName("admin");
Expand Down
6 changes: 2 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@

<php>
<!-- The database will be created automatically if it doesn't exist, assuming the user has rights to -->
<var name="DB_DSN" value="mysql:host=localhost;charset=utf8"/>
<var name="DB_USER" value="root"/>
<var name="DB_PASSWD" value=""/>
<var name="DB_DBNAME" value="rbac_test"/>
<var name="DB_DSN_SQLITE" value="sqlite::memory:"/>
<!--<var name="DB_DSN_MYSQL" value="mysql:host=localhost;dbname=testdb"/>-->
</php>

<logging>
Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions schema/sqlite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CREATE TABLE IF NOT EXISTS "auth_permission" (
"permission_id" INTEGER PRIMARY KEY AUTOINCREMENT,
"name" INTEGER NOT NULL,
"description" TEXT,
"added_on" DATETIME NULL DEFAULT current_timestamp,
"updated_on" DATETIME NULL DEFAULT current_timestamp,
UNIQUE ("name" ASC)
);

CREATE TABLE IF NOT EXISTS "auth_role" (
"role_id" INTEGER PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"description" TEXT,
"added_on" DATETIME NULL,
"updated_on" DATETIME NULL DEFAULT current_timestamp,
UNIQUE ("name" ASC)
);

CREATE TABLE IF NOT EXISTS "auth_role_permissions" (
"role_permission_id" INTEGER PRIMARY KEY AUTOINCREMENT,
"role_id" INTEGER NOT NULL,
"permission_id" INTEGER NOT NULL,
"added_on" DATETIME NULL DEFAULT current_timestamp,
FOREIGN KEY ("permission_id") REFERENCES "auth_permission" ("permission_id")
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY ("role_id") REFERENCES "auth_role" ("role_id")
ON DELETE CASCADE
ON UPDATE CASCADE,
UNIQUE ("role_id" ASC, "permission_id" ASC)
);

CREATE TABLE IF NOT EXISTS "auth_subject_role" (
"subject_role_id" INTEGER PRIMARY KEY AUTOINCREMENT,
"subject_id" INTEGER NOT NULL,
"role_id" INTEGER NOT NULL,
FOREIGN KEY ("role_id") REFERENCES "auth_role" ("role_id")
ON DELETE CASCADE
ON UPDATE CASCADE,
UNIQUE ("subject_id" ASC, "role_id" ASC)
);
Loading

0 comments on commit 19ca5a5

Please sign in to comment.