class ModuleResourceLoader implements TemplateGlobalProvider (View source)

Helper for mapping module resources to paths / urls

Traits

A class that can be instantiated or replaced via DI

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
string
resolvePath(string $resource)

Convert a file of the form "vendor/package:resource" into a BASE_PATH-relative file For other files, return original value

public
string
resolveURL(string $resource)

Resolves resource specifier to the given url.

public static 
string
resourcePath(string $resource)

Template wrapper for resolvePath

public static 
string
resourceURL(string $resource)

Template wrapper for resolveURL

public static 
array
get_template_global_variables()

Called by SSViewer to get a list of global variables to expose to the template, the static method to call on this class to get the value for those variables, and the class to use for casting the returned value for use in a template

public
resolveResource(string $resource)

Return module resource for the given path, if specified as one.

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

string resolvePath(string $resource)

Convert a file of the form "vendor/package:resource" into a BASE_PATH-relative file For other files, return original value

Parameters

string $resource

Return Value

string

string resolveURL(string $resource)

Resolves resource specifier to the given url.

Parameters

string $resource

Return Value

string

static string resourcePath(string $resource)

Template wrapper for resolvePath

Parameters

string $resource

Return Value

string

static string resourceURL(string $resource)

Template wrapper for resolveURL

Parameters

string $resource

Return Value

string

static array get_template_global_variables()

Called by SSViewer to get a list of global variables to expose to the template, the static method to call on this class to get the value for those variables, and the class to use for casting the returned value for use in a template

If the method to call is not included for a particular template variable, a method named the same as the template variable will be called

If the casting class is not specified for a particular template variable, ViewableData::$default_cast is used

The first letter of the template variable is case-insensitive. However the method name is always case sensitive.

Return Value

array

Returns an array of items. Each key => value pair is one of three forms:

  • template name (no key)
  • template name => method name
  • template name => [], where the array can contain these key => value pairs
    • "method" => method name
    • "casting" => casting class to use (i.e., Varchar, HTMLFragment, etc)

ModuleResource|string resolveResource(string $resource)

Return module resource for the given path, if specified as one.

Returns the original resource otherwise.

Parameters

string $resource

Return Value

ModuleResource|string

The resource, or input string if not a module resource