Resource implements ResourceInterface
Resource Class.
Resources are used to represent a file with info regarding the stream and Location used to find it. When a resource is created, we save the stream used to find it, the location where it was found, and the absolute and relative paths of the file. Using this information, we can later rebuilt the URI used to find this file. Since the full path will contains the relative location of the stream and location inside the filesystem, this information will be removed to recrete the relative 'basepath' of the file, allowing the recreatation of the uri (scheme://basePath).
Tags
Table of Contents
$location | ResourceLocationInterface|null | |
---|---|---|
$path | string | |
$locatorBasePath | string | |
$separator | string | |
$stream | ResourceStreamInterface | |
__construct() | Constructor. | mixed |
getUri() | Get Resource URI Also adds the prefix stream prefix if it existprefix. | string |
getBasePath() | Get the resource base path, aka the path that comes after the `://`. | string |
getFilename() | Extract the resource filename (test.txt -> test). | string |
getBasename() | Extract the trailing name component (test.txt -> test.txt). | string |
getExtension() | Extract the resource extension (test.txt -> txt). | string |
getLocation() | ResourceLocationInterface|null | |
getAbsolutePath() | string | |
__toString() | Magic function to convert the class into the resource absolute path. | string |
getPath() | string | |
getLocatorBasePath() | string | |
setLocatorBasePath() | static | |
getSeparator() | string | |
setSeparator() | static | |
getStream() | ResourceStreamInterface |
Properties
$location
protected
ResourceLocationInterface|null
$location
$path
protected
string
$path
$locatorBasePath
protected
string
$locatorBasePath
$separator
protected
string
$separator
= '/'
$stream
protected
ResourceStreamInterface
$stream
Methods
__construct()
Constructor.
public
__construct(
$stream :
ResourceStreamInterface
[, $location :
ResourceLocationInterface|null
= null ]
, $path :
string
[, $locatorBasePath :
string
= '' ]
)
: mixed
Parameters
- $stream : ResourceStreamInterface
ResourceStream used to locate this resource
- $location : ResourceLocationInterface|null = null
ResourceLocation used to locate this resource
- $path : string
Resource path, relative to the locator base path, and containing the stream and location path
- $locatorBasePath : string = ''
Locator base Path (default to '')
Return values
mixedgetUri()
Get Resource URI Also adds the prefix stream prefix if it existprefix.
public
getUri(
)
: string
Return values
stringgetBasePath()
Get the resource base path, aka the path that comes after the `://`.
public
getBasePath(
)
: string
To to this, we use the relative path and remove
the stream and location base path. For example, a stream with a base path
of data/foo/
, will return a relative path for every resource it find as
data/foo/filename.txt
. So we want to remove the data/foo/
part to
keep only the filename.txt
part, aka the part after the ://
in the URI.
Same goes for the location part, which comes before the stream:
locations/locationA/data/foo
Return values
stringgetFilename()
Extract the resource filename (test.txt -> test).
public
getFilename(
)
: string
Return values
stringgetBasename()
Extract the trailing name component (test.txt -> test.txt).
public
getBasename(
)
: string
Return values
stringgetExtension()
Extract the resource extension (test.txt -> txt).
public
getExtension(
)
: string
Return values
stringgetLocation()
public
getLocation(
)
: ResourceLocationInterface|null
Return values
ResourceLocationInterface|nullgetAbsolutePath()
public
getAbsolutePath(
)
: string
Return values
string__toString()
Magic function to convert the class into the resource absolute path.
public
__toString(
)
: string
Return values
string —The resource absolute path
getPath()
public
getPath(
)
: string
Return values
stringgetLocatorBasePath()
public
getLocatorBasePath(
)
: string
Return values
stringsetLocatorBasePath()
public
setLocatorBasePath(
$locatorBasePath :
string
)
: static
Parameters
- $locatorBasePath : string
Return values
staticgetSeparator()
public
getSeparator(
)
: string
Return values
stringsetSeparator()
public
setSeparator(
$separator :
string
)
: static
Parameters
- $separator : string
Return values
staticgetStream()
public
getStream(
)
: ResourceStreamInterface