class Module implements Serializable (View source)

Abstraction of a PHP Package. Can be used to retrieve information about Silverstripe CMS modules, and other packages managed via composer, by reading their composer.json file.

Constants

deprecated TRIM_CHARS

deprecated CI_PHPUNIT_NINE

Return value of getCIConfig() when module uses PHPUNit 9

deprecated CI_PHPUNIT_FIVE

Return value of getCIConfig() when module uses PHPUNit 5

deprecated CI_UNKNOWN

Return value of getCIConfig() when module does not use any CI

Properties

protected string $path

Full directory path to this module with no trailing slash

protected string $basePath

Base folder of application with no trailing slash

protected array $composerData

Cache of composer data

protected ModuleResource[] $resources

Loaded resources for this module

Methods

public
__construct(string $path, string $basePath)

Construct a module

public
string
getName()

Gets name of this module. Used as unique key and identifier for this module.

public
string|null
getComposerName()

Get full composer name. Will be null if no composer.json is available

public
array
getExposedFolders()

Get list of folders that need to be made available

public
string
getShortName()

Gets "short" name of this module. This is the base directory this module is installed in.

public
string
getResourcesDir()

Name of the resource directory where vendor resources should be exposed as defined by the extra.resources-dir key in the composer file. A blank string will be returned if the key is undefined.

public
string
getPath()

Get base path for this module

public
string
getRelativePath()

Get path relative to base dir.

public
array
__serialize()

No description

public
void
__unserialize(array $data)

No description

public
string
serialize() deprecated

The __serialize() magic method will be automatically used instead of this

public
unserialize(string $serialized) deprecated

The __unserialize() magic method will be automatically used instead of this almost all the time This method will be automatically used if existing serialized data was not saved as an associative array and the PHP version used in less than PHP 9.0

public
activate()

Activate _config.php for this module, if one exists

protected
loadComposer()

No description

public
getResource(string $path)

Get resource for this module

public
string
getRelativeResourcePath(string $path) deprecated

No description

public
string
getResourcePath(string $path) deprecated

No description

public
string
getResourceURL(string $path) deprecated

No description

public
string
hasResource(string $path) deprecated

No description

Details

__construct(string $path, string $basePath)

Construct a module

Parameters

string $path

Absolute filesystem path to this module

string $basePath

base path for the application this module is installed in

string getName()

Gets name of this module. Used as unique key and identifier for this module.

If installed by composer, this will be the full composer name (vendor/name). If not installed by composer this will default to the basedir()

Return Value

string

string|null getComposerName()

Get full composer name. Will be null if no composer.json is available

Return Value

string|null

array getExposedFolders()

Get list of folders that need to be made available

Return Value

array

string getShortName()

Gets "short" name of this module. This is the base directory this module is installed in.

If installed in root, this will be generated from the composer name instead

Return Value

string

string getResourcesDir()

Name of the resource directory where vendor resources should be exposed as defined by the extra.resources-dir key in the composer file. A blank string will be returned if the key is undefined.

Only applicable when reading the composer file for the main project.

Return Value

string

string getPath()

Get base path for this module

Return Value

string

Path with no trailing slash E.g. /var/www/module

string getRelativePath()

Get path relative to base dir.

If module path is base this will be empty string

Return Value

string

Path with trimmed slashes. E.g. vendor/silverstripe/module.

array __serialize()

No description

Return Value

array

void __unserialize(array $data)

No description

Parameters

array $data

Return Value

void

string serialize() deprecated

deprecated 4.12.0 Use __serialize() instead

The __serialize() magic method will be automatically used instead of this

Return Value

string

unserialize(string $serialized) deprecated

deprecated 4.12.0 Use __unserialize() instead

The __unserialize() magic method will be automatically used instead of this almost all the time This method will be automatically used if existing serialized data was not saved as an associative array and the PHP version used in less than PHP 9.0

Parameters

string $serialized

activate()

Activate _config.php for this module, if one exists

protected loadComposer()

No description

Exceptions

Exception

ModuleResource getResource(string $path)

Get resource for this module

Parameters

string $path

Return Value

ModuleResource

string getRelativeResourcePath(string $path) deprecated

deprecated 4.0.1 Use getResource($path)->getRelativePath() instead

No description

Parameters

string $path

Return Value

string

string getResourcePath(string $path) deprecated

deprecated 4.0.1 Use getResource($path)->getPath() instead

No description

Parameters

string $path

Return Value

string

string getResourceURL(string $path) deprecated

deprecated 4.0.1 Use getResource($path)->getURL() instead

No description

Parameters

string $path

Return Value

string

string hasResource(string $path) deprecated

deprecated 4.0.1 Use getResource($path)->exists() instead

No description

Parameters

string $path

Return Value

string