*/
protected static $current_token = [];
+ /**
+ * Get current user id, returns 0 if $login is set to false and not logged in.
+ * When $login is true, the execution will stop when not logged in.
+ *
+ * @param bool $login Perform a login request if "true"
+ *
+ * @return int User ID
+ */
+ public static function getCurrentUserID(bool $login = true)
+ {
+ if (empty(self::$current_user_id)) {
+ api_login(DI::app(), $login);
+
+ self::$current_user_id = api_user();
+ }
+
+ return (int)self::$current_user_id;
+ }
+
/**
* Fetch a dummy application token
*
return self::$current_token;
}
-
- /**
- * Get current user id, returns 0 if $login is set to false and not logged in.
- * When $login is true, the execution will stop when not logged in.
- *
- * @param bool $login Perform a login request if "true"
- *
- * @return int User ID
- */
- public static function getCurrentUserID(bool $login = true)
- {
- if (empty(self::$current_user_id)) {
- api_login(DI::app(), $login);
-
- self::$current_user_id = api_user();
- }
-
- return (int)self::$current_user_id;
- }
}
protected static $current_token = [];
/**
- * Check if the provided scope does exist
- *
- * @param string $scope the requested scope (read, write, follow, push)
+ * Get current user id, returns 0 if not logged in
*
- * @return bool "true" if the scope is allowed
+ * @return int User ID
*/
- public static function isAllowedScope(string $scope)
+ public static function getCurrentUserID()
{
- $token = self::getCurrentApplicationToken();
-
- if (empty($token)) {
- Logger::notice('Empty application token');
- return false;
- }
-
- if (!isset($token[$scope])) {
- Logger::warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
- return false;
- }
-
- if (empty($token[$scope])) {
- Logger::warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
- return false;
+ if (empty(self::$current_user_id)) {
+ $token = self::getCurrentApplicationToken();
+ if (!empty($token['uid'])) {
+ self::$current_user_id = $token['uid'];
+ } else {
+ self::$current_user_id = 0;
+ }
}
- return true;
+ return (int)self::$current_user_id;
}
/**
}
/**
- * Get current user id, returns 0 if not logged in
+ * Check if the provided scope does exist
*
- * @return int User ID
+ * @param string $scope the requested scope (read, write, follow, push)
+ *
+ * @return bool "true" if the scope is allowed
*/
- public static function getCurrentUserID()
+ public static function isAllowedScope(string $scope)
{
- if (empty(self::$current_user_id)) {
- $token = self::getCurrentApplicationToken();
- if (!empty($token['uid'])) {
- self::$current_user_id = $token['uid'];
- } else {
- self::$current_user_id = 0;
- }
+ $token = self::getCurrentApplicationToken();
+
+ if (empty($token)) {
+ Logger::notice('Empty application token');
+ return false;
}
- return (int)self::$current_user_id;
+ if (!isset($token[$scope])) {
+ Logger::warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
+ return false;
+ }
+
+ if (empty($token[$scope])) {
+ Logger::warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
+ return false;
+ }
+
+ return true;
}
/**