Azure
extends AbstractAdapter
in package
Storage adapter Azure class
Tags
Table of Contents
Constants
- DEFAULT_CONTENT_TYPE = 'application/octet-stream'
- Fallback Content-Type sent when the file/blob name has no extension File::getFileMimeType() can resolve (it returns null in that case) - required because the mime type feeds directly into a signed request header, and a null header value breaks request signing with a raw TypeError rather than a clean exception. 'application/octet-stream' is the standard "unknown binary content" MIME type.
- MAX_LIST_PAGES = 10000
- Maximum number of pages walkBlobs() will follow via NextMarker before giving up.
Properties
- $auth : Auth|null
- Azure auth object
- $baseDirectory : string|null
- Storage base directory
- $client : Client|null
- HTTP client
- $directory : string|null
- Current directory
- $handler : HandlerInterface|null
- HTTP client handler, injected for testing (defaults to the real Curl handler when null)
Methods
- __construct() : mixed
- Constructor
- chdir() : void
- Change directory
- copyFile() : void
- Copy file
- copyFileFromExternal() : void
- Copy file from a location external to the current location
- copyFileToExternal() : void
- Copy file to a location external to the current location
- create() : Azure
- Create Azure client
- deleteFile() : void
- Delete file
- fetchFile() : mixed
- Fetch file
- fetchFileInfo() : array<string|int, mixed>
- Fetch file info
- fetchFileStream() : mixed
- Fetch file as a stream resource
- fileExists() : bool
- File exists
- getAuth() : Auth|null
- Get auth
- getBaseDir() : string|null
- Get base directory
- getClient() : Client|null
- Get client
- getCurrentDir() : string|null
- Get current directory
- getFileMTime() : int|string
- Get file modified time
- getFileSize() : int
- Get file size
- getFileType() : string
- Get file type
- getHandler() : HandlerInterface|null
- Get handler
- getTemporaryUrl() : string
- Get a temporary (presigned) URL for the file, valid for $expiresInSeconds
- hasAuth() : bool
- Has auth
- hasClient() : bool
- Has client
- hasHandler() : bool
- Has handler
- initClient() : Azure
- Initialize client
- isDir() : bool
- Check if is a dir
- isFile() : bool
- Check if is a file
- listAll() : array<string|int, mixed>
- List all
- listDirs() : array<string|int, mixed>
- List directories
- listFiles() : array<string|int, mixed>
- List files
- md5File() : string
- Create MD5 checksum of the file
- mkdir() : void
- Make directory
- moveFileFromExternal() : void
- Move file from a location external to the current location
- moveFileToExternal() : void
- Move file to a location external to the current location
- putFile() : void
- Put file
- putFileContents() : void
- Put file contents
- putFileStream() : void
- Put file from a stream resource
- renameFile() : void
- Rename file
- replaceFileContents() : void
- Replace file
- rmdir() : void
- Remove a directory
- setAuth() : Azure
- Set auth
- setBaseDir() : void
- Set base directory
- setClient() : Azure
- Set client
- setHandler() : Azure
- Set handler
- uploadFile() : void
- Upload file from server request $_FILES['file']
- getClientRequest() : Request
- Get the current client's request, narrowed to the concrete request type initClient() always constructs (the client base class declares the wider AbstractRequest return type)
- scrub() : string
- Scrub value of leading dots or slashes
- searchFilter() : array<string|int, mixed>
- Search and filter values
- currentPrefix() : string
- Get the current directory as a blob-name prefix relative to the base directory (the container), i.e. what chdir() has descended into. Returns an empty string when the current directory is the base directory itself.
- resolveUri() : string
- Resolve a filename/directory argument to its full Azure blob URI, accounting for the current directory (chdir()) relative to the base directory
- walkBlobs() : array<string|int, mixed>
- Walk every page of the blob listing for the current directory, returning blob names matching $resourceType ('file' or 'directory')
Constants
DEFAULT_CONTENT_TYPE
Fallback Content-Type sent when the file/blob name has no extension File::getFileMimeType() can resolve (it returns null in that case) - required because the mime type feeds directly into a signed request header, and a null header value breaks request signing with a raw TypeError rather than a clean exception. 'application/octet-stream' is the standard "unknown binary content" MIME type.
protected
string
DEFAULT_CONTENT_TYPE
= 'application/octet-stream'
MAX_LIST_PAGES
Maximum number of pages walkBlobs() will follow via NextMarker before giving up.
protected
int
MAX_LIST_PAGES
= 10000
A generous-but-finite backstop against a malformed or repeating continuation marker causing an infinite loop. Overridable in subclasses (e.g. for fast tests).
Properties
$auth
Azure auth object
protected
Auth|null
$auth
= null
$baseDirectory
Storage base directory
protected
string|null
$baseDirectory
= null
$client
HTTP client
protected
Client|null
$client
= null
$directory
Current directory
protected
string|null
$directory
= null
$handler
HTTP client handler, injected for testing (defaults to the real Curl handler when null)
protected
HandlerInterface|null
$handler
= null
Methods
__construct()
Constructor
public
__construct(string $location, Auth $auth) : mixed
Parameters
- $location : string
- $auth : Auth
chdir()
Change directory
public
chdir([string|null $directory = null ]) : void
Parameters
- $directory : string|null = null
copyFile()
Copy file
public
copyFile(string $sourceFile, string $destFile) : void
Parameters
- $sourceFile : string
- $destFile : string
copyFileFromExternal()
Copy file from a location external to the current location
public
copyFileFromExternal(string $externalFile, string $destFile) : void
Parameters
- $externalFile : string
- $destFile : string
copyFileToExternal()
Copy file to a location external to the current location
public
copyFileToExternal(string $sourceFile, string $externalFile) : void
Parameters
- $sourceFile : string
- $externalFile : string
create()
Create Azure client
public
static create(string $accountName, string $accountKey) : Azure
Parameters
- $accountName : string
- $accountKey : string
Return values
AzuredeleteFile()
Delete file
public
deleteFile(string $filename[, string|null $snapshots = 'include' ]) : void
Parameters
- $filename : string
- $snapshots : string|null = 'include'
-
['include', 'only', null]
fetchFile()
Fetch file
public
fetchFile(string $filename[, bool $raw = true ]) : mixed
Parameters
- $filename : string
- $raw : bool = true
fetchFileInfo()
Fetch file info
public
fetchFileInfo(string $filename) : array<string|int, mixed>
Parameters
- $filename : string
Return values
array<string|int, mixed>fetchFileStream()
Fetch file as a stream resource
public
fetchFileStream(string $filename) : mixed
Parameters
- $filename : string
Tags
fileExists()
File exists
public
fileExists(string $filename) : bool
Parameters
- $filename : string
Return values
boolgetAuth()
Get auth
public
getAuth() : Auth|null
Return values
Auth|nullgetBaseDir()
Get base directory
public
getBaseDir() : string|null
Return values
string|nullgetClient()
Get client
public
getClient() : Client|null
Return values
Client|nullgetCurrentDir()
Get current directory
public
getCurrentDir() : string|null
Return values
string|nullgetFileMTime()
Get file modified time
public
getFileMTime(string $filename) : int|string
Parameters
- $filename : string
Tags
Return values
int|stringgetFileSize()
Get file size
public
getFileSize(string $filename) : int
Parameters
- $filename : string
Tags
Return values
intgetFileType()
Get file type
public
getFileType(string $filename) : string
Parameters
- $filename : string
Tags
Return values
stringgetHandler()
Get handler
public
getHandler() : HandlerInterface|null
Return values
HandlerInterface|nullgetTemporaryUrl()
Get a temporary (presigned) URL for the file, valid for $expiresInSeconds
public
getTemporaryUrl(string $filename[, int $expiresInSeconds = 900 ]) : string
Parameters
- $filename : string
- $expiresInSeconds : int = 900
Return values
stringhasAuth()
Has auth
public
hasAuth() : bool
Return values
boolhasClient()
Has client
public
hasClient() : bool
Return values
boolhasHandler()
Has handler
public
hasHandler() : bool
Return values
boolinitClient()
Initialize client
public
initClient([string $method = 'GET' ][, array<string|int, mixed> $headers = [] ][, bool $auto = true ]) : Azure
Parameters
- $method : string = 'GET'
- $headers : array<string|int, mixed> = []
- $auto : bool = true
Return values
AzureisDir()
Check if is a dir
public
isDir(string $directory) : bool
Parameters
- $directory : string
Return values
boolisFile()
Check if is a file
public
isFile(string $filename) : bool
Parameters
- $filename : string
Return values
boollistAll()
List all
public
listAll([string|null $search = null ][, bool $recursive = false ]) : array<string|int, mixed>
Parameters
- $search : string|null = null
- $recursive : bool = false
Return values
array<string|int, mixed>listDirs()
List directories
public
listDirs([string|null $search = null ][, bool $recursive = false ]) : array<string|int, mixed>
Parameters
- $search : string|null = null
- $recursive : bool = false
Return values
array<string|int, mixed>listFiles()
List files
public
listFiles([string|null $search = null ][, bool $recursive = false ]) : array<string|int, mixed>
Parameters
- $search : string|null = null
- $recursive : bool = false
Return values
array<string|int, mixed>md5File()
Create MD5 checksum of the file
public
md5File(string $filename) : string
Parameters
- $filename : string
Tags
Return values
stringmkdir()
Make directory
public
mkdir(string $directory) : void
Parameters
- $directory : string
moveFileFromExternal()
Move file from a location external to the current location
public
moveFileFromExternal(string $externalFile, string $destFile[, string|null $snapshots = 'include' ]) : void
Parameters
- $externalFile : string
- $destFile : string
- $snapshots : string|null = 'include'
-
['include', 'only', null]
moveFileToExternal()
Move file to a location external to the current location
public
moveFileToExternal(string $sourceFile, string $externalFile) : void
Parameters
- $sourceFile : string
- $externalFile : string
putFile()
Put file
public
putFile(string $fileFrom[, bool $copy = true ]) : void
Parameters
- $fileFrom : string
- $copy : bool = true
Tags
putFileContents()
Put file contents
public
putFileContents(string $filename, string $fileContents) : void
Parameters
- $filename : string
- $fileContents : string
putFileStream()
Put file from a stream resource
public
putFileStream(string $filename, mixed $resource) : void
Parameters
- $filename : string
- $resource : mixed
Tags
renameFile()
Rename file
public
renameFile(string $oldFile, string $newFile) : void
Parameters
- $oldFile : string
- $newFile : string
replaceFileContents()
Replace file
public
replaceFileContents(string $filename, string $fileContents) : void
Parameters
- $filename : string
- $fileContents : string
Tags
rmdir()
Remove a directory
public
rmdir(string $directory) : void
Parameters
- $directory : string
setAuth()
Set auth
public
setAuth(Auth $auth) : Azure
Parameters
- $auth : Auth
Return values
AzuresetBaseDir()
Set base directory
public
setBaseDir([string|null $directory = null ]) : void
Parameters
- $directory : string|null = null
setClient()
Set client
public
setClient(Client $client) : Azure
Parameters
- $client : Client
Return values
AzuresetHandler()
Set handler
public
setHandler(HandlerInterface $handler) : Azure
Parameters
- $handler : HandlerInterface
Return values
AzureuploadFile()
Upload file from server request $_FILES['file']
public
uploadFile(array<string|int, mixed> $file) : void
Parameters
- $file : array<string|int, mixed>
Tags
getClientRequest()
Get the current client's request, narrowed to the concrete request type initClient() always constructs (the client base class declares the wider AbstractRequest return type)
protected
getClientRequest() : Request
Tags
Return values
Requestscrub()
Scrub value of leading dots or slashes
protected
scrub(string $value) : string
Parameters
- $value : string
Tags
Return values
stringsearchFilter()
Search and filter values
protected
searchFilter(array<string|int, mixed> $objects, string $search) : array<string|int, mixed>
Parameters
- $objects : array<string|int, mixed>
- $search : string
Return values
array<string|int, mixed>currentPrefix()
Get the current directory as a blob-name prefix relative to the base directory (the container), i.e. what chdir() has descended into. Returns an empty string when the current directory is the base directory itself.
private
currentPrefix() : string
Return values
stringresolveUri()
Resolve a filename/directory argument to its full Azure blob URI, accounting for the current directory (chdir()) relative to the base directory
private
resolveUri(string $path) : string
The path is scrubbed first, so a caller-supplied filename can neither traverse out of the storage directory via '..' nor escape the container entirely by looking like an absolute path. This is only for internal, current-directory-scoped paths - the *External() methods set their genuinely external URI on the request directly.
Parameters
- $path : string
Tags
Return values
stringwalkBlobs()
Walk every page of the blob listing for the current directory, returning blob names matching $resourceType ('file' or 'directory')
private
walkBlobs(bool $recursive, string $resourceType) : array<string|int, mixed>
Parameters
- $recursive : bool
- $resourceType : string