Config
in package
Table of Contents
Properties
- $accountId : int
- $activeContext : string
- $apiVersion : string|null
- $appKey : string|null
- $authMode : string
- $baseUrl : string|null
- $contexts : array<string, LoggerInterface, masquerade_user_id?: int}>
- $logger : LoggerInterface|null
- $masqueradeUserId : int|null
- $oauthClientId : string|null
- $oauthClientSecret : string|null
- $oauthExpiresAt : int|null
- $oauthRedirectUri : string|null
- $oauthRefreshToken : string|null
- $oauthScopes : array<string|int, string>|null
- $oauthToken : string|null
- $oauthUserId : int|null
- $oauthUserName : string|null
- $timeout : int|null
Methods
- asUser() : void
- Set the user ID to masquerade as for API calls.
- autoDetect() : void
- Auto-detect configuration from environment variables.
- clearOAuthTokens() : void
- Clear all OAuth tokens and related data.
- debugConfig() : array<string, mixed>
- Debug the configuration for a specific context.
- getAccountId() : int
- Get the account ID.
- getAllContexts() : array<string|int, string>
- Get all configured contexts.
- getApiKey() : string|null
- Get the API key (alias for getAppKey for common naming).
- getApiVersion() : string|null
- Get the API version.
- getAppKey() : string|null
- Get the application key.
- getAuthMode() : string
- Get the current authentication mode.
- getBaseUrl() : string|null
- Get the base URL for API requests.
- getContext() : string
- Get the currently active context.
- getLogger() : LoggerInterface
- Get the configured logger instance.
- getMasqueradeUserId() : int|null
- Get the current masquerade user ID.
- getMiddleware() : array<string, array<string, mixed>>
- Get middleware configuration.
- getOAuthClientId() : string|null
- Get the OAuth client ID.
- getOAuthClientSecret() : string|null
- Get the OAuth client secret.
- getOAuthExpiresAt() : int|null
- Get the OAuth token expiration timestamp.
- getOAuthRedirectUri() : string|null
- Get the OAuth redirect URI.
- getOAuthRefreshToken() : string|null
- Get the OAuth refresh token.
- getOAuthScopes() : array<string|int, string>|null
- Get the OAuth scopes.
- getOAuthToken() : string|null
- Get the OAuth access token.
- getOAuthUserId() : int|null
- Get the OAuth user ID.
- getOAuthUserName() : string|null
- Get the OAuth user name.
- getTimeout() : int|null
- Get the timeout for API requests.
- hasAccountIdConfigured() : bool
- Check if an account ID has been explicitly configured for a context.
- hasLogger() : bool
- Check if a logger has been configured.
- isMasquerading() : bool
- Check if masquerading is currently active.
- isOAuthTokenExpired() : bool
- Check if the OAuth token is expired or about to expire.
- resetContext() : void
- Reset a specific context, removing all its configuration.
- setAccountId() : void
- Set the account ID.
- setApiKey() : void
- Set the API key (alias for setAppKey for common naming).
- setApiVersion() : void
- Set the API version.
- setAppKey() : void
- Set the application key.
- setBaseUrl() : void
- Set the base URL for API requests.
- setContext() : void
- Set the active context for configuration.
- setLogger() : void
- Set a PSR-3 logger instance for the SDK.
- setMiddleware() : void
- Set middleware configuration.
- setOAuthClientId() : void
- Set the OAuth client ID.
- setOAuthClientSecret() : void
- Set the OAuth client secret.
- setOAuthExpiresAt() : void
- Set the OAuth token expiration timestamp.
- setOAuthRedirectUri() : void
- Set the OAuth redirect URI.
- setOAuthRefreshToken() : void
- Set the OAuth refresh token.
- setOAuthScopes() : void
- Set the OAuth scopes.
- setOAuthToken() : void
- Set the OAuth access token.
- setOAuthUserId() : void
- Set the OAuth user ID.
- setOAuthUserName() : void
- Set the OAuth user name.
- setTimeout() : void
- Set the timeout for API requests.
- stopMasquerading() : void
- Stop masquerading and return to normal authenticated user operations.
- useApiKey() : void
- Switch to API key authentication mode.
- useOAuth() : void
- Switch to OAuth authentication mode.
- validate() : void
- Validate the configuration for a specific context.
- syncLegacyValues() : void
- Synchronize legacy static properties with active context values.
Properties
$accountId
private
static int
$accountId
= 1
$activeContext
private
static string
$activeContext
= 'default'
$apiVersion
private
static string|null
$apiVersion
= 'v1'
$appKey
private
static string|null
$appKey
= null
$authMode
private
static string
$authMode
= 'api_key'
Authentication mode ('api_key' or 'oauth')
$baseUrl
private
static string|null
$baseUrl
= null
$contexts
private
static array<string, LoggerInterface, masquerade_user_id?: int}>
$contexts
= []
$logger
private
static LoggerInterface|null
$logger
= null
PSR-3 logger instance
$masqueradeUserId
private
static int|null
$masqueradeUserId
= null
User ID to masquerade as
$oauthClientId
private
static string|null
$oauthClientId
= null
OAuth client ID
$oauthClientSecret
private
static string|null
$oauthClientSecret
= null
OAuth client secret
$oauthExpiresAt
private
static int|null
$oauthExpiresAt
= null
OAuth token expiration timestamp
$oauthRedirectUri
private
static string|null
$oauthRedirectUri
= null
OAuth redirect URI
$oauthRefreshToken
private
static string|null
$oauthRefreshToken
= null
OAuth refresh token
$oauthScopes
private
static array<string|int, string>|null
$oauthScopes
= null
OAuth scopes
$oauthToken
private
static string|null
$oauthToken
= null
OAuth access token
$oauthUserId
private
static int|null
$oauthUserId
= null
OAuth user ID
$oauthUserName
private
static string|null
$oauthUserName
= null
OAuth user name
$timeout
private
static int|null
$timeout
= 30
Methods
asUser()
Set the user ID to masquerade as for API calls.
public
static asUser(int $userId[, string|null $context = null ]) : void
This enables Canvas's "Act As User" functionality, allowing administrators to perform API operations on behalf of another user. The authenticated user must have appropriate Canvas permissions to masquerade.
Parameters
- $userId : int
-
The Canvas user ID to masquerade as.
- $context : string|null = null
-
The context to set masquerading for. If null, uses active context.
autoDetect()
Auto-detect configuration from environment variables.
public
static autoDetect([string|null $context = null ]) : void
Parameters
- $context : string|null = null
-
The context to set configuration for. If null, uses active context.
Tags
clearOAuthTokens()
Clear all OAuth tokens and related data.
public
static clearOAuthTokens([string|null $context = null ]) : void
Parameters
- $context : string|null = null
-
The context to clear OAuth data for. If null, uses active context.
debugConfig()
Debug the configuration for a specific context.
public
static debugConfig([string|null $context = null ]) : array<string, mixed>
Parameters
- $context : string|null = null
-
The context to debug. If null, uses active context.
Return values
array<string, mixed> —Configuration details for debugging.
getAccountId()
Get the account ID.
public
static getAccountId([string|null $context = null ]) : int
Parameters
- $context : string|null = null
-
The context to get the account ID from. If null, uses active context.
Return values
int —The account ID.
getAllContexts()
Get all configured contexts.
public
static getAllContexts() : array<string|int, string>
Return values
array<string|int, string> —List of context names.
getApiKey()
Get the API key (alias for getAppKey for common naming).
public
static getApiKey([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the key from. If null, uses active context.
Return values
string|null —The API key or null if not set.
getApiVersion()
Get the API version.
public
static getApiVersion([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the version from. If null, uses active context.
Return values
string|null —The API version or null if not set.
getAppKey()
Get the application key.
public
static getAppKey([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the key from. If null, uses active context.
Return values
string|null —The application key or null if not set.
getAuthMode()
Get the current authentication mode.
public
static getAuthMode([string|null $context = null ]) : string
Parameters
- $context : string|null = null
-
The context to get the auth mode from. If null, uses active context.
Return values
string —The authentication mode ('api_key' or 'oauth').
getBaseUrl()
Get the base URL for API requests.
public
static getBaseUrl([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the URL from. If null, uses active context.
Return values
string|null —The base URL or null if not set.
getContext()
Get the currently active context.
public
static getContext() : string
Return values
string —The active context name.
getLogger()
Get the configured logger instance.
public
static getLogger([string|null $context = null ]) : LoggerInterface
Parameters
- $context : string|null = null
-
The context to get the logger from. If null, uses active context.
Return values
LoggerInterface —The logger instance (returns NullLogger if not configured)
getMasqueradeUserId()
Get the current masquerade user ID.
public
static getMasqueradeUserId([string|null $context = null ]) : int|null
Parameters
- $context : string|null = null
-
The context to get the masquerade user ID from. If null, uses active context.
Return values
int|null —The user ID being masqueraded as, or null if not masquerading.
getMiddleware()
Get middleware configuration.
public
static getMiddleware([string|null $context = null ]) : array<string, array<string, mixed>>
Parameters
- $context : string|null = null
-
The context to get the middleware for (null for active context)
Return values
array<string, array<string, mixed>> —The middleware configuration
getOAuthClientId()
Get the OAuth client ID.
public
static getOAuthClientId([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the client ID from. If null, uses active context.
Return values
string|null —The OAuth client ID or null if not set.
getOAuthClientSecret()
Get the OAuth client secret.
public
static getOAuthClientSecret([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the client secret from. If null, uses active context.
Return values
string|null —The OAuth client secret or null if not set.
getOAuthExpiresAt()
Get the OAuth token expiration timestamp.
public
static getOAuthExpiresAt([string|null $context = null ]) : int|null
Parameters
- $context : string|null = null
-
The context to get the expiration from. If null, uses active context.
Return values
int|null —The Unix timestamp when the token expires or null if not set.
getOAuthRedirectUri()
Get the OAuth redirect URI.
public
static getOAuthRedirectUri([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the redirect URI from. If null, uses active context.
Return values
string|null —The OAuth redirect URI or null if not set.
getOAuthRefreshToken()
Get the OAuth refresh token.
public
static getOAuthRefreshToken([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the refresh token from. If null, uses active context.
Return values
string|null —The OAuth refresh token or null if not set.
getOAuthScopes()
Get the OAuth scopes.
public
static getOAuthScopes([string|null $context = null ]) : array<string|int, string>|null
Parameters
- $context : string|null = null
-
The context to get the scopes from. If null, uses active context.
Return values
array<string|int, string>|null —The OAuth scopes or null if not set.
getOAuthToken()
Get the OAuth access token.
public
static getOAuthToken([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the token from. If null, uses active context.
Return values
string|null —The OAuth access token or null if not set.
getOAuthUserId()
Get the OAuth user ID.
public
static getOAuthUserId([string|null $context = null ]) : int|null
Parameters
- $context : string|null = null
-
The context to get the user ID from. If null, uses active context.
Return values
int|null —The OAuth user ID or null if not set.
getOAuthUserName()
Get the OAuth user name.
public
static getOAuthUserName([string|null $context = null ]) : string|null
Parameters
- $context : string|null = null
-
The context to get the user name from. If null, uses active context.
Return values
string|null —The OAuth user name or null if not set.
getTimeout()
Get the timeout for API requests.
public
static getTimeout([string|null $context = null ]) : int|null
Parameters
- $context : string|null = null
-
The context to get the timeout from. If null, uses active context.
Return values
int|null —The timeout in seconds or null if not set.
hasAccountIdConfigured()
Check if an account ID has been explicitly configured for a context.
public
static hasAccountIdConfigured([string|null $context = null ]) : bool
Parameters
- $context : string|null = null
-
The context to check. If null, uses active context.
Return values
bool —True if account ID is explicitly configured, false if using default.
hasLogger()
Check if a logger has been configured.
public
static hasLogger([string|null $context = null ]) : bool
Parameters
- $context : string|null = null
-
The context to check. If null, uses active context.
Return values
bool —True if a logger is configured, false otherwise
isMasquerading()
Check if masquerading is currently active.
public
static isMasquerading([string|null $context = null ]) : bool
Parameters
- $context : string|null = null
-
The context to check. If null, uses active context.
Return values
bool —True if masquerading is active, false otherwise.
isOAuthTokenExpired()
Check if the OAuth token is expired or about to expire.
public
static isOAuthTokenExpired([string|null $context = null ]) : bool
Parameters
- $context : string|null = null
-
The context to check. If null, uses active context.
Return values
bool —True if token is expired or will expire within 5 minutes.
resetContext()
Reset a specific context, removing all its configuration.
public
static resetContext(string $context) : void
Parameters
- $context : string
-
The context to reset.
setAccountId()
Set the account ID.
public
static setAccountId(int $accountId[, string|null $context = null ]) : void
Parameters
- $accountId : int
-
The account ID.
- $context : string|null = null
-
The context to set the account ID for. If null, uses active context.
setApiKey()
Set the API key (alias for setAppKey for common naming).
public
static setApiKey(string $key[, string|null $context = null ]) : void
Parameters
- $key : string
-
The API key.
- $context : string|null = null
-
The context to set the key for. If null, uses active context.
setApiVersion()
Set the API version.
public
static setApiVersion(string $version[, string|null $context = null ]) : void
Parameters
- $version : string
-
The API version.
- $context : string|null = null
-
The context to set the version for. If null, uses active context.
setAppKey()
Set the application key.
public
static setAppKey(string $key[, string|null $context = null ]) : void
Parameters
- $key : string
-
The application key.
- $context : string|null = null
-
The context to set the key for. If null, uses active context.
setBaseUrl()
Set the base URL for API requests.
public
static setBaseUrl(string $url[, string|null $context = null ]) : void
Parameters
- $url : string
-
The base URL.
- $context : string|null = null
-
The context to set the URL for. If null, uses active context.
Tags
setContext()
Set the active context for configuration.
public
static setContext(string $context) : void
Parameters
- $context : string
-
The context name to make active.
setLogger()
Set a PSR-3 logger instance for the SDK.
public
static setLogger(LoggerInterface $logger[, string|null $context = null ]) : void
Parameters
- $logger : LoggerInterface
-
The PSR-3 logger instance
- $context : string|null = null
-
The context to set the logger for. If null, uses active context.
setMiddleware()
Set middleware configuration.
public
static setMiddleware(array<string, array<string, mixed>> $middleware[, string|null $context = null ]) : void
Parameters
- $middleware : array<string, array<string, mixed>>
-
Middleware configuration
- $context : string|null = null
-
The context to set the middleware for (null for active context)
setOAuthClientId()
Set the OAuth client ID.
public
static setOAuthClientId(string $clientId[, string|null $context = null ]) : void
Parameters
- $clientId : string
-
The OAuth client ID.
- $context : string|null = null
-
The context to set the client ID for. If null, uses active context.
setOAuthClientSecret()
Set the OAuth client secret.
public
static setOAuthClientSecret(string $clientSecret[, string|null $context = null ]) : void
Parameters
- $clientSecret : string
-
The OAuth client secret.
- $context : string|null = null
-
The context to set the client secret for. If null, uses active context.
setOAuthExpiresAt()
Set the OAuth token expiration timestamp.
public
static setOAuthExpiresAt(int $expiresAt[, string|null $context = null ]) : void
Parameters
- $expiresAt : int
-
The Unix timestamp when the token expires.
- $context : string|null = null
-
The context to set the expiration for. If null, uses active context.
setOAuthRedirectUri()
Set the OAuth redirect URI.
public
static setOAuthRedirectUri(string $redirectUri[, string|null $context = null ]) : void
Parameters
- $redirectUri : string
-
The OAuth redirect URI.
- $context : string|null = null
-
The context to set the redirect URI for. If null, uses active context.
setOAuthRefreshToken()
Set the OAuth refresh token.
public
static setOAuthRefreshToken(string $refreshToken[, string|null $context = null ]) : void
Parameters
- $refreshToken : string
-
The OAuth refresh token.
- $context : string|null = null
-
The context to set the refresh token for. If null, uses active context.
setOAuthScopes()
Set the OAuth scopes.
public
static setOAuthScopes(array<string|int, string> $scopes[, string|null $context = null ]) : void
Parameters
- $scopes : array<string|int, string>
-
The OAuth scopes.
- $context : string|null = null
-
The context to set the scopes for. If null, uses active context.
setOAuthToken()
Set the OAuth access token.
public
static setOAuthToken(string $token[, string|null $context = null ]) : void
Parameters
- $token : string
-
The OAuth access token.
- $context : string|null = null
-
The context to set the token for. If null, uses active context.
setOAuthUserId()
Set the OAuth user ID.
public
static setOAuthUserId(int $userId[, string|null $context = null ]) : void
Parameters
- $userId : int
-
The OAuth user ID.
- $context : string|null = null
-
The context to set the user ID for. If null, uses active context.
setOAuthUserName()
Set the OAuth user name.
public
static setOAuthUserName(string $userName[, string|null $context = null ]) : void
Parameters
- $userName : string
-
The OAuth user name.
- $context : string|null = null
-
The context to set the user name for. If null, uses active context.
setTimeout()
Set the timeout for API requests.
public
static setTimeout(int $timeout[, string|null $context = null ]) : void
Parameters
- $timeout : int
-
The timeout in seconds.
- $context : string|null = null
-
The context to set the timeout for. If null, uses active context.
stopMasquerading()
Stop masquerading and return to normal authenticated user operations.
public
static stopMasquerading([string|null $context = null ]) : void
Parameters
- $context : string|null = null
-
The context to stop masquerading for. If null, uses active context.
useApiKey()
Switch to API key authentication mode.
public
static useApiKey([string|null $context = null ]) : void
Parameters
- $context : string|null = null
-
The context to switch to API key for. If null, uses active context.
useOAuth()
Switch to OAuth authentication mode.
public
static useOAuth([string|null $context = null ]) : void
Parameters
- $context : string|null = null
-
The context to switch to OAuth for. If null, uses active context.
validate()
Validate the configuration for a specific context.
public
static validate([string|null $context = null ]) : void
Parameters
- $context : string|null = null
-
The context to validate. If null, uses active context.
Tags
syncLegacyValues()
Synchronize legacy static properties with active context values.
private
static syncLegacyValues() : void
This ensures backward compatibility when switching contexts.