Util
in package
Contains misc utility methods.
Tags
Table of Contents
Properties
- $_enabled_modules : array<string|int, mixed>
Methods
- cyrillicToLatin() : string
- Convert Cyrillic to Latin letters.
- determineOrder() : array<string|int, mixed>
- Determine the order of array items with dependencies (denoted by the "after" or "before" field) This is a more generic version of the module sort order determination.
- findBeforeAfter() : array<string|int, mixed>
- Used by order determination to get items before or after a specified item Typically not called on its own - use Util::determineOrder in most cases!
- getLatestNews() : string
- Get the latest Nameless news.
- getSetting() : string|null
- Get a setting from the database table `nl2_settings`.
- isCompatible() : bool
- Determine whether a module/template version is compatible with the current NamelessMC version.
- isModuleEnabled() : bool
- Determine if a specific module is enabled.
- listTimezones() : array<string|int, mixed>
- Get an array containing all timezone lists.
- readFileEnd() : string
- Read the last part of a file, removing a leading partial line if necessary.
- recursiveRemoveDirectory() : bool
- Recursively remove a directory.
- setSetting() : void
- Modify a setting in the database table `nl2_settings`.
- updateCheck() : string|UpdateCheck
- Check for Nameless updates.
Properties
$_enabled_modules
private
static array<string|int, mixed>
$_enabled_modules
= []
Methods
cyrillicToLatin()
Convert Cyrillic to Latin letters.
public
static cyrillicToLatin(string $string) : string
https://en.wikipedia.org/wiki/ISO_9.
Parameters
- $string : string
-
String to convert.
Return values
string —Converted string.
determineOrder()
Determine the order of array items with dependencies (denoted by the "after" or "before" field) This is a more generic version of the module sort order determination.
public
static determineOrder(array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
- $items : array<string|int, mixed>
-
Items (array of items consisting of after, before and name)
Return values
array<string|int, mixed> —Ordered items
findBeforeAfter()
Used by order determination to get items before or after a specified item Typically not called on its own - use Util::determineOrder in most cases!
public
static findBeforeAfter(array<string|int, mixed> $items, string $current) : array<string|int, mixed>
Parameters
- $items : array<string|int, mixed>
-
Names of items already processed
- $current : string
-
Name of current item
Return values
array<string|int, mixed> —Items before and after the current item
getLatestNews()
Get the latest Nameless news.
public
static getLatestNews() : string
Return values
string —NamelessMC news in JSON.
getSetting()
Get a setting from the database table `nl2_settings`.
public
static getSetting(string $setting[, string|null $fallback = null ][, string $module = 'core' ]) : string|null
Use Settings::get() instead. Will be removed in 2.2.0
Parameters
- $setting : string
-
Setting to check.
- $fallback : string|null = null
-
Fallback to return if $setting is not set in DB. Defaults to null.
- $module : string = 'core'
-
Module name to keep settings separate from other modules. Set module to 'Core' for global settings.
Return values
string|null —Setting from DB or $fallback.
isCompatible()
Determine whether a module/template version is compatible with the current NamelessMC version.
public
static isCompatible(string $version, string $nameless_version) : bool
This ignores patch versions, and only checks major and minor versions. For example, 2.0.0 and 2.0.1 are compatible, but 2.0.0 and 2.1.0 are not.
Parameters
- $version : string
-
Version of module/template to check
- $nameless_version : string
-
Current NamelessMC version
Return values
bool —Whether they are compatible or not
isModuleEnabled()
Determine if a specific module is enabled.
public
static isModuleEnabled(string $name) : bool
Parameters
- $name : string
-
Name of module to check for.
Return values
bool —Whether this module is enabled or not.
listTimezones()
Get an array containing all timezone lists.
public
static listTimezones() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —All timezones.
readFileEnd()
Read the last part of a file, removing a leading partial line if necessary.
public
static readFileEnd(string $file_path[, int $max_bytes = 100000 ]) : string
Parameters
- $file_path : string
-
Path to file to read
- $max_bytes : int = 100000
-
Max number of bytes to read at end of file
Return values
string —Read string
recursiveRemoveDirectory()
Recursively remove a directory.
public
static recursiveRemoveDirectory(string $directory) : bool
Parameters
- $directory : string
-
Path to directory to remove.
Return values
bool —Whether the action succeeded or not.
setSetting()
Modify a setting in the database table `nl2_settings`.
public
static setSetting(string $setting, string|null $new_value[, string $module = 'core' ]) : void
Use Settings::set() instead. Will be removed in 2.2.0
Parameters
- $setting : string
-
Setting name.
- $new_value : string|null
-
New setting value, or null to delete
- $module : string = 'core'
-
Module name to keep settings separate from other modules. Set module to 'Core' for global settings.
updateCheck()
Check for Nameless updates.
public
static updateCheck() : string|UpdateCheck
Return values
string|UpdateCheck —Object with information about any updates, or error message.