UserFrosting API

Assets

Facilitates convenient access to assets and asset bundles within PHP code.

Useful for production and development scenarios.

Tags
see
AssetsTemplatePlugin

for template engine integration.

author

Alex Weissman (https://alexanderweissman.com)

author

Jordan Mele (https://blog.djmm.me)

Table of Contents

$locator ResourceLocatorInterface
$locatorScheme string
$baseUrl string
$assetBundles \UserFrosting\Assets\AssetBundles\AssetBundlesInterface[]
__construct() Constructor. mixed
addAssetBundles() Add asset bundles. mixed
resetAssetBundles() Reset asset bundles, removing all registered assetBundles. mixed
getAssetBundles() Returns the list of assetBundles. \UserFrosting\Assets\AssetBundles\AssetBundlesInterface[]
getJsBundleAssets() Get asset paths within specified JS bundle. string[]
getCssBundleAssets() Get asset paths within specified CSS bundle. string[]
getAbsoluteUrl() Get Asset url. mixed
urlPathToAbsolutePath() Processes a relative path from a URL to an absolute path. Returns null if no file exists at the generated path. null|string
urlPathToStreamUri() Processes a relative path from a URL to a locator stream uri. Returns null if no file exists at the generated path. string
getBaseUrl() Returns base Assets base Url. string
setBaseUrl() Set Asset base Url. $this
getLocatorScheme() Get Asset Locator Scheme. string
setLocatorScheme() Set Asset locator scheme. $this

Properties

$locatorScheme

protected string $locatorScheme

$baseUrl

protected string $baseUrl

$assetBundles

protected \UserFrosting\Assets\AssetBundles\AssetBundlesInterface[] $assetBundles = []

Methods

__construct()

Constructor.

public __construct( $locator : ResourceLocatorInterface , $locatorScheme : string , $baseUrl : string ) : mixed
Parameters
$locator : ResourceLocatorInterface

Resource locator used to find assets.

$locatorScheme : string

Scheme to use in locator.

$baseUrl : string

Sites base URL and optionally assets directory to later use when generating absolute path to an asset.

Return values
mixed

resetAssetBundles()

Reset asset bundles, removing all registered assetBundles.

public resetAssetBundles( ) : mixed
Return values
mixed

getAssetBundles()

Returns the list of assetBundles.

public getAssetBundles( ) : \UserFrosting\Assets\AssetBundles\AssetBundlesInterface[]
Return values
\UserFrosting\Assets\AssetBundles\AssetBundlesInterface[]

getJsBundleAssets()

Get asset paths within specified JS bundle.

public getJsBundleAssets( $bundleName : string ) : string[]
Parameters
$bundleName : string

Bundle name.

Tags
throws
OutOfRangeException

if specified JS asset bundle is not found.

Return values
string[]

getCssBundleAssets()

Get asset paths within specified CSS bundle.

public getCssBundleAssets( $bundleName : string ) : string[]
Parameters
$bundleName : string

Bundle name.

Tags
throws
OutOfRangeException

if specified CSS asset bundle is not found.

Return values
string[]

getAbsoluteUrl()

Get Asset url.

public getAbsoluteUrl( $streamPath : string|array ) : mixed

Transform a locator uri to a url accessible to a browser In other words, transform assets://vendor/bootstrap/js/bootstrap.js to http://example.com/vendor/bootstrap/js/bootstrap.js, replacing the :// with the base url Make sure the ressource exist in the process.

Parameters
$streamPath : string|array

The asset uri

Tags
throws
BadMethodCallException
throws
FileNotFoundException
Return values
mixed

urlPathToAbsolutePath()

Processes a relative path from a URL to an absolute path. Returns null if no file exists at the generated path.

public urlPathToAbsolutePath( $uncleanRelativePath : string ) : null|string

Applies protections against attempts to access restricted files.

Parameters
$uncleanRelativePath : string

Potentially dangerous relative path.

Return values
null|string

urlPathToStreamUri()

Processes a relative path from a URL to a locator stream uri. Returns null if no file exists at the generated path.

public urlPathToStreamUri( $urlPath : string ) : string

Applies protections against attempts to access restricted files.

Parameters
$urlPath : string
Return values
string

getBaseUrl()

Returns base Assets base Url.

public getBaseUrl( ) : string
Return values
string

setBaseUrl()

Set Asset base Url.

public setBaseUrl( $baseUrl : string ) : $this
Parameters
$baseUrl : string
Tags
throws
InvalidArgumentException
Return values
$this

getLocatorScheme()

Get Asset Locator Scheme.

public getLocatorScheme( ) : string
Return values
string

setLocatorScheme()

Set Asset locator scheme.

public setLocatorScheme( $locatorScheme : string ) : $this
Parameters
$locatorScheme : string
Tags
throws
InvalidArgumentException
Return values
$this

Search results