openstamanager/src/Plugins.php

99 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2018-09-05 15:00:19 +02:00
use Models\Plugin;
/**
2017-09-21 15:51:39 +02:00
* Classe per la gestione delle informazioni relative ai plugin installati.
*
* @since 2.3
*/
class Plugins
{
/** @var array Elenco dei plugin disponibili */
protected static $plugins = [];
2018-08-11 15:37:38 +02:00
protected static $references = [];
/**
2017-09-21 15:51:39 +02:00
* Restituisce tutte le informazioni di tutti i plugin installati.
*
* @return array
*/
public static function getPlugins()
{
if (empty(self::$plugins)) {
$plugins = [];
2018-08-11 15:37:38 +02:00
$references = [];
2018-08-11 15:37:38 +02:00
$modules = Modules::getModules();
foreach ($modules as $module) {
foreach ($module->plugins as $result) {
$plugins[$result['id']] = $result;
$references[$result['name']] = $result['id'];
}
}
self::$plugins = $plugins;
2018-08-11 15:37:38 +02:00
self::$references = $references;
}
return self::$plugins;
}
/**
* Restituisce le informazioni relative a un singolo modulo specificato.
*
2017-09-21 15:51:39 +02:00
* @param string|int $plugin
*
2018-09-05 10:36:41 +02:00
* @return Plugin
*/
public static function get($plugin)
{
2018-08-11 15:37:38 +02:00
$plugins = self::getPlugins();
if (!is_numeric($plugin) && !empty(self::$references[$plugin])) {
$plugin = self::$references[$plugin];
}
2017-09-21 15:51:39 +02:00
2018-08-11 15:37:38 +02:00
return $plugins[$plugin];
}
2018-06-26 09:41:43 +02:00
2018-09-05 10:36:41 +02:00
/**
* Restituisce il modulo attualmente in utilizzo.
*
* @return Plugin
*/
public static function getCurrent()
{
return Plugin::getCurrent($id);
}
/**
* Imposta il modulo attualmente in utilizzo.
*
* @param int $id
*/
public static function setCurrent($id)
{
Plugin::setCurrent($id);
// Fix modulo
$plugin = self::getCurrent();
2018-09-19 10:44:32 +02:00
if (isset($plugin)) {
Modules::setCurrent($plugin->module()->id);
}
2018-09-05 10:36:41 +02:00
}
2018-06-26 09:41:43 +02:00
/**
* Individua il percorso per il file.
*
2018-09-19 10:44:32 +02:00
* @param string|int $element
2018-06-26 09:41:43 +02:00
* @param string $file
*
* @return string|null
*/
2018-09-19 10:44:32 +02:00
public static function filepath($element, $file)
2018-06-26 09:41:43 +02:00
{
2018-09-19 10:44:32 +02:00
return self::get($element)->filepath($file);
2018-06-26 09:41:43 +02:00
}
}