LastFM
extends OAuthProvider
in package
Last.fm
Tags
Table of Contents
Constants
- PERIOD_12MONTH = '12month'
- PERIOD_1MONTH = '1month'
- PERIOD_3MONTH = '3month'
- PERIOD_6MONTH = '6month'
- PERIOD_7DAY = '7day'
- PERIOD_OVERALL = 'overall'
- PERIODS = [self::PERIOD_OVERALL, self::PERIOD_7DAY, self::PERIOD_1MONTH, self::PERIOD_3MONTH, self::PERIOD_6MONTH, self::PERIOD_12MONTH]
- MAGIC_PROPERTIES = ['apiDocs', 'apiURL', 'applicationURL', 'serviceName', 'userRevokeURL']
Properties
- $accessTokenURL : string
- the provider's access token exchange URL
- $apiDocs : string|null
- an optional link to the provider's API docs (magic)
- $apiURL : string
- the API base URL (magic)
- $applicationURL : string|null
- an optional URL to the provider's credential registration/application page (magic)
- $authURL : string
- the authentication URL
- $http : ClientInterface
- $logger : LoggerInterface
- $options : OAuthOptions|SettingsContainerInterface
- $requestFactory : RequestFactoryInterface
- $revokeURL : string
- an optional URL for application side token revocation
- $serviceName : string
- the name of the provider/class (magic)
- $storage : OAuthStorageInterface
- $streamFactory : StreamFactoryInterface
- $uriFactory : UriFactoryInterface
- $userRevokeURL : string|null
- an optional link to the page where a user can revoke access tokens (magic)
Methods
- __construct() : mixed
- OAuthProvider constructor.
- __get() : string|null
- Magic getter for the properties specified in self::ALLOWED_PROPERTIES
- getAccessToken() : AccessToken
- getAccessTokenFromStorage() : AccessToken
- Gets an access token from the current OAuthStorageInterface (shorthand/convenience)
- getAuthURL() : UriInterface
- getRequestAuthorization() : RequestInterface
- getStorage() : OAuthStorageInterface
- Returns the current OAuthStorageInterface
- InvalidateAccessToken() : bool
- me() : ResponseInterface
- Returns information about the currently authenticated user (usually a /me or /user endpoint).
- request() : ResponseInterface
- Prepares an API request to $path with the given parameters, gets authorization, fires the request and returns a PSR-7 ResponseInterface with the corresponding API response
- sendRequest() : ResponseInterface
- setLogger() : static
- Sets an optional PSR-3 LoggerInterface
- setRequestFactory() : static
- Sets an optional PSR-17 RequestFactoryInterface
- setStorage() : static
- Sets an optional OAuthStorageInterface
- setStreamFactory() : static
- Sets an optional PSR-17 StreamFactoryInterface
- setUriFactory() : static
- Sets an optional PSR-17 UriFactoryInterface
- storeAccessToken() : static
- Sets an access token in the current OAuthStorageInterface (shorthand/convenience)
- cleanBodyParams() : array<string|int, mixed>
- Cleans an array of body parameters
- cleanQueryParams() : array<string|int, mixed>
- Cleans an array of query parameters
- construct() : void
- A replacement constructor that you can call in extended classes, so that you don't have to implement the monstrous original `__construct()`
- createAccessToken() : AccessToken
- Creates an access token with the provider set to $this->serviceName
- getRequestBody() : StreamInterface
- Prepares the request body
- getRequestHeaders() : array<string|int, mixed>
- Prepare request headers
- getRequestTarget() : string
- Determine the request target from the given URI (path segment or URL) with respect to $apiURL, anything except host and path will be ignored, scheme will always be set to "https".
- getRequestURL() : string
- Prepares the request URL
- getSignature() : string
- nonce() : string
- returns a 32 byte random string (in hexadecimal representation) for use as a nonce
- parseTokenResponse() : AccessToken
Constants
PERIOD_12MONTH
public
mixed
PERIOD_12MONTH
= '12month'
PERIOD_1MONTH
public
mixed
PERIOD_1MONTH
= '1month'
PERIOD_3MONTH
public
mixed
PERIOD_3MONTH
= '3month'
PERIOD_6MONTH
public
mixed
PERIOD_6MONTH
= '6month'
PERIOD_7DAY
public
mixed
PERIOD_7DAY
= '7day'
PERIOD_OVERALL
public
mixed
PERIOD_OVERALL
= 'overall'
PERIODS
public
mixed
PERIODS
= [self::PERIOD_OVERALL, self::PERIOD_7DAY, self::PERIOD_1MONTH, self::PERIOD_3MONTH, self::PERIOD_6MONTH, self::PERIOD_12MONTH]
MAGIC_PROPERTIES
protected
array<string|int, string>
MAGIC_PROPERTIES
= ['apiDocs', 'apiURL', 'applicationURL', 'serviceName', 'userRevokeURL']
Properties
$accessTokenURL
the provider's access token exchange URL
protected
string
$accessTokenURL
= 'https://ws.audioscrobbler.com/2.0'
$apiDocs
an optional link to the provider's API docs (magic)
protected
string|null
$apiDocs
= 'https://www.last.fm/api/'
$apiURL
the API base URL (magic)
protected
string
$apiURL
= 'https://ws.audioscrobbler.com/2.0'
$applicationURL
an optional URL to the provider's credential registration/application page (magic)
protected
string|null
$applicationURL
= 'https://www.last.fm/api/account/create'
$authURL
the authentication URL
protected
string
$authURL
= 'https://www.last.fm/api/auth'
$http
protected
ClientInterface
$http
$logger
protected
LoggerInterface
$logger
= new NullLogger()
$options
protected
OAuthOptions|SettingsContainerInterface
$options
$requestFactory
protected
RequestFactoryInterface
$requestFactory
$revokeURL
an optional URL for application side token revocation
protected
string
$revokeURL
Tags
$serviceName
the name of the provider/class (magic)
protected
string
$serviceName
$storage
protected
OAuthStorageInterface
$storage
= new MemoryStorage()
$streamFactory
protected
StreamFactoryInterface
$streamFactory
$uriFactory
protected
UriFactoryInterface
$uriFactory
$userRevokeURL
an optional link to the page where a user can revoke access tokens (magic)
protected
string|null
$userRevokeURL
= 'https://www.last.fm/settings/applications'
Methods
__construct()
OAuthProvider constructor.
public
__construct(OAuthOptions|SettingsContainerInterface $options, ClientInterface $http, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory, UriFactoryInterface $uriFactory[, OAuthStorageInterface $storage = new MemoryStorage() ][, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
- $options : OAuthOptions|SettingsContainerInterface
- $http : ClientInterface
- $requestFactory : RequestFactoryInterface
- $streamFactory : StreamFactoryInterface
- $uriFactory : UriFactoryInterface
- $storage : OAuthStorageInterface = new MemoryStorage()
- $logger : LoggerInterface = new NullLogger()
__get()
Magic getter for the properties specified in self::ALLOWED_PROPERTIES
public
final __get(string $name) : string|null
Parameters
- $name : string
Return values
string|nullgetAccessToken()
public
getAccessToken(string $session_token) : AccessToken
Parameters
- $session_token : string
Return values
AccessTokengetAccessTokenFromStorage()
Gets an access token from the current OAuthStorageInterface (shorthand/convenience)
public
getAccessTokenFromStorage() : AccessToken
Tags
Return values
AccessTokengetAuthURL()
public
getAuthURL([array<string|int, mixed>|null $params = null ][, array<string|int, mixed>|null $scopes = null ]) : UriInterface
Parameters
- $params : array<string|int, mixed>|null = null
- $scopes : array<string|int, mixed>|null = null
Tags
Return values
UriInterfacegetRequestAuthorization()
public
getRequestAuthorization(RequestInterface $request[, AccessToken|null $token = null ]) : RequestInterface
Parameters
- $request : RequestInterface
- $token : AccessToken|null = null
Tags
Return values
RequestInterfacegetStorage()
Returns the current OAuthStorageInterface
public
final getStorage() : OAuthStorageInterface
Tags
Return values
OAuthStorageInterfaceInvalidateAccessToken()
public
InvalidateAccessToken([AccessToken|null $token = null ]) : bool
Parameters
- $token : AccessToken|null = null
Tags
Return values
boolme()
Returns information about the currently authenticated user (usually a /me or /user endpoint).
public
me() : ResponseInterface
Tags
Return values
ResponseInterfacerequest()
Prepares an API request to $path with the given parameters, gets authorization, fires the request and returns a PSR-7 ResponseInterface with the corresponding API response
public
request(string $path[, array<string|int, mixed>|null $params = null ][, string|null $method = null ][, StreamInterface|array<string|int, mixed>|string|null $body = null ][, array<string|int, mixed>|null $headers = null ][, string|null $protocolVersion = null ]) : ResponseInterface
Parameters
- $path : string
- $params : array<string|int, mixed>|null = null
- $method : string|null = null
- $body : StreamInterface|array<string|int, mixed>|string|null = null
- $headers : array<string|int, mixed>|null = null
- $protocolVersion : string|null = null
Tags
Return values
ResponseInterfacesendRequest()
public
final sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Tags
Return values
ResponseInterfacesetLogger()
Sets an optional PSR-3 LoggerInterface
public
final setLogger(LoggerInterface $logger) : static
Parameters
- $logger : LoggerInterface
Tags
Return values
staticsetRequestFactory()
Sets an optional PSR-17 RequestFactoryInterface
public
final setRequestFactory(RequestFactoryInterface $requestFactory) : static
Parameters
- $requestFactory : RequestFactoryInterface
Tags
Return values
staticsetStorage()
Sets an optional OAuthStorageInterface
public
final setStorage(OAuthStorageInterface $storage) : static
Parameters
- $storage : OAuthStorageInterface
Tags
Return values
staticsetStreamFactory()
Sets an optional PSR-17 StreamFactoryInterface
public
final setStreamFactory(StreamFactoryInterface $streamFactory) : static
Parameters
- $streamFactory : StreamFactoryInterface
Tags
Return values
staticsetUriFactory()
Sets an optional PSR-17 UriFactoryInterface
public
final setUriFactory(UriFactoryInterface $uriFactory) : static
Parameters
- $uriFactory : UriFactoryInterface
Tags
Return values
staticstoreAccessToken()
Sets an access token in the current OAuthStorageInterface (shorthand/convenience)
public
storeAccessToken(AccessToken $token) : static
Parameters
- $token : AccessToken
Tags
Return values
staticcleanBodyParams()
Cleans an array of body parameters
protected
cleanBodyParams(iterable<string|int, mixed> $params) : array<string|int, mixed>
Parameters
- $params : iterable<string|int, mixed>
Return values
array<string|int, mixed>cleanQueryParams()
Cleans an array of query parameters
protected
cleanQueryParams(iterable<string|int, mixed> $params) : array<string|int, mixed>
Parameters
- $params : iterable<string|int, mixed>
Return values
array<string|int, mixed>construct()
A replacement constructor that you can call in extended classes, so that you don't have to implement the monstrous original `__construct()`
protected
construct() : void
createAccessToken()
Creates an access token with the provider set to $this->serviceName
protected
createAccessToken() : AccessToken
Tags
Return values
AccessTokengetRequestBody()
Prepares the request body
protected
getRequestBody(StreamInterface|array<string|int, mixed>|string $body, RequestInterface $request) : StreamInterface
Parameters
- $body : StreamInterface|array<string|int, mixed>|string
- $request : RequestInterface
Tags
Return values
StreamInterfacegetRequestHeaders()
Prepare request headers
protected
getRequestHeaders([array<string|int, mixed>|null $headers = null ]) : array<string|int, mixed>
Parameters
- $headers : array<string|int, mixed>|null = null
Return values
array<string|int, mixed>getRequestTarget()
Determine the request target from the given URI (path segment or URL) with respect to $apiURL, anything except host and path will be ignored, scheme will always be set to "https".
protected
getRequestTarget(string $uri) : string
Throws if the host of a given URL does not match the host of $apiURL.
Parameters
- $uri : string
Tags
Return values
stringgetRequestURL()
Prepares the request URL
protected
getRequestURL(string $path[, array<string|int, mixed>|null $params = null ]) : string
Parameters
- $path : string
- $params : array<string|int, mixed>|null = null
Return values
stringgetSignature()
protected
getSignature(array<string|int, mixed> $params) : string
Parameters
- $params : array<string|int, mixed>
Return values
stringnonce()
returns a 32 byte random string (in hexadecimal representation) for use as a nonce
protected
nonce([int $bytes = 32 ]) : string
Parameters
- $bytes : int = 32
Tags
Return values
stringparseTokenResponse()
protected
parseTokenResponse(ResponseInterface $response) : AccessToken
Parameters
- $response : ResponseInterface