From 7c1989eb2d125083bdb03eefbe4d415d10478180 Mon Sep 17 00:00:00 2001
From: xdrm-brackets
-
-
-
- CRAP
-
-
+
+
+ CRAP
+
+
+
@@ -79,23 +79,23 @@
-
-
-
- 172.49
-
-
+
+
+ 57.18
+
+
+
@@ -108,15 +108,15 @@
- 2.15
+ 2.01
-
-
+
+
@@ -129,57 +129,57 @@
- 6.84
+ 6.10
-
-
+
+
-
getPDO
-
-
getConfig
-
@@ -204,24 +204,24 @@
-
check
-
@@ -277,47 +277,47 @@
- public function __construct($host, $dbname, $username, $password){
- $this->host = $host;
- $this->dbname = $dbname;
- $this->username = $username;
+ $this->password = $password;
+ $this->host = $host;
+ $this->dbname = $dbname;
+ $this->username = $username; $this->password = $password;
- try{
+ self::$pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password); self::$pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password);
- // On signale que tout s'est bien passe
+ self::$error = ManagerError::Success; self::$error = ManagerError::Success;
-
+ }catch(Exception $e){ }catch(Exception $e){ // On signale qu'il y a une erreur self::$error = ManagerError::PDOConnection;
- }
+ } } /* retourne une instance de la classe */
- public static function getInstance(){
+ if( self::$instance == null || self::$error != ManagerError::Success ){ // Si aucune instance existante OU erreur de connection if( self::$instance == null || self::$error != ManagerError::Success ){ // Si aucune instance existante OU erreur de connection
- // chargement de la configuration du server SQL
- if( !isset($_SERVER['HTTP_HOST']) || isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'socioview' )
+ $conf = json_decode( ResourceDispatcher::getResource(self::$config_path['local']), true );
+ if( !isset($_SERVER['HTTP_HOST']) || isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'socioview' ) $conf = json_decode( ResourceDispatcher::getResource(self::$config_path['local']), true );
- else
+ $conf = json_decode( ResourceDispatcher::getResource(self::$config_path['remote']), true ); $conf = json_decode( ResourceDispatcher::getResource(self::$config_path['remote']), true );
- // creation de l'instance en fonction des parametres
+ self::$instance = new DataBase($conf['host'], $conf['dbname'], $conf['user'], $conf['password']); self::$instance = new DataBase($conf['host'], $conf['dbname'], $conf['user'], $conf['password']);
-
+ } }
-
+ return self::$instance; return self::$instance; } /* retourne la connection statique */
- public static function getPDO(){
+ $instance = self::getInstance(); $instance = self::getInstance();
-
+ return self::$pdo; return self::$pdo; }
@@ -330,9 +330,9 @@
public function getConfig(){
- return array(
- 'host' => $this->host,
- 'username' => $this->username
+ );
+ 'host' => $this->host,
+ 'username' => $this->username ); }
@@ -435,44 +435,44 @@
* */
- public static function check($type, $value){
+ $checker = true; $checker = true; /* [0] On verifie que $value n'est pas nul
- =========================================================*/
+ if( is_null($value) ) return false; if( is_null($value) ) return false; /* [1] Si de type VARCHAR(min, max)
- =========================================================*/
+ if( preg_match('/^varchar\((\d+), ?(\d+)\)$/', $type, $match) ){ if( preg_match('/^varchar\((\d+), ?(\d+)\)$/', $type, $match) ){
- // On recupere la taille min
+ $min = (int) $match[1]; $min = (int) $match[1];
- // On recupere la taille max
+ $max = (int) $match[2]; $max = (int) $match[2];
- // On effectue la verification
+ return $checker && is_string($value) && strlen($value) <= $max && strlen($value) >= $min; return $checker && is_string($value) && strlen($value) <= $max && strlen($value) >= $min; } /* [2] Si de type ARRAY(type_elements)
- =========================================================*/
+ if( preg_match('/^array<(.+)>$/', $type, $match) ){ if( preg_match('/^array<(.+)>$/', $type, $match) ){
- // Si c'est pas un tableau on retourne une erreur
- if( !is_array($value) )
+ return false;
+ if( !is_array($value) ) return false;
-
+ $elements_type = $match[1]; $elements_type = $match[1];
- // On verifie le type pour chaque element
+ foreach($value as $element) foreach($value as $element)
- // Si erreur dans au moins 1 element, on retourne que c'est incorrect
- if( !self::check($elements_type, $element) )
+ return false;
+ if( !self::check($elements_type, $element) ) return false;
- // Si aucune erreur, on retourne que tout est bon
+ return true; return true; }
@@ -480,28 +480,28 @@
=========================================================*/ switch($type){
- // Entier positif (id dans BDD)
+ case 'id': case 'id': return $checker && is_numeric($value) && $value <= 2147483647 && $value >= 0; break;
- // String quelconque (peut etre vide)
- case 'text':
+ return $checker && is_string($value);
+ case 'text': return $checker && is_string($value);
- // Adresse mail (255 caracteres max)
+ case 'mail': case 'mail': return $checker && is_string($value) && strlen($value) <= 50 && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $value); break;
- // Hash sha1
+ case 'sha1': case 'sha1': return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value); break;
-
- default:
+ return false;
+ default: return false;
-
+ } } return $checker;
@@ -559,7 +559,7 @@
Dead Code
- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:22:22 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:48:24 UTC 2016.
diff --git a/phpunit/coverage/ManagerError.php.html b/phpunit/coverage/ManagerError.php.html index c81b112..60b50b6 100755 --- a/phpunit/coverage/ManagerError.php.html +++ b/phpunit/coverage/ManagerError.php.html @@ -247,7 +247,7 @@ Dead Code- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:22:22 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:48:24 UTC 2016.
diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html index 2a0dd9e..6289f3c 100755 --- a/phpunit/coverage/ResourceDispatcher.php.html +++ b/phpunit/coverage/ResourceDispatcher.php.html @@ -262,49 +262,49 @@- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:22:22 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:48:24 UTC 2016.
diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html index 26e7a23..3093c19 100755 --- a/phpunit/coverage/autoloader.php.html +++ b/phpunit/coverage/autoloader.php.html @@ -167,19 +167,19 @@- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:22:22 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Sun Apr 17 10:48:24 UTC 2016.
diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html index 221999b..1394ca1 100755 --- a/phpunit/coverage/index.html +++ b/phpunit/coverage/index.html @@ -43,21 +43,21 @@