Assets
Facilitates convenient access to assets and asset bundles within PHP code.
Useful for production and development scenarios.
Tags
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
$locator
protected
ResourceLocatorInterface
$locator
$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
mixedaddAssetBundles()
Add asset bundles.
public
addAssetBundles(
$assetBundles :
AssetBundlesInterface
)
: mixed
Parameters
- $assetBundles : AssetBundlesInterface
Return values
mixedresetAssetBundles()
Reset asset bundles, removing all registered assetBundles.
public
resetAssetBundles(
)
: mixed
Return values
mixedgetAssetBundles()
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
Return values
string[]getCssBundleAssets()
Get asset paths within specified CSS bundle.
public
getCssBundleAssets(
$bundleName :
string
)
: string[]
Parameters
- $bundleName : string
Bundle name.
Tags
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
Return values
mixedurlPathToAbsolutePath()
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|stringurlPathToStreamUri()
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
stringgetBaseUrl()
Returns base Assets base Url.
public
getBaseUrl(
)
: string
Return values
stringsetBaseUrl()
Set Asset base Url.
public
setBaseUrl(
$baseUrl :
string
)
: $this
Parameters
- $baseUrl : string
Tags
Return values
$thisgetLocatorScheme()
Get Asset Locator Scheme.
public
getLocatorScheme(
)
: string
Return values
stringsetLocatorScheme()
Set Asset locator scheme.
public
setLocatorScheme(
$locatorScheme :
string
)
: $this
Parameters
- $locatorScheme : string