diff --git a/application/class/Application.php b/application/class/Application.php index f92fd92..54b2c9e 100644 --- a/application/class/Application.php +++ b/application/class/Application.php @@ -2,8 +2,6 @@ namespace MVC\Classe; -require APPLICATION_PATH . DIRECTORY_SEPARATOR . "parameters.php"; - class Application { public $http; @@ -12,7 +10,8 @@ class Application public $route; - public function __construct(){ + public function __construct() + { $this->http = new HttpMethod(); $this->browser = new Browser(); @@ -22,13 +21,13 @@ class Application $this->route = $dispacher->route; } - public function launch(){ + public function launch() + { //print_r($this->route); $controlleur = new Controlleur($this); //si la page n'est un controlleur d'action alors on affiche l'écran - if(!$this->url->page['control']) { + if (!$this->url->page['control']) { print($controlleur->vue->ecran); } } - } diff --git a/application/class/Asynchonous.php b/application/class/Asynchonous.php index f6ff387..8063785 100644 --- a/application/class/Asynchonous.php +++ b/application/class/Asynchonous.php @@ -3,10 +3,8 @@ namespace MVC\Classe; - class Asynchonous { - private $_css; private $_javascript; @@ -37,5 +35,4 @@ class Asynchonous { echo $this->_javascript; } - -} \ No newline at end of file +} diff --git a/application/class/Bdd.php b/application/class/Bdd.php index 69001d0..5793f6f 100644 --- a/application/class/Bdd.php +++ b/application/class/Bdd.php @@ -8,34 +8,66 @@ class Bdd public function __construct($bdd = 'bdd1') { - switch($bdd) { + switch ($bdd) { case 'bdd1': - $this->bdd = new PDO(DSN_BDD1, USER_BDD1, PASS_BDD1); + $this->bdd = new \PDO(DSN_BDD1, USER_BDD1, PASS_BDD1); break; case 'bdd2': - $this->bdd = new PDO(DSN_BDD2, USER_BDD2, PASS_BDD2); + $this->bdd = new \PDO(DSN_BDD2, USER_BDD2, PASS_BDD2); break; default: - $this->bdd = new PDO(DSN_BDD_DEFAULT, USER_BDD_DEFAULT, PASS_BDD_DEFAULT); + $this->bdd = new \PDO(DSN_BDD_DEFAULT, USER_BDD_DEFAULT, PASS_BDD_DEFAULT); } + $this->bdd->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); + $this->bdd->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); } - public function faireUneRequete($sql) + public function faireSQLRequete($sql) { - $req = $this->bdd->query($sql, PDO::FETCH_ASSOC); + $req = $this->bdd->query($sql); return $req; } - public function exploiterResultat($res){ + /** + * + * Exemple: + * $sql = "SELECT * FROM annonce WHERE cat_id = :categorie and ann_est_valide = 1"; + * $req = $bdd->faireBindRequete($sql, + * array( + * array('categorie', $categorie, \PDO::PARAM_INT), + * ) + * ); + * $data = $bdd->exploiterResultat($req) + * + * + * @param $sql + * @param array|null $params + * @return bool|\PDOStatement + */ + public function faireBindRequete($sql, array $params = null) + { + $req = $this->bdd->prepare($sql); + if ($params) { + foreach ($params as $value) { + $req->bindParam($value[0], Caracter::normalise_ChaineDeCaracteres($value[1]), $value[2]); + } + } + $req->execute(); + //$req->closeCursor(); + return $req; + } - foreach($res as $data) { + public function exploiterResultat($req) + { + $res = $req->fetchAll(); + foreach ($res as $data) { foreach ($data as $key => $row) { if (is_string($row)) { - $row = Caracter::normalise_ChaineDeCaracteresDownload($row); + $row = Caracter::normalise_ChaineDeCaracteres($row); } $data[$key] = $row; } } return $res; } -} \ No newline at end of file +} diff --git a/application/class/Browser.php b/application/class/Browser.php index 2772fc9..b97344d 100644 --- a/application/class/Browser.php +++ b/application/class/Browser.php @@ -3,10 +3,8 @@ namespace MVC\Classe; - class Browser { - public $user; public $userAgent; @@ -29,43 +27,73 @@ class Browser $t = " " . $t; // Humans / Regular Users - if (strpos($t, 'opera') || strpos($t, 'opr/')) return 'Opera'; - elseif (strpos($t, 'edge')) return 'Edge'; - elseif (strpos($t, 'chrome')) return 'Chrome'; - elseif (strpos($t, 'safari')) return 'Safari'; - elseif (strpos($t, 'firefox')) return 'Firefox'; - elseif (strpos($t, 'msie') || strpos($t, 'trident/7')) return 'Internet Explorer'; + if (strpos($t, 'opera') || strpos($t, 'opr/')) { + return 'Opera'; + } elseif (strpos($t, 'edge')) { + return 'Edge'; + } elseif (strpos($t, 'chrome')) { + return 'Chrome'; + } elseif (strpos($t, 'safari')) { + return 'Safari'; + } elseif (strpos($t, 'firefox')) { + return 'Firefox'; + } elseif (strpos($t, 'msie') || strpos($t, 'trident/7')) { + return 'Internet Explorer'; + } // Application Users - elseif (strpos($t, 'curl')) return '[App] Curl'; + elseif (strpos($t, 'curl')) { + return '[App] Curl'; + } // Search Engines - elseif (strpos($t, 'google')) return '[Bot] Googlebot'; - elseif (strpos($t, 'bing')) return '[Bot] Bingbot'; - elseif (strpos($t, 'slurp')) return '[Bot] Yahoo! Slurp'; - elseif (strpos($t, 'duckduckgo')) return '[Bot] DuckDuckBot'; - elseif (strpos($t, 'baidu')) return '[Bot] Baidu'; - elseif (strpos($t, 'yandex')) return '[Bot] Yandex'; - elseif (strpos($t, 'sogou')) return '[Bot] Sogou'; - elseif (strpos($t, 'exabot')) return '[Bot] Exabot'; - elseif (strpos($t, 'msn')) return '[Bot] MSN'; + elseif (strpos($t, 'google')) { + return '[Bot] Googlebot'; + } elseif (strpos($t, 'bing')) { + return '[Bot] Bingbot'; + } elseif (strpos($t, 'slurp')) { + return '[Bot] Yahoo! Slurp'; + } elseif (strpos($t, 'duckduckgo')) { + return '[Bot] DuckDuckBot'; + } elseif (strpos($t, 'baidu')) { + return '[Bot] Baidu'; + } elseif (strpos($t, 'yandex')) { + return '[Bot] Yandex'; + } elseif (strpos($t, 'sogou')) { + return '[Bot] Sogou'; + } elseif (strpos($t, 'exabot')) { + return '[Bot] Exabot'; + } elseif (strpos($t, 'msn')) { + return '[Bot] MSN'; + } // Common Tools and Bots - elseif (strpos($t, 'mj12bot')) return '[Bot] Majestic'; - elseif (strpos($t, 'ahrefs')) return '[Bot] Ahrefs'; - elseif (strpos($t, 'semrush')) return '[Bot] SEMRush'; - elseif (strpos($t, 'rogerbot') || strpos($t, 'dotbot')) return '[Bot] Moz or OpenSiteExplorer'; - elseif (strpos($t, 'frog') || strpos($t, 'screaming')) return '[Bot] Screaming Frog'; + elseif (strpos($t, 'mj12bot')) { + return '[Bot] Majestic'; + } elseif (strpos($t, 'ahrefs')) { + return '[Bot] Ahrefs'; + } elseif (strpos($t, 'semrush')) { + return '[Bot] SEMRush'; + } elseif (strpos($t, 'rogerbot') || strpos($t, 'dotbot')) { + return '[Bot] Moz or OpenSiteExplorer'; + } elseif (strpos($t, 'frog') || strpos($t, 'screaming')) { + return '[Bot] Screaming Frog'; + } // Miscellaneous - elseif (strpos($t, 'facebook')) return '[Bot] Facebook'; - elseif (strpos($t, 'pinterest')) return '[Bot] Pinterest'; + elseif (strpos($t, 'facebook')) { + return '[Bot] Facebook'; + } elseif (strpos($t, 'pinterest')) { + return '[Bot] Pinterest'; + } // Check for strings commonly used in bot user agents elseif (strpos($t, 'crawler') || strpos($t, 'api') || strpos($t, 'spider') || strpos($t, 'http') || strpos($t, 'bot') || strpos($t, 'archive') || - strpos($t, 'info') || strpos($t, 'data')) return '[Bot] Other'; + strpos($t, 'info') || strpos($t, 'data')) { + return '[Bot] Other'; + } return 'Other (Unknown)'; } @@ -90,4 +118,4 @@ class Browser return false; } } -} \ No newline at end of file +} diff --git a/application/class/Caracter.php b/application/class/Caracter.php index a170028..623f635 100644 --- a/application/class/Caracter.php +++ b/application/class/Caracter.php @@ -3,15 +3,12 @@ namespace MVC\Classe; - use ForceUTF8\Encoding; class Caracter { - - public static function normalise_ChaineDeCaracteresDownload($chaine) + public static function normalise_ChaineDeCaracteres($chaine) { - //return Caracter::remplacerAccents($chaine); return Encoding::fixUTF8(Caracter::fp_stripslashes($chaine)); } @@ -77,4 +74,4 @@ class Caracter $chaine = str_replace('"', '"', $chaine); return $chaine; } -} \ No newline at end of file +} diff --git a/application/class/Controlleur.php b/application/class/Controlleur.php index 5eaa7cc..8d45fbf 100644 --- a/application/class/Controlleur.php +++ b/application/class/Controlleur.php @@ -2,13 +2,13 @@ namespace MVC\Classe; -class Controlleur{ - - public $modele; - public $vue; - - public function __construct($application){ - +class Controlleur +{ + public $modele; + public $vue; + + public function __construct($application) + { switch ($application->http->method) { //cas des requètes PUT et DELETE case 'PUT': @@ -20,8 +20,9 @@ class Controlleur{ $this->callHttpResponse($application); die(); } + // no break default: - if ($application->route != NULL) { + if ($application->route != null) { $conduit = explode('::', $application->route['controller']); require CONDUIT_PATH . DIRECTORY_SEPARATOR . $conduit[0] . '.php'; $conduitRoute = "\\" . $conduit[0]; @@ -30,8 +31,7 @@ class Controlleur{ $class->initialize($application->route); $this->vue = new VueVide(); $this->vue->ecran = $class->$method(); - - } else if ($application->url->page['control']) { + } elseif ($application->url->page['control']) { $url_params = $application->url->page['params']; require TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . '.php'; } else { @@ -39,9 +39,7 @@ class Controlleur{ $this->vue = new Vue($this); } } - - - } + } public function callHttpResponse($application) { @@ -56,11 +54,10 @@ class Controlleur{ $reponse->instanciate($application->url, $application->http->getData()); $method = strtolower($application->http->method); - Logger::addLog('http11'," $reponseHttp app {$application->http->method} request! ( ".get_class($reponse)."->$method() )"); + Logger::addLog('http11', " $reponseHttp app {$application->http->method} request! ( ".get_class($reponse)."->$method() )"); $this->vue = new VueVide(); $this->vue->ecran = $reponse->$method(); return; } - } diff --git a/application/class/ControlleurAction.php b/application/class/ControlleurAction.php index 8ccdc77..82d7368 100644 --- a/application/class/ControlleurAction.php +++ b/application/class/ControlleurAction.php @@ -3,10 +3,8 @@ namespace MVC\Classe; - class ControlleurAction { - public static function inserer($action, $data = array()) { $action = explode('.', $action); @@ -21,13 +19,8 @@ class ControlleurAction } else { return $slot->default($data); } - } else { /*HandleError*/ } - - } - - -} \ No newline at end of file +} diff --git a/application/class/Dispacher.php b/application/class/Dispacher.php index 8ac87d1..5a32e9a 100644 --- a/application/class/Dispacher.php +++ b/application/class/Dispacher.php @@ -9,10 +9,8 @@ use Symfony\Component\Routing\RequestContext as RequestContext; use Symfony\Component\Routing\Loader\YamlFileLoader as YamlFileLoader; use Symfony\Component\Routing\Exception\ResourceNotFoundException; - class Dispacher { - public $route; public function __construct() @@ -20,7 +18,7 @@ class Dispacher //Avoid callback from empty homepage if ($_SERVER['REQUEST_URI'] == '/' || $_SERVER['REQUEST_URI'] == '') { - $this->route = NULL; + $this->route = null; } else { //Test the route from config file try { @@ -38,8 +36,8 @@ class Dispacher $this->route = $parameters; } catch (ResourceNotFoundException $e) { - $this->route = NULL; + $this->route = null; } } } -} \ No newline at end of file +} diff --git a/application/class/Dumper.php b/application/class/Dumper.php index 922a63b..e31c80d 100644 --- a/application/class/Dumper.php +++ b/application/class/Dumper.php @@ -2,10 +2,10 @@ namespace MVC\Classe; - -class Dumper{ - - public static function dump($var){ +class Dumper +{ + public static function dump($var) + { echo "
";
if (is_bool($var)) {
echo ($var) ? "true" : "false";
@@ -14,5 +14,21 @@ class Dumper{
}
echo "";
}
+ /**
+ * Fonction Statique permettant d'initialiser les valeurs de php lors du script courant
+ *
+ * @return void
+ */
+ public static function setPHPvalues()
+ {
+ ini_set('display_errors', 1);
+ ini_set('display_startup_errors', 1);
+ ini_set('memory_limit', -1);
+ ini_set('max_execution_time', 0);
+ ini_set('default_socket_timeout', -1);
-}
\ No newline at end of file
+ error_reporting(E_ALL);
+
+ return;
+ }
+}
diff --git a/application/class/HttpMethod.php b/application/class/HttpMethod.php
index 20ab3e0..3413484 100644
--- a/application/class/HttpMethod.php
+++ b/application/class/HttpMethod.php
@@ -3,17 +3,15 @@
namespace MVC\Classe;
-
class HttpMethod
{
-
public $method;
protected $data;
public function __construct()
{
$this->method = $_SERVER['REQUEST_METHOD'];
- Logger::addLog('http.method',$this->method);
+ Logger::addLog('http.method', $this->method);
$this->acceptResponse();
}
@@ -28,6 +26,7 @@ class HttpMethod
//$this->data['GET'] = ...
//POST DATA except enctype="multipart/form-data"
$this->data = json_decode(file_get_contents("php://input"), true);
+ // no break
case 'DELETE':
//$this->data['GET'] = ...
//POST DATA except enctype="multipart/form-data"
@@ -44,5 +43,4 @@ class HttpMethod
{
return $this->data;
}
-
-}
\ No newline at end of file
+}
diff --git a/application/class/HttpMethodRequete.php b/application/class/HttpMethodRequete.php
index 513c463..284f446 100644
--- a/application/class/HttpMethodRequete.php
+++ b/application/class/HttpMethodRequete.php
@@ -3,7 +3,6 @@
namespace MVC\Classe;
-
/**
* Class Response
*
@@ -165,8 +164,6 @@ class HttpMethodRequete
/** Pour utiliser ce code il faut mettre la variable safe_mode a ON dans php.ini */
//exec($curl_cmd);
-
-
}
/**
@@ -218,5 +215,4 @@ class HttpMethodRequete
{
return $this->replaceContext('DELETE')->addContent($params)->send();
}
-
-}
\ No newline at end of file
+}
diff --git a/application/class/Implement/Action.php b/application/class/Implement/Action.php
index 0c3c415..5c74b35 100644
--- a/application/class/Implement/Action.php
+++ b/application/class/Implement/Action.php
@@ -3,14 +3,10 @@
namespace MVC\Classe\Implement;
-
-
class Action
{
public function render($view, $data)
{
-
-
$paths = new \SplPriorityQueue;
$paths->insert(VIEW_PATH . DIRECTORY_SEPARATOR . "system", 100);
@@ -20,6 +16,5 @@ class Action
$renderer = new \Windwalker\Renderer\BladeRenderer($paths, array('cache_path' => VIEW_PATH . DIRECTORY_SEPARATOR . "cache"));
return $renderer->render($view, $data);
-
}
-}
\ No newline at end of file
+}
diff --git a/application/class/Implement/Conduit.php b/application/class/Implement/Conduit.php
index cc63e1f..165c471 100644
--- a/application/class/Implement/Conduit.php
+++ b/application/class/Implement/Conduit.php
@@ -3,14 +3,12 @@
namespace MVC\Classe\Implement;
-
class Conduit extends Action
{
public function initialize($var)
{
//Export variable from conduit
foreach ($var as $key => $value) {
-
if ($key != "controller") {
if ($key != "_route") {
$this->$key = $value;
@@ -19,4 +17,4 @@ class Conduit extends Action
}
return;
}
-}
\ No newline at end of file
+}
diff --git a/application/class/Implement/Contrat/HttpReponseInterface.php b/application/class/Implement/Contrat/HttpReponseInterface.php
index edd3daa..0a40755 100644
--- a/application/class/Implement/Contrat/HttpReponseInterface.php
+++ b/application/class/Implement/Contrat/HttpReponseInterface.php
@@ -7,4 +7,4 @@ interface HttpReponseInterface
public function put();
public function delete();
-}
\ No newline at end of file
+}
diff --git a/application/class/Implement/Contrat/RestReponseInterface.php b/application/class/Implement/Contrat/RestReponseInterface.php
index e59e93c..2f9586f 100644
--- a/application/class/Implement/Contrat/RestReponseInterface.php
+++ b/application/class/Implement/Contrat/RestReponseInterface.php
@@ -11,4 +11,4 @@ interface RestReponseInterface
public function put();
public function delete();
-}
\ No newline at end of file
+}
diff --git a/application/class/Implement/HttpReponse.php b/application/class/Implement/HttpReponse.php
index 653a20c..0bc2b5c 100644
--- a/application/class/Implement/HttpReponse.php
+++ b/application/class/Implement/HttpReponse.php
@@ -7,7 +7,6 @@ use MVC\Classe\Implement\Contrat\HttpReponseInterface;
class HttpReponse extends Action implements HttpReponseInterface
{
-
public $url;
public $params;
public $data;
@@ -35,12 +34,9 @@ class HttpReponse extends Action implements HttpReponseInterface
public function put()
{
-
}
public function delete()
{
-
}
-
-}
\ No newline at end of file
+}
diff --git a/application/class/Implement/RestReponse.php b/application/class/Implement/RestReponse.php
index b2a495c..350422f 100644
--- a/application/class/Implement/RestReponse.php
+++ b/application/class/Implement/RestReponse.php
@@ -10,7 +10,6 @@ use MVC\Classe\Implement\Contrat\RestReponseInterface;
class RestReponse implements RestReponseInterface
{
-
public $url;
public $params;
public $data;
@@ -38,21 +37,17 @@ class RestReponse implements RestReponseInterface
public function get()
{
-
}
public function post()
{
-
}
public function put()
{
-
}
public function delete()
{
-
}
-}
\ No newline at end of file
+}
diff --git a/application/class/Logger.php b/application/class/Logger.php
index 79334eb..81a1365 100644
--- a/application/class/Logger.php
+++ b/application/class/Logger.php
@@ -3,13 +3,11 @@
namespace MVC\Classe;
-
use Symfony\Component\Validator\Constraints\Date;
class Logger
{
-
- static function addLog($type = 'default', $what = "")
+ public static function addLog($type = 'default', $what = "")
{
$file = LOG_PATH . DIRECTORY_SEPARATOR . 'app.' . $type . '.log';
$browser = new Browser();
@@ -22,5 +20,23 @@ class Logger
file_put_contents($file, $what);
}
}
+ /**
+ * Fonction courante permettant de logger les erreurs obtenues dans un fichier
+ *
+ * @param array $errors
+ * @return void
+ */
+ public static function logCommandErrors(array $errors)
+ {
+ // log connection errors to the web service
+ ob_start();
+ foreach ($errors as $key => $value) {
+ echo "\n\n$key : \n";
+ print_r($value);
+ }
+ $write_string = ob_get_clean();
+ file_put_contents(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "logs" . DIRECTORY_SEPARATOR . "errors_command.log", $write_string);
-}
\ No newline at end of file
+ return;
+ }
+}
diff --git a/application/class/Modele.php b/application/class/Modele.php
index 43ef1d5..d690124 100644
--- a/application/class/Modele.php
+++ b/application/class/Modele.php
@@ -2,20 +2,21 @@
namespace MVC\Classe;
-class Modele{
-
- public $page;
-
- public function __construct($base_param){
-
- if(file_exists(MODELS_PATH.DIRECTORY_SEPARATOR.$base_param['name'].'.model')){
- $fichier = file(MODELS_PATH.DIRECTORY_SEPARATOR.$base_param['name'].'.model');
- foreach ($fichier as $ligne_num => $ligne) {
+class Modele
+{
+ public $page;
+
+ public function __construct($base_param)
+ {
+ if (file_exists(MODELS_PATH.DIRECTORY_SEPARATOR.$base_param['name'].'.model')) {
+ $fichier = file(MODELS_PATH.DIRECTORY_SEPARATOR.$base_param['name'].'.model');
+ foreach ($fichier as $ligne_num => $ligne) {
//on recherche le pattern des parametres
- if (preg_match("#[ ]*([a-zA-Z_+]*)[ ]*[:][ ]*([a-zA-Z0-9-_+'\{\,\ \}\(\)]*[ ]*)#", $ligne, $matches)) {
+ if (preg_match("#[ ]*([a-zA-Z_+]*)[ ]*[:][ ]*([a-zA-Z0-9ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ_+\-'\{\,\ \}\(\)]*[ ]*)#", $ligne, $matches)) {
//on recherche le pattern des tableau dans la valeur du paramètre
+ // dans le cas ou la déclaration se fait sur une seule ligne
if (preg_match("#{.*}#", $matches[2])) {
- if (preg_match_all("#(?