summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2015-09-24 00:59:21 +0200
committerArnold Daniels <arnold@jasny.net>2015-09-24 01:06:32 +0200
commit463adba3010551a77689283b9b3533ec8cd55325 (patch)
tree22d806ba0540df105433c2fd1f6c2e5a9503ff75
parentc6edcc7741d530ee07406f037c9af1173ad9341a (diff)
downloadauth-1.0.0-beta4.zip
auth-1.0.0-beta4.tar.gz
auth-1.0.0-beta4.tar.bz2
Use interface instead of abstract methodsv1.0.0-beta4
to prevent strict errors Black hole by default (no abstract persist functions)
-rw-r--r--src/Jasny/Auth.php47
-rw-r--r--src/Jasny/Auth/Fetching.php25
-rw-r--r--src/Jasny/Auth/NoSessions.php25
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;
- }
-}