summaryrefslogtreecommitdiffstats
path: root/inc/module.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/module.inc.php')
-rw-r--r--inc/module.inc.php69
1 files changed, 36 insertions, 33 deletions
diff --git a/inc/module.inc.php b/inc/module.inc.php
index 55713cd0..b072c4a2 100644
--- a/inc/module.inc.php
+++ b/inc/module.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Module
{
/*
@@ -7,16 +9,16 @@ class Module
*/
/**
- * @var \Module[]
+ * @var ?Module[]
*/
- private static $modules = false;
+ private static $modules = null;
/**
* @param string $name ID/Internal name of module
- * @param false $ignoreDepFail whether to return the module even if some of its dependencies failed
+ * @param bool $ignoreDepFail whether to return the module even if some of its dependencies failed
* @return false|Module
*/
- public static function get($name, $ignoreDepFail = false)
+ public static function get(string $name, bool $ignoreDepFail = false)
{
if (!isset(self::$modules[$name]))
return false;
@@ -28,13 +30,13 @@ class Module
/**
* Check whether given module is available, that is, all dependencies are
* met. If the module is available, it will be activated, so all its classes
- * are available through the auto-loader, and any js or css is added to the
+ * are available through the autoloader, and any js or css is added to the
* final page output.
*
* @param string $moduleId module to check
* @return bool true if module is available and activated
*/
- public static function isAvailable($moduleId, $activate = true)
+ public static function isAvailable(string $moduleId, bool $activate = true): bool
{
$module = self::get($moduleId);
if ($module === false)
@@ -45,7 +47,7 @@ class Module
return !$module->hasMissingDependencies();
}
- private static function resolveDepsByName($name)
+ private static function resolveDepsByName(string $name): bool
{
if (!isset(self::$modules[$name]))
return false;
@@ -57,7 +59,7 @@ class Module
* @param \Module $mod the module to check
* @return boolean true iff module deps are all found and enabled
*/
- private static function resolveDeps($mod)
+ private static function resolveDeps(Module $mod): bool
{
if (!$mod->depsChecked) {
$mod->depsChecked = true;
@@ -75,7 +77,7 @@ class Module
/**
* @return \Module[] List of valid, enabled modules
*/
- public static function getEnabled($sortById = false)
+ public static function getEnabled(bool $sortById = false): array
{
$ret = array();
$sort = array();
@@ -96,7 +98,7 @@ class Module
/**
* @return \Module[] List of all modules, including with missing deps
*/
- public static function getAll()
+ public static function getAll(): array
{
foreach (self::$modules as $module) {
self::resolveDeps($module);
@@ -107,7 +109,7 @@ class Module
/**
* @return \Module[] List of modules that have been activated
*/
- public static function getActivated()
+ public static function getActivated(): array
{
$ret = array();
$i = 0;
@@ -120,9 +122,9 @@ class Module
return $ret;
}
- public static function init()
+ public static function init(): void
{
- if (self::$modules !== false)
+ if (self::$modules !== null)
return;
$dh = opendir('modules');
if ($dh === false)
@@ -143,7 +145,8 @@ class Module
* Non-static
*/
- private $category = false;
+ /** @var ?string category id */
+ private $category = null;
private $clientPlugin = false;
private $depsMissing = false;
private $depsChecked = false;
@@ -161,7 +164,7 @@ class Module
*/
private $scripts = array();
- private function __construct($name)
+ private function __construct(string $name)
{
$file = 'modules/' . $name . '/config.json';
$json = @json_decode(@file_get_contents($file), true);
@@ -173,30 +176,30 @@ class Module
if (isset($json['category']) && is_string($json['category'])) {
$this->category = $json['category'];
}
- $this->collapse = isset($json['collapse']) && (bool)$json['collapse'];
+ $this->collapse = isset($json['collapse']) && $json['collapse'];
if (isset($json['client-plugin'])) {
$this->clientPlugin = (bool)$json['client-plugin'];
}
$this->name = $name;
}
- public function hasMissingDependencies()
+ public function hasMissingDependencies(): bool
{
return $this->depsMissing;
}
- public function newPage()
+ public function newPage(): Page
{
$modulePath = 'modules/' . $this->name . '/page.inc.php';
if (!file_exists($modulePath)) {
- Util::traceError("Module doesn't have a page: " . $modulePath);
+ ErrorHandler::traceError("Module doesn't have a page: " . $modulePath);
}
require_once $modulePath;
$class = 'Page_' . $this->name;
return new $class();
}
- public function activate($depth, $direct)
+ public function activate(?int $depth, ?bool $direct): bool
{
if ($this->depsMissing)
return false;
@@ -228,14 +231,14 @@ class Module
return true;
}
- public function getDependencies()
+ public function getDependencies(): array
{
$deps = array();
$this->getDepsInternal($deps);
return array_keys($deps);
}
- private function getDepsInternal(&$deps)
+ private function getDepsInternal(array &$deps): void
{
if (!is_array($this->dependencies))
return;
@@ -250,49 +253,49 @@ class Module
}
}
- public function getIdentifier()
+ public function getIdentifier(): string
{
return $this->name;
}
- public function getDisplayName()
+ public function getDisplayName(): string
{
- $string = Dictionary::translateFileModule($this->name, 'module', 'module_name');
+ $string = Dictionary::translateFileModule($this->name, 'module', 'module_name', false);
if ($string === false) {
return '!!' . $this->name . '!!';
}
return $string;
}
- public function getPageTitle()
+ public function getPageTitle(): string
{
- $val = Dictionary::translateFileModule($this->name, 'module', 'page_title');
+ $val = Dictionary::translateFileModule($this->name, 'module', 'page_title', false);
if ($val !== false)
return $val;
return $this->getDisplayName();
}
- public function getCategory()
+ public function getCategory(): ?string
{
return $this->category;
}
- public function getCategoryName()
+ public function getCategoryName(): string
{
return Dictionary::getCategoryName($this->category);
}
- public function doCollapse()
+ public function doCollapse(): bool
{
return $this->collapse;
}
- public function getDir()
+ public function getDir(): string
{
return 'modules/' . $this->name;
}
- public function getScripts()
+ public function getScripts(): array
{
if ($this->directActivation && $this->clientPlugin) {
if (!in_array('clientscript.js', $this->scripts) && file_exists($this->getDir() . '/clientscript.js')) {
@@ -303,7 +306,7 @@ class Module
return [];
}
- public function getCss()
+ public function getCss(): array
{
if ($this->directActivation && $this->clientPlugin) {
if (!in_array('style.css', $this->css) && file_exists($this->getDir() . '/style.css')) {