UserFrosting API

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
author

Louis Charette

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

$locatorBasePath

protected string $locatorBasePath

$separator

protected string $separator = '/'

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
mixed

getUri()

Get Resource URI Also adds the prefix stream prefix if it existprefix.

public getUri( ) : string
Return values
string

getBasePath()

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
string

getFilename()

Extract the resource filename (test.txt -> test).

public getFilename( ) : string
Return values
string

getBasename()

Extract the trailing name component (test.txt -> test.txt).

public getBasename( ) : string
Return values
string

getExtension()

Extract the resource extension (test.txt -> txt).

public getExtension( ) : string
Return values
string

getAbsolutePath()

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
string

getLocatorBasePath()

public getLocatorBasePath( ) : string
Return values
string

setLocatorBasePath()

public setLocatorBasePath( $locatorBasePath : string ) : static
Parameters
$locatorBasePath : string
Return values
static

getSeparator()

public getSeparator( ) : string
Return values
string

setSeparator()

public setSeparator( $separator : string ) : static
Parameters
$separator : string
Return values
static

Search results