Class Asset
Class for generating asset URLs.
Property Summary
- 
        $inflectionType protected staticstringInflection type. 
Method Summary
- 
          assetTimestamp() public staticAdds a timestamp to a file based resource based on the value of Asset.timestampin Configure. If Asset.timestamp is true and debug is true, or Asset.timestamp === 'force' a timestamp will be added.
- 
          cssUrl() public staticGenerates URL for given CSS file. 
- 
          encodeUrl() protected staticEncodes URL parts using rawurlencode(). 
- 
          imageUrl() public staticGenerates URL for given image file. 
- 
          inflectString() protected staticInflect the theme/plugin name to type set using Asset::setInflectionType().
- 
          pluginSplit() protected staticSplits a dot syntax plugin name into its plugin and filename. If $name does not have a dot, then index 0 will be null. It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot. 
- 
          requestWebroot() protected staticGet webroot from request. 
- 
          scriptUrl() public staticGenerates URL for given javascript file. 
- 
          setInflectionType() public staticSet inflection type to use when inflecting plugin/theme name. 
- 
          url() public staticGenerates URL for given asset file. 
- 
          webroot() public staticChecks if a file exists when theme is used, if no file is found default location is returned. 
Method Detail
assetTimestamp() ¶ public static
assetTimestamp(string $path, bool|string $timestamp = null): stringAdds a timestamp to a file based resource based on the value of Asset.timestamp in
Configure. If Asset.timestamp is true and debug is true, or Asset.timestamp === 'force'
a timestamp will be added.
Parameters
- 
                string$path
- The file path to timestamp, the path must be inside - App.wwwRootin Configure.
- 
                bool|string$timestamp optional
- If set will overrule the value of - Asset.timestampin Configure.
Returns
stringPath with a timestamp added, or not.
cssUrl() ¶ public static
cssUrl(string $path, array $options = []): stringGenerates URL for given CSS file.
Depending on options passed provides full URL with domain name. Also calls
Asset::assetTimestamp() to add timestamp to local files.
Parameters
- 
                string$path
- Path string. 
- 
                array$options optional
- Options array. Possible keys: - fullBaseReturn full URL with domain name- pathPrefixPath prefix for relative URLs- extAsset extension to append- pluginFalse value will prevent parsing path as a plugin- timestampOverrides the value of- Asset.timestampin Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.
Returns
stringGenerated URL
encodeUrl() ¶ protected static
encodeUrl(string $url): stringEncodes URL parts using rawurlencode().
Parameters
- 
                string$url
- The URL to encode. 
Returns
stringimageUrl() ¶ public static
imageUrl(string $path, array $options = []): stringGenerates URL for given image file.
Depending on options passed provides full URL with domain name. Also calls
Asset::assetTimestamp() to add timestamp to local files.
Parameters
- 
                string$path
- Path string. 
- 
                array$options optional
- Options array. Possible keys: - fullBaseReturn full URL with domain name- pathPrefixPath prefix for relative URLs- pluginFalse value will prevent parsing path as a plugin- timestampOverrides the value of- Asset.timestampin Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.
Returns
stringGenerated URL
inflectString() ¶ protected static
inflectString(string $string): stringInflect the theme/plugin name to type set using Asset::setInflectionType().
Parameters
- 
                string$string
- String inflected. 
Returns
stringInflected name of the theme
pluginSplit() ¶ protected static
pluginSplit(string $name): arraySplits a dot syntax plugin name into its plugin and filename. If $name does not have a dot, then index 0 will be null. It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot.
Parameters
- 
                string$name
- The name you want to plugin split. 
Returns
arrayArray with 2 indexes. 0 => plugin name, 1 => filename.
requestWebroot() ¶ protected static
requestWebroot(): stringGet webroot from request.
Returns
stringscriptUrl() ¶ public static
scriptUrl(string $path, array $options = []): stringGenerates URL for given javascript file.
Depending on options passed provides full URL with domain name. Also calls
Asset::assetTimestamp() to add timestamp to local files.
Parameters
- 
                string$path
- Path string. 
- 
                array$options optional
- Options array. Possible keys: - fullBaseReturn full URL with domain name- pathPrefixPath prefix for relative URLs- extAsset extension to append- pluginFalse value will prevent parsing path as a plugin- timestampOverrides the value of- Asset.timestampin Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.
Returns
stringGenerated URL
setInflectionType() ¶ public static
setInflectionType(string $inflectionType): voidSet inflection type to use when inflecting plugin/theme name.
Parameters
- 
                string$inflectionType
- Inflection type. Value should be a valid method name of - Inflectorclass like- 'dasherize'or- 'underscore'`.
Returns
voidurl() ¶ public static
url(string $path, array $options = []): stringGenerates URL for given asset file.
Depending on options passed provides full URL with domain name. Also calls
Asset::assetTimestamp() to add timestamp to local files.
Options:
- fullBaseBoolean true or a string (e.g. https://example) to return full URL with protocol and domain name.
- pathPrefixPath prefix for relative URLs
- extAsset extension to append
- pluginFalse value will prevent parsing path as a plugin
- themeOptional theme name
- timestampOverrides the value of- Asset.timestampin Configure. Set to false to skip timestamp generation. Set to true to apply timestamps when debug is true. Set to 'force' to always enable timestamping regardless of debug value.
Parameters
- 
                string$path
- Path string or URL array 
- 
                array$options optional
- Options array. 
Returns
stringGenerated URL
webroot() ¶ public static
webroot(string $file, array $options = []): stringChecks if a file exists when theme is used, if no file is found default location is returned.
Options:
- themeOptional theme name
Parameters
- 
                string$file
- The file to create a webroot path to. 
- 
                array$options optional
- Options array. 
Returns
stringWeb accessible path to file.
