7.7 KiB
SpacesAPI\Space
Represents a space once connected/created
You wouldn't normally instantiate this class directly,
Rather obtain an instance from \SpacesAPI\Spaces::space()
or \SpacesAPI\Spaces::create()
Methods
Name | Description |
---|---|
__construct | Load a space |
addCORSOrigin | Add an origin to the CORS settings on this space |
deleteDirectory | Delete an entire directory, including its contents |
destroy | Destroy/Delete this space |
downloadDirectory | Recursively download an entire directory. |
file | Get an instance of \SpacesAPI\File for a given filename |
getCORS | Get the CORS configuration for the space |
getName | Get the name of this space |
getS3Client | Get the current AWS S3 client instance (internal use) |
isPublic | Is file listing enabled? |
listFiles | List all files in the space (recursively) |
makePrivate | Disable file listing |
makePublic | Enable file listing |
removeCORSOrigin | Remove an origin from the CORS settings on this space |
removeAllCORSOrigins | Delete all CORS rules |
uploadDirectory | Recursively upload an entire directory |
uploadFile | Upload a file |
uploadText | Upload a string of text to file |
Space::__construct
Description
public __construct (\Aws\S3\S3Client $s3, string $name, bool $validate = true)
Load a space
You wouldn't normally call this directly,
rather obtain an instance from \SpacesAPI\Spaces::space()
or \SpacesAPI\Spaces::create()
Parameters
(\Aws\S3\S3Client) $s3
: An authenticated S3Client instance(string) $name
: Space name(bool) $validate
: Check that the space exists. Defaulttrue
Return Values
void
Throws Exceptions
\SpacesAPI\Exceptions\SpaceDoesntExistException
: If validation is true
and the space doesn't exist
Space::addCORSOrigin
Description
public addCORSOrigin (string $origin, array $methods, int $maxAge = 0, array $headers => [])
Add an origin to the CORS settings on this space
Parameters
(string) $origin
: eghttp://example.com
(array) $methods
: Array items must be one ofGET
,PUT
,DELETE
,POST
andHEAD
(int) $maxAge
: Access Control Max Age. Default0
(array) $headers
: Allowed Headers. Default[]
Return Values
void
Space::deleteDirectory
Description
public deleteDirectory (string $path)
Delete an entire directory, including its contents
Parameters
(string) $path
: The directory to delete
Return Values
void
Space::destroy
Description
public destroy (void)
Destroy/Delete this space, along with all files.
Parameters
This function has no parameters.
Return Values
void
Space::downloadDirectory
Description
public downloadDirectory (string $local, string|null $remote = null)
Recursively download an entire directory.
Parameters
(string) $local
: The local directory to save the directories/files in(string|null) $remote
: The remote directory to download.null
to download the entire space. Defaultnull
Return Values
void
Space::file
Description
public file (string $filename, bool $validate = true)
Get an instance of \SpacesAPI\File for a given filename
Parameters
(string) $filename
(bool) $validate
: Whether to validate the file exits. Defaults totrue
Return Values
\SpacesAPI\File
Throws Exceptions
\SpacesAPI\Exceptions\FileDoesntExistException
Thrown if the file doesn't exist
Space::getCORS
Description
public getCORS (void)
Get the CORS configuration for the space
Parameters
This function has no parameters.
Return Values
array|null
An array of CORS rules or
null
if no rules exist
Space::getName
Description
public getName (void)
Get the name of this space
Parameters
This function has no parameters.
Return Values
string
Space::getS3Client
Description
public getS3Client (void)
Get the current AWS S3 client instance
For internal library use. It is unlikely you will need to access this object, but can do so to gain access to the underlying S3Client for andvanced usage.
Parameters
This function has no parameters.
Return Values
\Aws\S3\S3Client
Space::isPublic
Description
public isPublic (void)
Is file listing enabled?
Parameters
This function has no parameters.
Return Values
bool
Space::listFiles
Description
public listFiles (string $directory = "")
List all files in the space (recursively)
Parameters
(string) $directory
: The directory to list files in. Empty string for root directory
Return Values
array
An array of
\SpacesAPI\File
instances indexed by the file name
Space::makePrivate
Description
public makePrivate (void)
Disable file listing
Parameters
This function has no parameters.
Return Values
void
Space::makePublic
Description
public makePublic (void)
Enable file listing
Parameters
This function has no parameters.
Return Values
void
Space::removeCORSOrigin
Description
public removeCORSOrigin (string $origin)
Remove an origin from the CORS settings on this space
Parameters
(string) $origin
: eghttp://example.com
Return Values
void
Space::removeAllCORSOrigins
Description
public deleteAllCORSOrigins (void)
Delete all CORS rules
Parameters
This function has no parameters.
Return Values
void
Space::uploadDirectory
Description
public uploadDirectory (string $local, string|null $remote = null)
Recursively upload an entire directory
Parameters
(string) $local
: The local directory to upload(string|null) $remote
: The remote directory to place the files in.null
to place in the root. Defaultnull
Return Values
void
Space::uploadFile
Description
public uploadFile (string $filepath, string|null $filename = null, string|null $mimeType = null, bool $private = true)
Upload a file
Parameters
(string) $filepath
: The path to the file, including the filename. Relative and absolute paths are accepted.(string|null) $filename
: The remote filename. Ifnull
, the local filename will be used. Defaultnull
(string|null) $mimeType
: The files mimeType. Ifnull
the mimeType is inferred from the file by DigitalOcean Spaces. Defaultnull
(bool)
$private : Iftrue
then the file is private, iffalse
the file is publicly available. Defaulttrue
Return Values
\SpacesAPI\File
Space::uploadText
Description
public uploadText (string $text, string $filename, array $params = [], bool $private = true)
Upload a string of text to file
Parameters
(string) $text
: The text to upload(string) $filename
: The filepath/name to save to(array) $params
: Any extra parameters. See here(bool) $private
: True for the file to be private, false to allow public access
Return Values
\SpacesAPI\File