SAL_Token

So that we have a real class instead of just passing around an array.

Defined (1)

The class is defined in the following location(s).

/sal/class.json-api-token.php  
  1. class SAL_Token { 
  2.  
  3. public $blog_id; 
  4. public $user_id; 
  5. public $scope; 
  6. public $client_id; 
  7. public $external_user_id; 
  8. public $external_user_code; 
  9. public $auth_type; 
  10.  
  11. function __construct( $blog_id, $user_id, $scope, $client_id, $external_user_id, $external_user_code, $auth_type ) { 
  12. $this->blog_id = $blog_id; // if blog_id is set and scope is not global, limit to that blog 
  13. $this->user_id = $user_id; 
  14. $this->client_id = $client_id; 
  15. $this->scope = $scope;  
  16. $this->external_user_id = $external_user_id; 
  17. $this->external_user_code = $external_user_code; 
  18. $this->auth_type = $auth_type; 
  19.  
  20. public function is_global() { 
  21. return $scope === 'global'; 
  22.  
  23. static function for_anonymous_user() { 
  24. return new SAL_Token(  
  25. null,  
  26. get_current_user_id(),  
  27. null, // there's only ever one scope in our current API implementation, auth or global 
  28. null,  
  29. null,  
  30. null,  
  31. null 
  32. ); 
  33.  
  34. static function from_rest_token( $token ) { 
  35. $user_id = isset( $token['user_id'] ) ? $token['user_id'] : get_current_user_id(); 
  36. $scope = isset( $token['scope'] ) ? $token['scope'][0] : null; 
  37. $client_id = isset( $token['client_id'] ) ? $token['client_id'] : null; 
  38. $external_user_id = isset( $token['external_user_id'] ) ? $token['external_user_id'] : null; 
  39. $external_user_code = isset( $token['external_user_code'] ) ? $token['external_user_code'] : null; 
  40. $auth = isset( $token['auth'] ) ? $token['auth'] : null;  
  41.  
  42. return new SAL_Token(  
  43. $token['blog_id'],  
  44. $user_id,  
  45. $scope, // there's only ever one scope in our current API implementation, auth or global 
  46. $client_id,  
  47. $external_user_id,  
  48. $external_user_code,  
  49. $auth 
  50. );