diff --git a/lib/helpers.php b/lib/helpers.php index e86c5fb2f..d3ccbe765 100755 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -23,6 +23,8 @@ * @since 2.4.2 */ use HTMLBuilder\HTMLBuilder; +use Intl\Formatter; +use Models\Module; /** * Restituisce l'oggetto dedicato alla gestione della connessione con il database. @@ -31,7 +33,11 @@ use HTMLBuilder\HTMLBuilder; */ function database() { - return \Database::getConnection(); + if (!app()->has(Database::class)){ + app()->instance(Database::class, new Database()); + } + + return app()->get(Database::class); } /** @@ -131,7 +137,25 @@ function flash() */ function formatter() { - return \AppLegacy::$formatter; + if (!app()->has(Formatter::class)){ + $formatter = new Formatter( + app()->getLocale(), + empty($options['timestamp']) ? 'd/m/Y H:i' : $options['timestamp'], + empty($options['date']) ? 'd/m/Y' : $options['date'], + empty($options['time']) ? 'H:i' : $options['time'], + empty($options['number']) ? [ + 'decimals' => ',', + 'thousands' => '.', + ] : $options['number'] + ); + + $formatter->setPrecision(auth()->check() ? setting('Cifre decimali per importi') : 2); + + app()->instance(Formatter::class, $formatter); + } + + + return app()->get(Formatter::class); } /** @@ -258,3 +282,15 @@ function input(array $json) { return HTMLBuilder::parse($json); } + +/* + * Restituisce il modulo relativo all'identificativo. + * + * @since 2.5 + * + * @return \Modules\Module + */ +function module($identifier) +{ + return Module::pool($identifier); +} diff --git a/src/AppLegacy.php b/src/AppLegacy.php index 557c432ab..72665fc90 100644 --- a/src/AppLegacy.php +++ b/src/AppLegacy.php @@ -244,7 +244,7 @@ class AppLegacy foreach ($sections as $section => $dir) { $result = array_unique(array_merge( self::$assets[$section], - $config['assets'][$section] ?:[] + isset($config['assets']) ? ($config['assets'][$section] ?:[]) :[] )); foreach ($result as $key => $element) { diff --git a/src/Database.php b/src/Database.php index 623e14da5..836601622 100755 --- a/src/Database.php +++ b/src/Database.php @@ -26,7 +26,7 @@ use Illuminate\Support\Facades\Schema; * * @since 2.3 */ -class Database extends Util\Singleton +class Database { /** @var \Illuminate\Database\Capsule\Manager Gestore di connessione Laravel */ protected $capsule; @@ -43,50 +43,13 @@ class Database extends Util\Singleton protected $mysql_version; /** - * Costruisce la nuova connessione al database. - * Ispirato dal framework open-source Medoo. - * - * @param string|array $server - * @param string $username - * @param string $password - * @param string $database_name - * @param string $charset * * @since 2.3 - * */ - protected function __construct($server, $username, $password, $database_name, $charset = null) + public function __construct() { } - /** - * Restituisce la connessione attiva al database, creandola nel caso non esista. - * - * @since 2.3 - * - * @return Database - */ - public static function getConnection($new = false, $data = []) - { - $class = get_called_class(); - - if (empty(parent::$instance[$class]) || !parent::$instance[$class]->isConnected() || $new) { - $config = AppLegacy::getConfig(); - - // Sostituzione degli eventuali valori aggiuntivi - $config = array_merge($config, $data); - - parent::$instance[$class] = new self($config['db_host'], $config['db_username'], $config['db_password'], $config['db_name']); - } - - return parent::$instance[$class]; - } - - public static function getInstance() - { - return self::getConnection(); - } - /** * Restituisce l'oggetto PDO artefice della connessione. *