diff --git a/lib/classes/Auth.php b/lib/classes/Auth.php index b8c8f8600..101fc8581 100644 --- a/lib/classes/Auth.php +++ b/lib/classes/Auth.php @@ -293,31 +293,6 @@ class Auth extends \Util\Singleton return password_hash($password, self::$passwordOptions['algorithm'], self::$passwordOptions['options']); } - public static function check() - { - return self::getInstance()->isAuthenticated(); - } - - public static function admin() - { - return self::getInstance()->isAdmin(); - } - - public static function user() - { - return self::getInstance()->getUser(); - } - - public static function logout() - { - return self::getInstance()->destory(); - } - - public static function firstModule() - { - return self::getInstance()->getFirstModule(); - } - /** * Restituisce l'elenco degli stati del sistema di autenticazione. * @@ -327,4 +302,52 @@ class Auth extends \Util\Singleton { return self::$status; } + + /** + * Controlla se l'utente è autenticato. + * + * @return bool + */ + public static function check() + { + return self::getInstance()->isAuthenticated(); + } + + /** + * Controlla se l'utente appartiene al gruppo degli Amministratori. + * + * @return bool + */ + public static function admin() + { + return self::getInstance()->isAdmin(); + } + + /** + * Restituisce le informazioni riguardanti l'utente autenticato. + * + * @return array + */ + public static function user() + { + return self::getInstance()->getUser(); + } + + /** + * Distrugge le informazioni riguardanti l'utente autenticato, forzando il logout. + */ + public static function logout() + { + return self::getInstance()->destory(); + } + + /** + * Restituisce il nome del primo modulo navigabile dall'utente autenticato. + * + * @return string + */ + public static function firstModule() + { + return self::getInstance()->getFirstModule(); + } } diff --git a/lib/classes/Database.php b/lib/classes/Database.php index 8edcca715..acb4a95dd 100644 --- a/lib/classes/Database.php +++ b/lib/classes/Database.php @@ -7,19 +7,28 @@ */ class Database extends Util\Singleton { + /** @var string Host del database */ protected $host; + /** @var int Porta di accesso del database */ protected $port; + /** @var string Username di accesso */ protected $username; + /** @var string Password di accesso */ protected $password; + /** @var string Nome del database */ protected $database_name; + /** @var string Charset della comunicazione */ protected $charset; + /** @var array Opzioni riguardanti la comunicazione (PDO) */ protected $option = []; - protected static $connection; + /** @var DebugBar\DataCollector\PDO\TraceablePDO Classe PDO tracciabile */ protected $pdo; + /** @var bool Stato di installazione del database */ protected $is_installed; + /** @var string Versione corrente di MySQL */ protected $mysql_version; /** @@ -37,7 +46,7 @@ class Database extends Util\Singleton * * @return Database */ - protected function __construct($server, $username, $password, $database_name, $charset = 'utf8mb4', $option = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]) + protected function __construct($server, $username, $password, $database_name, $charset = null, $option = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]) { if (is_array($server)) { $host = $server['host']; @@ -62,21 +71,28 @@ class Database extends Util\Singleton if (!empty($this->host) && !empty($this->database_name)) { try { - $this->pdo = new PDO( + $this->pdo = new \DebugBar\DataCollector\PDO\TraceablePDO(new PDO( 'mysql:host='.$this->host.(!empty($this->port) ? ';port='.$this->port : '').';dbname='.$this->database_name, $this->username, $this->password, $this->option - ); + )); + + if (empty($this->charset) && version_compare($this->getMySQLVersion(), '5.5.3') >= 0) { + $this->charset = 'utf8mb4'; + } // Fix per problemi di compatibilità delle password MySQL 4.1+ (da versione precedente) - $this->query('SET SESSION old_passwords = 0'); - //$this->query('SET PASSWORD = PASSWORD('.$this->prepare($this->password).')'); + $this->pdo->query('SET SESSION old_passwords = 0'); + //$this->pdo->query('SET PASSWORD = PASSWORD('.$this->prepare($this->password).')'); - $this->pdo = new \DebugBar\DataCollector\PDO\TraceablePDO($this->pdo); + // Impostazione del charset della comunicazione + if (!empty($this->charset)) { + $this->pdo->query("SET NAMES '".$this->charset."'"); + } - //$this->query("SET NAMES '".$this->charset."'"); - $this->query("SET sql_mode = ''"); + // Reset della modalità di esecuzione MySQL per la sessione corrente + $this->pdo->query("SET sql_mode = ''"); } catch (PDOException $e) { if ($e->getCode() == 1049 || $e->getCode() == 1044) { $e = new PDOException(($e->getCode() == 1049) ? _('Database non esistente!') : _('Credenziali di accesso invalide!')); @@ -494,6 +510,15 @@ class Database extends Util\Singleton } } + /** + * Sincronizza i valori indicati associati alle condizioni, rimuovendo le combinazioni aggiuntive e inserendo quelle non ancora presenti. + * + * @since 2.3 + * + * @param string $table + * @param array $conditions Condizioni di sincronizzazione + * @param array $list Valori da sincronizzare + */ public function sync($table, $conditions, $list) { if ( @@ -517,6 +542,15 @@ class Database extends Util\Singleton } } + /** + * Inserisce le le combinazioni tra i valori indicati e le condizioni. + * + * @since 2.3 + * + * @param string $table + * @param array $conditions Condizioni + * @param array $list Valori da aggiungere + */ public function attach($table, $conditions, $list) { if ( @@ -540,6 +574,15 @@ class Database extends Util\Singleton } } + /** + * Rimuove le le combinazioni tra i valori indicati e le condizioni. + * + * @since 2.3 + * + * @param string $table + * @param array $conditions Condizioni + * @param array $list Valori da rimuovere + */ public function detach($table, $conditions, $list) { if ( diff --git a/lib/classes/Filter.php b/lib/classes/Filter.php index 1ad5afb37..984d998e4 100644 --- a/lib/classes/Filter.php +++ b/lib/classes/Filter.php @@ -10,9 +10,9 @@ class Filter /** @var HTMLPurifier */ protected static $purifier; - /** @var array Lista dei contenuti inviati via POST */ + /** @var array Elenco dei contenuti inviati via POST */ protected static $post; - /** @var array Lista dei contenuti inviati via GET */ + /** @var array Elenco dei contenuti inviati via GET */ protected static $get; /** diff --git a/lib/classes/HTMLBuilder/HTMLBuilder.php b/lib/classes/HTMLBuilder/HTMLBuilder.php index 886c9a7e0..b5e848596 100644 --- a/lib/classes/HTMLBuilder/HTMLBuilder.php +++ b/lib/classes/HTMLBuilder/HTMLBuilder.php @@ -5,6 +5,8 @@ namespace HTMLBuilder; /** * Classe dedicata alla gestione della conversione di tag in codice HTML. * + * Tag di input + * * Campo di input generico: * {[ "type": "text", "required": 1, "value": "$idintervento$" ]} * @@ -16,6 +18,11 @@ namespace HTMLBuilder; * * La sostituzione dei parametri compresi tra $$ viene effettuata attraverso il parametro $records. * + * Tag personalizzati + * + * Struttura per l'inserimento e la visualizzazione dei file: + * {( "name": "filelist_and_upload", "id_module": "3", "id_record": "17" )} + * * @since 2.3 */ class HTMLBuilder @@ -32,7 +39,7 @@ class HTMLBuilder 'manager' => ')}', ]; - /** @var array Lista degli attributi inseriit nel formato che necessitano solo di essere presenti */ + /** @var array Elenco degli attributi che necessitano esclusivamente di essere presenti */ protected static $specifics = [ 'multiple', 'checked', @@ -41,7 +48,7 @@ class HTMLBuilder 'required', ]; - /** @var array Lista dei gestori dei campi HTML */ + /** @var array Elenco dei gestori dei campi HTML */ protected static $handlers = [ 'list' => [ 'default' => 'HTMLBuilder\Handler\DefaultHandler', @@ -63,7 +70,7 @@ class HTMLBuilder 'istance' => null, ]; - /** @var array Lista dei gestori delle strutture HTML */ + /** @var array Elenco dei gestori delle strutture HTML */ protected static $managers = [ 'list' => [ 'filelist_and_upload' => 'HTMLBuilder\Manager\FileManager', @@ -72,6 +79,13 @@ class HTMLBuilder 'instances' => [], ]; + /** + * Esegue la sostituzione dei tag personalizzati con il relativo codice HTML. + * + * @param string $html + * + * @return string + */ public static function replace($html) { preg_match_all('/'.preg_quote(self::$open['manager']).'(.+?)'.preg_quote(self::$close['manager']).'/i', $html, $managers); @@ -93,6 +107,13 @@ class HTMLBuilder return $html; } + /** + * Genera il codice HTML per i singoli tag di input. + * + * @param string $json + * + * @return string + */ protected static function generate($json) { // Elaborazione del formato @@ -118,6 +139,14 @@ class HTMLBuilder return $result; } + /** + * Decodifica i tag personalizzati e li converte in un array basato sul formato JSON. + * + * @param string $string + * @param string $type + * + * @return array + */ protected static function decode($string, $type) { $string = '{'.substr($string, strlen(self::$open[$type]), -strlen(self::$close[$type])).'}'; @@ -127,6 +156,13 @@ class HTMLBuilder return $json; } + /** + * Elabora l'array contenente le impostazioni del tag per renderlo fruibile alla conversione in HTML (per i tag di input). + * + * @param array $json + * + * @return array + */ protected static function elaborate($json) { global $records; @@ -203,6 +239,15 @@ class HTMLBuilder return [$values, $extras]; } + /** + * Sostituisce i placeholder delle impostazioni con i relativi valori (per i tag di input). + * + * @param string $result + * @param array $values + * @param array $extras + * + * @return string + */ protected static function process($result, $values, $extras) { unset($values['label']); @@ -226,6 +271,13 @@ class HTMLBuilder return $result; } + /** + * Restituisce il nome della classe resposabile per la gestione di una determinata tipologia di tag di input. + * + * @param string $input + * + * @return string + */ public static function getHandlerName($input) { $result = empty(self::$handlers['list'][$input]) ? self::$handlers['list']['default'] : self::$handlers['list'][$input]; @@ -233,6 +285,13 @@ class HTMLBuilder return $result; } + /** + * Restituisce l'istanza della classe resposabile per la gestione di una determinata tipologia di tag di input. + * + * @param string $input + * + * @return mixed + */ public static function getHandler($input) { $class = self::getHandlerName($input); @@ -243,6 +302,12 @@ class HTMLBuilder return self::$handlers['instances'][$class]; } + /** + * Imposta una determinata classe come resposabile per la gestione di una determinata tipologia di tag di input. + * + * @param string $input + * @param string|mixed $class + */ public static function setHandler($input, $class) { $original = $class; @@ -255,6 +320,11 @@ class HTMLBuilder } } + /** + * Restituisce l'oggetto responsabile per la costruzione del codice HTML contenente gli input effettivi. + * + * @return mixed + */ public static function getWrapper() { if (empty(self::$wrapper['instance'])) { @@ -265,6 +335,11 @@ class HTMLBuilder return self::$wrapper['instance']; } + /** + * Imposta l'oggetto responsabile per la costruzione del codice HTML contenente gli input effettivi. + * + * @param string|mixed $class + */ public static function setWrapper($class) { $original = $class; @@ -277,6 +352,13 @@ class HTMLBuilder } } + /** + * Restituisce l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato. + * + * @param string $input + * + * @return mixed + */ public static function getManager($input) { $result = null; @@ -293,6 +375,12 @@ class HTMLBuilder return $result; } + /** + * Imposta l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato. + * + * @param string $input + * @param string|mixed $class + */ public static function setManager($input, $class) { $original = $class; @@ -306,6 +394,13 @@ class HTMLBuilder } } +/** + * Predispone un testo per l'inserimento all'interno di un attributo HTML. + * + * @param string $string + * + * @return string + */ function prepareToField($string) { return str_replace('"', '"', $string); diff --git a/lib/classes/Intl/Formatter.php b/lib/classes/Intl/Formatter.php index e39375371..a34f92869 100644 --- a/lib/classes/Intl/Formatter.php +++ b/lib/classes/Intl/Formatter.php @@ -7,16 +7,20 @@ use UnexpectedValueException; use Exception; /** - * Classe per gestire le conversione di date e numeri tra diversi formati. + * Classe per gestire la formattazione di date e numeri in convenzioni differenti. * * @since 2.3 */ class Formatter { + /** @var array Separatori per la formattazione dei numeri */ protected $numberSeparators; + /** @var string Pattern per le date */ protected $datePattern; + /** @var string Pattern per gli orari */ protected $timePattern; + /** @var string Pattern per i timestamp */ protected $timestampPattern; public function __construct($numberSeparators = [], $date = null, $time = null, $timestamp = null) @@ -356,7 +360,7 @@ class Formatter * * @return string */ - public function convertNumberTo($formatter, $value) + public function formatNumberTo($formatter, $value) { $pieces = $this->toNumberObject($value); @@ -379,7 +383,7 @@ class Formatter * * @return string */ - public function convertTimestampTo($formatter, $value) + public function formatTimestampTo($formatter, $value) { $result = $this->toTimestampObject($value); @@ -394,7 +398,7 @@ class Formatter * * @return string */ - public function convertDateTo($formatter, $value) + public function formatDateTo($formatter, $value) { $result = $this->toDateObject($value); @@ -409,7 +413,7 @@ class Formatter * * @return string */ - public function convertTimeTo($formatter, $value) + public function formatTimeTo($formatter, $value) { $result = $this->toTimeObject($value); @@ -424,9 +428,9 @@ class Formatter * * @return string */ - public function getNumberFrom($formatter, $value) + public function formatNumberFrom($formatter, $value) { - return $formatter->convertNumberTo($this, $value); + return $formatter->formatNumberTo($this, $value); } /** @@ -437,9 +441,9 @@ class Formatter * * @return string */ - public function getTimestampFrom($formatter, $value) + public function formatTimestampFrom($formatter, $value) { - return $formatter->convertTimestampTo($this, $value); + return $formatter->formatTimestampTo($this, $value); } /** @@ -450,9 +454,9 @@ class Formatter * * @return string */ - public function getDateFrom($formatter, $value) + public function formatDateFrom($formatter, $value) { - return $formatter->convertDateTo($this, $value); + return $formatter->formatDateTo($this, $value); } /** @@ -463,8 +467,8 @@ class Formatter * * @return string */ - public function getTimeFrom($formatter, $value) + public function formatTimeFrom($formatter, $value) { - return $formatter->convertTimeTo($this, $value); + return $formatter->formatTimeTo($this, $value); } } diff --git a/lib/classes/Modules.php b/lib/classes/Modules.php index efd6f05cd..9d7b3dc7f 100644 --- a/lib/classes/Modules.php +++ b/lib/classes/Modules.php @@ -7,15 +7,23 @@ */ class Modules { + /** @var int Identificativo del modulo corrente */ protected static $current_module; + /** @var int Identificativo dell'elemento corrente */ protected static $current_element; + /** @var array Elenco dei moduli disponibili */ protected static $modules = []; + /** @var array Elenco delle condizioni aggiuntive disponibili */ protected static $additionals = []; + /** @var array Elenco delle query generiche dei moduli */ protected static $queries = []; + /** @var array Elenco gerarchico dei moduli */ protected static $hierarchy = []; + /** @var array Profondità dell'elenco gerarchico */ protected static $depth; + /** @var array Struttura HTML dedicata al menu principale */ protected static $menu; /** diff --git a/lib/classes/Permissions.php b/lib/classes/Permissions.php index 02a6b73e9..43e38fa71 100644 --- a/lib/classes/Permissions.php +++ b/lib/classes/Permissions.php @@ -7,7 +7,9 @@ */ class Permissions { + /** @var array Elenco dei permessi necessari */ protected static $permissions = []; + /** @var bool Condizione riguardante il controllo effettivo dei permessi */ protected static $skip_permissions = false; /** diff --git a/lib/classes/Plugins.php b/lib/classes/Plugins.php index 92c1c413a..cb35a3c91 100644 --- a/lib/classes/Plugins.php +++ b/lib/classes/Plugins.php @@ -7,7 +7,9 @@ */ class Plugins { + /** @var array Elenco dei plugin disponibili */ protected static $plugins = []; + /** @var array Elenco delle query generiche dei plugin */ protected static $queries = []; /** diff --git a/lib/classes/Settings.php b/lib/classes/Settings.php index 1258d2597..f43668f81 100644 --- a/lib/classes/Settings.php +++ b/lib/classes/Settings.php @@ -7,6 +7,7 @@ */ class Settings { + /** @var array Elenco delle impostazioni ottenute */ protected static $values = []; /** diff --git a/lib/classes/Translator.php b/lib/classes/Translator.php index 50dd8e9d1..1a29d7aec 100644 --- a/lib/classes/Translator.php +++ b/lib/classes/Translator.php @@ -236,7 +236,7 @@ class Translator extends Util\Singleton */ public static function numberToEnglish($string) { - return floatval(self::getLocaleFormatter()->convertNumberTo(self::getEnglishFormatter(), $string)); + return floatval(self::getLocaleFormatter()->formatNumberTo(self::getEnglishFormatter(), $string)); } /** @@ -257,7 +257,7 @@ class Translator extends Util\Singleton $string = number_format($string, $decimals, self::getEnglishFormatter()->getNumberSeparators()['decimals'], self::getEnglishFormatter()->getNumberSeparators()['thousands']); } - return self::getEnglishFormatter()->convertNumberTo(self::getLocaleFormatter(), $string); + return self::getEnglishFormatter()->formatNumberTo(self::getLocaleFormatter(), $string); } /** @@ -269,7 +269,7 @@ class Translator extends Util\Singleton */ public static function dateToEnglish($string) { - return self::getLocaleFormatter()->convertDateTo(self::getEnglishFormatter(), $string); + return self::getLocaleFormatter()->formatDateTo(self::getEnglishFormatter(), $string); } /** @@ -286,7 +286,7 @@ class Translator extends Util\Singleton return $fail; } - return self::getEnglishFormatter()->convertDateTo(self::getLocaleFormatter(), $string); + return self::getEnglishFormatter()->formatDateTo(self::getLocaleFormatter(), $string); } /** @@ -298,7 +298,7 @@ class Translator extends Util\Singleton */ public static function timeToEnglish($string) { - return self::getLocaleFormatter()->convertTimeTo(self::getEnglishFormatter(), $string); + return self::getLocaleFormatter()->formatTimeTo(self::getEnglishFormatter(), $string); } /** @@ -315,7 +315,7 @@ class Translator extends Util\Singleton return $fail; } - return self::getEnglishFormatter()->convertTimeTo(self::getLocaleFormatter(), $string); + return self::getEnglishFormatter()->formatTimeTo(self::getLocaleFormatter(), $string); } /** @@ -327,7 +327,7 @@ class Translator extends Util\Singleton */ public static function timestampToEnglish($string) { - return self::getLocaleFormatter()->convertTimestampTo(self::getEnglishFormatter(), $string); + return self::getLocaleFormatter()->formatTimestampTo(self::getEnglishFormatter(), $string); } /** @@ -344,7 +344,7 @@ class Translator extends Util\Singleton return $fail; } - return self::getEnglishFormatter()->convertTimestampTo(self::getLocaleFormatter(), $string); + return self::getEnglishFormatter()->formatTimestampTo(self::getLocaleFormatter(), $string); } /** diff --git a/lib/classes/Update.php b/lib/classes/Update.php index 12eee94b7..cc576562a 100644 --- a/lib/classes/Update.php +++ b/lib/classes/Update.php @@ -7,9 +7,12 @@ */ class Update { - /** @var array Lista degli aggiornamenti da completare */ + /** @var array Elenco degli aggiornamenti da completare */ protected static $updates; + /** + * Controlla la presenza di aggiornamenti e prepara il database per la procedura. + */ protected static function prepareToUpdate() { $database = Database::getConnection(); @@ -53,6 +56,7 @@ class Update $reset = count(array_intersect($results, $versions)) != count($results); + // Memorizzazione degli aggiornamenti if ($reset && $database->isConnected()) { // Individua le versioni che sono state installate, anche solo parzialmente $done = ($database_ready) ? $database->fetchArray('SELECT version, done FROM updates WHERE `done` IS NOT NULL') : []; @@ -85,6 +89,11 @@ class Update } } + /** + * Restituisce l'elenco degli aggiornamento incompleti o non ancora effettuati. + * + * @return array + */ public static function getTodos() { if (!is_array(self::$updates)) { @@ -109,6 +118,11 @@ class Update return self::$updates; } + /** + * Restituisce il primo aggiornamento che deve essere completato. + * + * @return array + */ public static function getUpdate() { if (!empty(self::getTodos())) { @@ -116,21 +130,43 @@ class Update } } + /** + * Controlla che la stringa inserita possieda una struttura corrispondente a quella di una versione. + * + * @param string $string + * + * @return bool + */ public static function isVersion($string) { return preg_match('/^\d+(?:\.\d+)+$/', $string); } + /** + * Controlla ci sono aggiornamenti da fare per il database. + * + * @return bool + */ public static function isUpdateAvailable() { return !empty(self::getTodos()); } + /** + * Controlla se la procedura di aggiornamento è conclusa. + * + * @return bool + */ public static function isUpdateCompleted() { return !self::isUpdateAvailable(); } + /** + * Controlla se l'aggiornamento è in esecuzione. + * + * @return bool + */ public static function isUpdateLocked() { $todos = array_column(self::getTodos(), 'done'); @@ -143,6 +179,11 @@ class Update return false; } + /** + * Restituisce la versione corrente del software gestita dal database. + * + * @return string + */ public static function getDatabaseVersion() { $database = Database::getConnection(); @@ -152,16 +193,33 @@ class Update return $results[0]['version']; } + /** + * Restituisce la versione corrente del software gestita dal file system (file VERSION nella root). + * + * @return string + */ public static function getVersion() { return self::getFile('VERSION'); } + /** + * Restituisce la revisione corrente del software gestita dal file system (file REVISION nella root). + * + * @return string + */ public static function getRevision() { return self::getFile('REVISION'); } + /** + * Ottiene i contenuti di un file. + * + * @param string $file + * + * @return string + */ protected static function getFile($file) { $file = (str_contains($file, DOCROOT.DIRECTORY_SEPARATOR)) ? $file : DOCROOT.DIRECTORY_SEPARATOR.$file; @@ -177,6 +235,11 @@ class Update return trim($result); } + /** + * Effettua una pulizia del database a seguito del completamento dell'aggiornamento. + * + * @return bool + */ public static function updateCleanup() { if (self::isUpdateCompleted()) { @@ -194,6 +257,14 @@ class Update return false; } + /** + * Esegue una precisa sezione dell'aggiornamento fa fare, partendo dalle query e passando poi allo script relativo. + * Prima dell'esecuzione dello script viene inoltre eseguita un'operazione di normalizzazione dei campi delle tabelle del database finalizzata a generalizzare la gestione delle informazioni per l'API: vengono quindi aggiunti i campi created_at e, se permesso dalla versione di MySQL, updated_at ad ogni tabella registrata del software. + * + * @param int $rate Numero di singole query da eseguire dell'aggiornamento corrente + * + * @return array|bool + */ public static function doUpdate($rate = 20) { global $logger; @@ -209,7 +280,7 @@ class Update $database = Database::getConnection(); try { - // Esecuzione query release + // Esecuzione delle query if (!empty($update['sql']) && (!empty($update['done']) || is_null($update['done'])) && file_exists($file.'.sql')) { $queries = readSQLFile($file.'.sql', ';'); $count = count($queries); @@ -224,6 +295,7 @@ class Update $database->query('UPDATE `updates` SET `done` = '.prepare($i + 3).' WHERE id = '.prepare($update['id'])); } + // Restituisce l'indice della prima e dell'ultima query eseguita, con la differenza relativa per l'avanzamento dell'aggiornamento return [ $start, $end, @@ -232,16 +304,18 @@ class Update } } + // Imposta l'aggiornamento nello stato di esecuzione dello script $database->query('UPDATE `updates` SET `done` = 0 WHERE id = '.prepare($update['id'])); // Normalizzazione dei campi per l'API self::executeScript(DOCROOT.'/update/api.php'); - // Esecuzione script release + // Esecuzione dello script if (!empty($update['script']) && file_exists($file.'.php')) { self::executeScript($file.'.php'); } + // Imposta l'aggiornamento come completato $database->query('UPDATE `updates` SET `done` = 1 WHERE id = '.prepare($update['id'])); // Normalizzazione di charset e collation @@ -256,6 +330,12 @@ class Update } } + /** + * Normalizza l'infrastruttura del database indicato, generalizzando charset e collation all'interno del database e delle tabelle ed effettuando una conversione delle tabelle all'engine InnoDB. + * Attenzione: se l'engine InnoDB non è supportato, il server ignorerà la conversione dell'engine e le foreign key del gestionale non funzioneranno adeguatamente. + * + * @param [type] $database_name + */ protected static function normalizeDatabase($database_name) { set_time_limit(0); @@ -301,11 +381,15 @@ class Update } } + /** + * Esegue uno script PHP in un'ambiente il più possibile protetto. + * + * @param string $script + */ protected static function executeScript($script) { - include __DIR__.'/../../core.php'; - - $database = $dbo; + $database = Database::getConnection(); + $dbo = $database; // Informazioni relative a MySQL $mysql_ver = $database->getMySQLVersion(); diff --git a/lib/classes/Util/Singleton.php b/lib/classes/Util/Singleton.php index 38de2d669..c3342aafb 100644 --- a/lib/classes/Util/Singleton.php +++ b/lib/classes/Util/Singleton.php @@ -3,13 +3,18 @@ namespace Util; /** + * Classe astratta per la generazione di oggetti istanziabili una singola volta. + * * @since 2.3 */ abstract class Singleton { - /** @var \Util\Singleton Oggetti istanziati */ + /** @var Util\Singleton Oggetti istanziati */ protected static $instance = []; + /** + * Protected constructor to prevent creating a new instance of the Singleton via the `new` operator from outside of this class. + */ protected function __construct() { } @@ -21,7 +26,7 @@ abstract class Singleton */ public static function getInstance() { - $class = get_called_class(); // late-static-bound class name + $class = get_called_class(); if (!isset(self::$instance[$class])) { self::$instance[$class] = new static(); @@ -30,10 +35,16 @@ abstract class Singleton return self::$instance[$class]; } + /** + * Private clone method to prevent cloning of the instance of the Singleton instance. + */ private function __clone() { } + /** + * Private unserialize method to prevent unserializing of the Singleton instance. + */ private function __wakeup() { } diff --git a/lib/classes/Widgets.php b/lib/classes/Widgets.php index c004124fc..e7e17907e 100644 --- a/lib/classes/Widgets.php +++ b/lib/classes/Widgets.php @@ -7,14 +7,14 @@ */ class Widgets { + /** @var array Elenco delle strutture HTML dei widget */ public static $widgets = []; /** - * Funzione addModuleWidgets - * $id_modulo: modulo in cui ci si trova - * $location: location all'interno del modulo, per esempio controller oppure inserimento/modifica - * Prende da database tutti i widget associati al modulo passato come parametro e li aggiunge con createWidget - * alla pagina. + * Prende da database tutti i widget associati al modulo passato come parametro e li aggiunge alla pagina. + * + * @param string $id_module Modulo a cui aggiungere i widget + * @param string $location Posizione all'interno del modulo */ public static function addModuleWidgets($id_module, $location) { @@ -55,11 +55,14 @@ class Widgets } /** - * Funzione createWidget - * $id_widget: l'id numerico del widget da creare ed inserire nella pagina - * Sa seconda del tipo di widget inserisce il codice HTML per la sua creazione nella pagina. - * Ottiene i dati per la creazione - * del widget da tabella, in maniera da crearli in maniera dinamica a seconda dei campi. + * A seconda del tipo di widget inserisce il codice HTML per la sua creazione nella pagina. + * Ottiene i dati per la creazione del widget dalla tabella, in maniera da crearli in maniera dinamica a seconda dei campi. + * + * @param int $id_widget Identificativo numerico del widget + * @param string $class + * @param int $totalNumber + * + * @return string */ protected static function createWidget($id_widget, $class, $totalNumber = 4) {