diff options
| author | 2022-01-07 10:05:09 +0100 | |
|---|---|---|
| committer | 2022-01-07 10:05:09 +0100 | |
| commit | ed19445f74c30854c60873cd1df1c38e15fc316b (patch) | |
| tree | 926496a8e1f4d71c8a9b2fd0f87e835037792491 /lib/Minz/ModelPdo.php | |
| parent | f8c5df28ab3f7e68460b74fed11f799c702435b7 (diff) | |
Optimise Minz_ModelPdo::class (#4119)
* - Fix typo,
- remove unnecessary null in property,
- remove unused property,
- add phpDoc,
- add ext PDO in composer.json,
- use strict comparison,
- indentation
* Translate
* Update lib/Minz/ModelPdo.php
Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
* The code is more explicite
* Fix phpstan
* Fix phpstan expect one
* Fix phpstan
* Return in back...
* make fix-all
* Fix exception and more types
* Fix more types
* Remove ext- in composer.json
Co-authored-by: Luc SANCHEZ <l.sanchez-ext@ubitransport.com>
Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'lib/Minz/ModelPdo.php')
| -rw-r--r-- | lib/Minz/ModelPdo.php | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index f183dae10..0f5b9efca 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -6,20 +6,41 @@ */ /** - * La classe Model_sql représente le modèle interragissant avec les bases de données + * The Model_sql class represents the model for interacting with databases. */ class Minz_ModelPdo { /** - * Partage la connexion à la base de données entre toutes les instances. + * Shares the connection to the database between all instances. */ public static $usesSharedPdo = true; - private static $sharedPdo = null; + + /** + * @var Minz_Pdo|null + */ + private static $sharedPdo; + + /** + * @var string|null + */ private static $sharedCurrentUser; + /** + * @var Minz_Pdo|null + */ protected $pdo; + + /** + * @var string|null + */ protected $current_user; + /** + * @return void + * @throws Minz_ConfigurationNamespaceException + * @throws Minz_PDOConnectionException + * @throws PDOException + */ private function dbConnect() { $db = Minz_Configuration::get('system')->db; $driver_options = isset($db['pdo_options']) && is_array($db['pdo_options']) ? $db['pdo_options'] : []; @@ -67,22 +88,25 @@ class Minz_ModelPdo { } /** - * Créé la connexion à la base de données à l'aide des variables - * HOST, BASE, USER et PASS définies dans le fichier de configuration + * Create the connection to the database using the variables + * HOST, BASE, USER and PASS variables defined in the configuration file + * @param string|null $currentUser + * @param Minz_Pdo|null $currentPdo + * @throws Minz_ConfigurationNamespaceException + * @throws Minz_PDOConnectionException */ public function __construct($currentUser = null, $currentPdo = null) { if ($currentUser === null) { $currentUser = Minz_Session::param('currentUser'); } - if ($currentPdo != null) { + if ($currentPdo !== null) { $this->pdo = $currentPdo; return; } if ($currentUser == '') { throw new Minz_PDOConnectionException('Current user must not be empty!', '', Minz_Exception::ERROR); } - if (self::$usesSharedPdo && self::$sharedPdo != null && - ($currentUser == '' || $currentUser === self::$sharedCurrentUser)) { + if (self::$usesSharedPdo && self::$sharedPdo !== null && $currentUser === self::$sharedCurrentUser) { $this->pdo = self::$sharedPdo; $this->current_user = self::$sharedCurrentUser; return; @@ -99,9 +123,11 @@ class Minz_ModelPdo { } catch (PDOException $e) { $ex = $e; if (empty($e->errorInfo[0]) || $e->errorInfo[0] !== '08006') { - //We are only only interested in: SQLSTATE connection exception / connection failure + //We are only interested in: SQLSTATE connection exception / connection failure break; } + } catch (Exception $e) { + $ex = $e; } sleep(2); } @@ -114,19 +140,34 @@ class Minz_ModelPdo { ); } + /** + * @return void + */ public function beginTransaction() { $this->pdo->beginTransaction(); } - public function inTransaction() { + + public function inTransaction(): bool { return $this->pdo->inTransaction(); } + + /** + * @return void + */ public function commit() { $this->pdo->commit(); } + + /** + * @return void + */ public function rollBack() { $this->pdo->rollBack(); } + /** + * @return void + */ public static function clean() { self::$sharedPdo = null; self::$sharedCurrentUser = ''; |
