diff options
-rw-r--r-- | src/Jasny/Auth.php | 47 | ||||
-rw-r--r-- | src/Jasny/Auth/Fetching.php | 25 | ||||
-rw-r--r-- | src/Jasny/Auth/NoSessions.php | 25 |
3 files changed, 52 insertions, 45 deletions
diff --git a/src/Jasny/Auth.php b/src/Jasny/Auth.php index 107883f..855960b 100644 --- a/src/Jasny/Auth.php +++ b/src/Jasny/Auth.php @@ -3,11 +3,29 @@ namespace Jasny; use Jasny\Auth\User; +use Jasny\Auth\Fetching; /** * Authentication and access control + * + * <code> + * class MyAuth extends Jasny\Auth + * { + * use Jasny\Auth\Sessions; + * + * public static function fetchUserById($id) + * { + * ... + * } + * + * public static function fetchUserByUsername($username) + * { + * ... + * } + * } + * </code> */ -abstract class Auth +abstract class Auth implements Fetching { /** * Secret word for creating a verification hash @@ -23,33 +41,22 @@ abstract class Auth /** - * Fetch a user by ID - * - * @param int $id - * @return User - */ - abstract public static function fetchUserById($id); - - /** - * Fetch a user by username - * - * @param string $username - * @return User - */ - abstract public static function fetchUserByUsername($username); - - - /** * Persist the current user id across requests */ - abstract protected static function persistCurrentUser(); + protected static function persistCurrentUser() + { + // Black hole + } /** * Get current authenticated user id * * @return mixed */ - abstract protected static function getCurrentUserId(); + protected static function getCurrentUserId() + { + return null; + } /** diff --git a/src/Jasny/Auth/Fetching.php b/src/Jasny/Auth/Fetching.php new file mode 100644 index 0000000..3d1c01d --- /dev/null +++ b/src/Jasny/Auth/Fetching.php @@ -0,0 +1,25 @@ +<?php + +namespace Auth; + +/** + * Methods that need to be implemented for fetching user info + */ +interface Fetching +{ + /** + * Fetch a user by ID + * + * @param int $id + * @return User + */ + public static function fetchUserById($id); + + /** + * Fetch a user by username + * + * @param string $username + * @return User + */ + public static function fetchUserByUsername($username); +} diff --git a/src/Jasny/Auth/NoSessions.php b/src/Jasny/Auth/NoSessions.php deleted file mode 100644 index 82d106d..0000000 --- a/src/Jasny/Auth/NoSessions.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Jasny\Auth; - -/** - * Don't persist the authenticated user - */ -trait NoSessions -{ - /** - * Don't persist - */ - protected static function persistCurrentUser() - { } - - /** - * There is never a persisted user id - * - * @return null - */ - protected static function getCurrentUserId() - { - return null; - } -} |