| Total Complexity | 5 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class Connect |
||
| 10 | { |
||
| 11 | private static $instance; |
||
| 12 | |||
| 13 | public static function getInstance(): ?PDO |
||
| 14 | { |
||
| 15 | if (empty(self::$instance)) { |
||
| 16 | try { |
||
| 17 | |||
| 18 | if(!defined('DATAMANAGER_CONFIG')){ |
||
| 19 | throw new DatamanagerException("Information for connection to the database not defined."); |
||
| 20 | } |
||
| 21 | |||
| 22 | self::$instance = new PDO( |
||
| 23 | DATAMANAGER_CONFIG['driver'] . ':host='.DATAMANAGER_CONFIG['host'] . ';port='.DATAMANAGER_CONFIG['port'] . ';dbname='.DATAMANAGER_CONFIG['database'] . ';charset='.DATAMANAGER_CONFIG['charset'], |
||
| 24 | DATAMANAGER_CONFIG['username'], |
||
| 25 | DATAMANAGER_CONFIG['password'], |
||
| 26 | DATAMANAGER_CONFIG['options'] |
||
| 27 | ); |
||
| 28 | } catch (Exception $exception) { |
||
| 29 | throw new DatamanagerException(str_replace(['SQLSTATE[HY000]',"[{$exception->getCode()}]"], '', $exception->getMessage()), $exception->getCode(), $exception); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | return self::$instance; |
||
| 33 | } |
||
| 34 | |||
| 35 | public static function destroy(){ |
||
| 36 | self::$instance = null; |
||
| 37 | } |
||
| 40 |