baserCMS クラスリファレンス

Asset
in package

Class for generating asset URLs.

Table of Contents

Properties

$inflectionType  : string
Inflection type.

Methods

assetTimestamp()  : string
Adds 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.
cssUrl()  : string
Generates URL for given CSS file.
imageUrl()  : string
Generates URL for given image file.
scriptUrl()  : string
Generates URL for given javascript file.
setInflectionType()  : void
Set inflection type to use when inflecting plugin/theme name.
url()  : string
Generates URL for given asset file.
webroot()  : string
Checks if a file exists when theme is used, if no file is found default location is returned.
encodeUrl()  : string
Encodes URL parts using rawurlencode().
inflectString()  : string
Inflect the theme/plugin name to type set using `Asset::setInflectionType()`.
pluginSplit()  : array<string|int, mixed>
Splits a dot syntax plugin name into its plugin and filename.
requestWebroot()  : string
Get webroot from request.

Properties

$inflectionType

Inflection type.

protected static string $inflectionType = 'underscore'

Methods

assetTimestamp()

Adds 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.

public static assetTimestamp(string $path[, bool|string $timestamp = null ]) : string
Parameters
$path : string

The file path to timestamp, the path must be inside App.wwwRoot in Configure.

$timestamp : bool|string = null

If set will overrule the value of Asset.timestamp in Configure.

Return values
string

Path with a timestamp added, or not.

cssUrl()

Generates URL for given CSS file.

public static cssUrl(string $path[, array<string|int, mixed> $options = [] ]) : string

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Parameters
$path : string

Path string.

$options : array<string|int, mixed> = []

Options array. Possible keys: fullBase Return full URL with domain name pathPrefix Path prefix for relative URLs ext Asset extension to append plugin False value will prevent parsing path as a plugin timestamp Overrides the value of Asset.timestamp in 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.

Return values
string

Generated URL

imageUrl()

Generates URL for given image file.

public static imageUrl(string $path[, array<string|int, mixed> $options = [] ]) : string

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Parameters
$path : string

Path string.

$options : array<string|int, mixed> = []

Options array. Possible keys: fullBase Return full URL with domain name pathPrefix Path prefix for relative URLs plugin False value will prevent parsing path as a plugin timestamp Overrides the value of Asset.timestamp in 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.

Return values
string

Generated URL

scriptUrl()

Generates URL for given javascript file.

public static scriptUrl(string $path[, array<string|int, mixed> $options = [] ]) : string

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Parameters
$path : string

Path string.

$options : array<string|int, mixed> = []

Options array. Possible keys: fullBase Return full URL with domain name pathPrefix Path prefix for relative URLs ext Asset extension to append plugin False value will prevent parsing path as a plugin timestamp Overrides the value of Asset.timestamp in 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.

Return values
string

Generated URL

setInflectionType()

Set inflection type to use when inflecting plugin/theme name.

public static setInflectionType(string $inflectionType) : void
Parameters
$inflectionType : string

Inflection type. Value should be a valid method name of Inflector class like 'dasherize' or 'underscore'`.

url()

Generates URL for given asset file.

public static url(string $path[, array<string|int, mixed> $options = [] ]) : string

Depending on options passed provides full URL with domain name. Also calls Asset::assetTimestamp() to add timestamp to local files.

Options:

  • fullBase Boolean true or a string (e.g. https://example) to return full URL with protocol and domain name.
  • pathPrefix Path prefix for relative URLs
  • ext Asset extension to append
  • plugin False value will prevent parsing path as a plugin
  • theme Optional theme name
  • timestamp Overrides the value of Asset.timestamp in 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
$path : string

Path string or URL array

$options : array<string|int, mixed> = []

Options array.

Return values
string

Generated URL

webroot()

Checks if a file exists when theme is used, if no file is found default location is returned.

public static webroot(string $file[, array<string|int, mixed> $options = [] ]) : string

Options:

  • theme Optional theme name
Parameters
$file : string

The file to create a webroot path to.

$options : array<string|int, mixed> = []

Options array.

Return values
string

Web accessible path to file.

encodeUrl()

Encodes URL parts using rawurlencode().

protected static encodeUrl(string $url) : string
Parameters
$url : string

The URL to encode.

Return values
string

inflectString()

Inflect the theme/plugin name to type set using `Asset::setInflectionType()`.

protected static inflectString(string $string) : string
Parameters
$string : string

String inflected.

Return values
string

Inflected name of the theme

pluginSplit()

Splits a dot syntax plugin name into its plugin and filename.

protected static pluginSplit(string $name) : array<string|int, mixed>

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
$name : string

The name you want to plugin split.

Tags
psalm-return

array{string|null, string}

Return values
array<string|int, mixed>

Array with 2 indexes. 0 => plugin name, 1 => filename.

requestWebroot()

Get webroot from request.

protected static requestWebroot() : string
Return values
string

        
On this page

Search results