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("#(?[0-9a-zA-Z-_+]*)#", $matches[2], $arrayMatches)) { + if (preg_match_all("#(?[0-9a-zA-ZÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ_+\-]*)#", $matches[2], $arrayMatches)) { $array = array(); foreach ($arrayMatches['capture'] as $val) { if ($val != '') { @@ -28,14 +29,12 @@ class Modele{ } $this->page[$matches[1]] = $matches[2]; } - } $this->page['url_params'] = $base_param['params']; - }else{ - $this->page['name'] = $base_param['name']; - $this->page['description'] = $base_param['description']; - $this->page['params'] = $base_param['params']; - } - } - + } else { + $this->page['name'] = $base_param['name']; + $this->page['description'] = $base_param['description']; + $this->page['params'] = $base_param['params']; + } + } } diff --git a/application/class/Modular.php b/application/class/Modular.php index fe2c8a4..e5f28d1 100644 --- a/application/class/Modular.php +++ b/application/class/Modular.php @@ -2,13 +2,14 @@ namespace MVC\Classe; -class Modular{ - +class Modular +{ private $app = ""; private $subapp_dir = ""; private $subfile = "index.php"; - public function __construct($appName,$type = 'symfony',$options = array()){ + public function __construct($appName, $type = 'symfony', $options = array()) + { //Dumper::dump($options);die(); @@ -17,18 +18,18 @@ class Modular{ case "symfony": break; case "wordpress": - if(isset($options[0])) { + if (isset($options[0])) { switch ($options[0]) { case 'wp-admin': $this->subapp_dir = DIRECTORY_SEPARATOR . $options[0]; - if(isset($options[1])) { + if (isset($options[1])) { switch ($options[1]) { case 'setup-config.php': case 'install.php': $this->subfile = $options[1]; break; default: - if(preg_match('#(.)*\.php#',$options[1])){ + if (preg_match('#(.)*\.php#', $options[1])) { $this->subfile = $options[1]; } } @@ -42,7 +43,7 @@ class Modular{ } break; case "prestashop": - if(isset($options[0])) { + if (isset($options[0])) { switch ($options[0]) { case 'admin-dev': case 'install-dev': @@ -53,20 +54,20 @@ class Modular{ } break; case "phplist": - if(isset($options[0])) { + if (isset($options[0])) { switch ($options[0]) { case 'admin': $this->subapp_dir = DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'lists'. DIRECTORY_SEPARATOR . $options[0] ; break; default: } - }else{ + } else { $this->subapp_dir = DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'lists'; } break; case "wanewsletter": $this->subfile = "install.php"; - if(isset($options[0])) { + if (isset($options[0])) { switch ($options[0]) { case 'admin': $this->subapp_dir = DIRECTORY_SEPARATOR . $options[0] ; @@ -82,11 +83,13 @@ class Modular{ } } - public function getAppName(){ + public function getAppName() + { return $this->app; } - public function load($type = "symfony"){ + public function load($type = "symfony") + { switch ($type) { case "symfony": require MODULES_PATH . DIRECTORY_SEPARATOR . $this->getAppName() . DIRECTORY_SEPARATOR . "public" . DIRECTORY_SEPARATOR . "index.php"; @@ -108,4 +111,4 @@ class Modular{ break; } } -} \ No newline at end of file +} diff --git a/application/class/ModularRegister.php b/application/class/ModularRegister.php index 58c3e9d..12589b3 100644 --- a/application/class/ModularRegister.php +++ b/application/class/ModularRegister.php @@ -2,28 +2,29 @@ namespace MVC\Classe; -class ModularRegister{ - +class ModularRegister +{ public $registry = array(); public $index = array(); - public function __construct(){ - + public function __construct() + { $fichier = file(MODULES_PATH . DIRECTORY_SEPARATOR . "setup" . DIRECTORY_SEPARATOR ."registre.model"); foreach ($fichier as $ligne_num => $ligne) { if (preg_match("#([ ]*[a-zA-Z0-9-_+éèàùïîç]*)[ ]*[:][ ]*([0-9a-zA-Z-_+ 'éèàùïîç.]*[ ]*)#", $ligne, $matches)) { - $this->registry[$matches[1]] = $matches[2]; $this->index[] = $matches[1]; } } } - public function getRegistre(){ + public function getRegistre() + { return $this->registry; } - public function getIndex(){ + public function getIndex() + { return $this->index; } -} \ No newline at end of file +} diff --git a/application/class/Session.php b/application/class/Session.php index beab2c1..ba2e768 100644 --- a/application/class/Session.php +++ b/application/class/Session.php @@ -3,64 +3,62 @@ namespace MVC\Classe; - class Session { - - static public function start() + public static function start() { session_start(); return; } - static public function destroy() + public static function destroy() { session_destroy(); return; } - static public function setUserProfile($userProfile) + public static function setUserProfile($userProfile) { $_SESSION['userProfile'] = $userProfile; return; } - static public function setId($id) + public static function setId($id) { $_SESSION['id'] = $id; return; } - static public function setUserName($username) + public static function setUserName($username) { $_SESSION['username'] = $username; return; } - static public function setToken($token) + public static function setToken($token) { $_SESSION['userToken'] = $token; return; } - static public function setStorage($hybriauthStorage) + public static function setStorage($hybriauthStorage) { $_SESSION['storage'] = $hybriauthStorage; return; } - static public function getStorage() + public static function getStorage() { return $_SESSION['storage'] ; } - static public function setHybridAuth($hybriauth) + public static function setHybridAuth($hybriauth) { $_SESSION['auth'] = $hybriauth; return; } - static public function getHybridAuth() + public static function getHybridAuth() { return $_SESSION['auth'] ; } - static public function isRegistered() + public static function isRegistered() { if (isset($_SESSION['userProfile'])) { return true; @@ -69,7 +67,7 @@ class Session } } - static public function redirectIfNotRegistered() + public static function redirectIfNotRegistered() { if (isset($_SESSION['userProfile'])) { return ; @@ -78,5 +76,4 @@ class Session die('Ooops, something was wrong...'); } } - -} \ No newline at end of file +} diff --git a/application/class/Tri.php b/application/class/Tri.php index 75b3278..874407b 100644 --- a/application/class/Tri.php +++ b/application/class/Tri.php @@ -2,12 +2,13 @@ namespace MVC\Classe; -class Tri{ - - public static function cmp($a,$b){ +class Tri +{ + public static function cmp($a, $b) + { if ($a == $b) { return 0; } return ($a < $b) ? -1 : 1; } -} \ No newline at end of file +} diff --git a/application/class/Url.php b/application/class/Url.php index c976f61..b746571 100644 --- a/application/class/Url.php +++ b/application/class/Url.php @@ -14,56 +14,61 @@ class Url public function __construct($method, $appRequest) { - //on créé le registre des modules symfony + //on créé le registre des modules d'applications tierces $this->registre = new \MVC\Classe\ModularRegister(); //définition des parametres de base $page = array(); - $page['name'] = 'accueil'; + $page['name'] = 'index'; $page['description'] = ""; $page['params'] = array(); $page['control'] = false; $url = parse_url($_SERVER['REQUEST_URI']); - $urlTrim = trim( $url['path'] , '/' ); - $urlParts = explode('/' , $urlTrim ); + $urlTrim = trim($url['path'], '/'); + $urlParts = explode('/', $urlTrim); + + //suppression des sous repertoires du BASE_SERVER_DIRECTORY + $basePath = explode( '/', BASE_SERVER_DIRECTORY); + foreach($basePath as $subDir) { + if ($urlParts[0] == $subDir) { + array_shift($urlParts); + } + } //print_r($urlParts); - if(isset($urlParts[0])) { + if (isset($urlParts[0])) { //Récupération du nom de la page - ($urlParts[0] == 'index' || $urlParts[0] == '') ? $page['name'] = 'accueil' : $page['name'] = $urlParts[0]; - //array_shift($urlParts); + ($urlParts[0] == 'index' || $urlParts[0] == '') ? $page['name'] = 'index' : $page['name'] = $urlParts[0]; unset($urlParts[0]); - }else{ - $page['name'] = 'accueil'; + } else { + $page['name'] = 'index'; } //il se peut que l'on ait des variable avec ? dans l'url - $urlQuery = explode('?' , $page['name'] ); + $urlQuery = explode('?', $page['name']); $page['name'] = $urlQuery[0]; $page['name'] = strtolower($page['name']); - if($page['name'] == 'control'){ + if ($page['name'] == 'control') { $page['control'] = true; - ($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1]; - //array_shift($urlParts); + ($urlParts[1] == 'index' || $urlParts[1] == '') ? $page['name']='index' : $page['name']=$urlParts[1]; unset($urlParts[1]); - } //vérification du nombre de parametres: $numParts = count($urlParts); //s'il n'existe pas autant de clé que de valeurs, ce peut ^etre un module symfony - if ( $numParts%2 != 0 ) { + if ($numParts%2 != 0) { //si un module symfony n'est pas reférencé avec le nom de la page, on renvoi un erreur - if( !in_array($page['name'], $this->registre->getIndex()) ){ + if (!in_array($page['name'], $this->registre->getIndex())) { $page['name'] = 'error'; $page['params'] = array(); $this->page = $page; return; - }else { + } else { foreach ($urlParts as $key => $value) { $values[] = $value; $keys[] = $key; @@ -72,9 +77,9 @@ class Url } //cas d'utilisation normal : il existe autant de clé que de valeurs - } else if ( $numParts != 0 ) { + } elseif ($numParts != 0) { // si c'est un module alors on charge un a un les parametres - if( in_array($page['name'], $this->registre->getIndex()) ){ + if (in_array($page['name'], $this->registre->getIndex())) { foreach ($urlParts as $key => $value) { $values[] = $value; $keys[] = $key; @@ -101,9 +106,9 @@ class Url $page['name'] = lcfirst($page['name']); $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; //verification de l'existence de la page dans les controlleurs - if($page['control']){ + if ($page['control']) { $pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; - }else { + } else { //recherche du fichier controlleur correpondant HTTP1.1 ou HTTP1.0 switch ($method) { //cas des requètes HTTP1.1 @@ -134,10 +139,14 @@ class Url } $this->page = $page; $this->pageFile = $pageFile; - } - static public function link_rewrite($isControlPatern, $page, $params = array()) + public static function asset_rewrite($urlAsset) + { + return '/' . BASE_SERVER_DIRECTORY . $urlAsset; + } + + public static function link_rewrite($isControlPatern, $page, $params = array()) { if ($isControlPatern) { return self::controlLink_rewrite($page, $params); @@ -146,35 +155,34 @@ class Url } } - static public function module_link_rewrite($page, $params = array()) + public static function module_link_rewrite($page, $params = array()) { $stringParams = ''; foreach ($params as $values) { $stringParams .= "/" . $values; } - return '/' . $page . $stringParams; + return '/' . BASE_SERVER_DIRECTORY . $page . $stringParams; } - static private function link_rewrite_slashParam($page, $params = array()) + private static function link_rewrite_slashParam($page, $params = array()) { $stringParams = ''; foreach ($params as $key => $values) { $stringParams .= "/" . $key . "/" . $values; } - return '/' . $page . $stringParams; - + return '/' . BASE_SERVER_DIRECTORY . $page . $stringParams; } - static private function controlLink_rewrite($page, $params = array()) + private static function controlLink_rewrite($page, $params = array()) { $stringParams = ''; foreach ($params as $key => $values) { $stringParams .= "/" . $key . "/" . $values; } - return '/' . 'control' . '/' . $page . $stringParams; + return '/' . BASE_SERVER_DIRECTORY . 'control' . '/' . $page . $stringParams; } - static public function absolute_link_rewrite($isControlPatern, $page, $params = array()) + public static function absolute_link_rewrite($isControlPatern, $page, $params = array()) { $url = $_SERVER['HTTP_HOST']; if ($isControlPatern) { @@ -188,8 +196,6 @@ class Url $scheme = 'http'; } - return ($scheme . "://" . $url . $uri); - + return ($scheme . "://" . BASE_SERVER_DIRECTORY . $url . $uri); } - } diff --git a/application/class/Vue.php b/application/class/Vue.php index 40a66b8..50b3307 100644 --- a/application/class/Vue.php +++ b/application/class/Vue.php @@ -2,44 +2,52 @@ namespace MVC\Classe; -define( "LAYOUT_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "layout"); - - -class Vue{ - - public $ecran; - public $block_body; - - public function __construct($application){ - +class Vue +{ + public $ecran; + public $block_body; + + public function __construct($application) + { $templateData = array(); - extract( $application->modele->page ); + extract($application->modele->page); - ob_start(); - if(file_exists(VIEW_PATH.DIRECTORY_SEPARATOR."view".DIRECTORY_SEPARATOR.$name.".blade.php")) { + ob_start(); + if (file_exists(VIEW_PATH.DIRECTORY_SEPARATOR."view".DIRECTORY_SEPARATOR.$name.".blade.php")) { //l'inclusion du controlleur doit renvoyer le tableau $templateData require CONTROLLER_PATH . DIRECTORY_SEPARATOR . $name . '.php'; - //TEMPLATING BLADE + + + + //TEMPLATING BLADE $paths = new \SplPriorityQueue; $paths->insert(VIEW_PATH . DIRECTORY_SEPARATOR . "system", 100); $paths->insert(VIEW_PATH . DIRECTORY_SEPARATOR . "layout", 200); $paths->insert(VIEW_PATH . DIRECTORY_SEPARATOR . "view", 300); - $renderer = new \Windwalker\Renderer\BladeRenderer($paths, array('cache_path' => VIEW_PATH . DIRECTORY_SEPARATOR . "cache")); + if(!isset($engine)){$engine = 'blade';} + + switch ($engine){ + case 'twig': + $renderer = new \Windwalker\Renderer\TwigRenderer($paths); + $name .= '.html'; + break; + case 'blade': + default: + $renderer = new \Windwalker\Renderer\BladeRenderer($paths, array('cache_path' => VIEW_PATH . DIRECTORY_SEPARATOR . "cache")); + } + //de base on ajoute les parametres du .model et ceux provenant de l'url foreach ($application->modele->page as $key => $value) { $templateData[$key] = $value; } echo $renderer->render($name, $templateData); - - }else{ + } else { include CONTROLLER_PATH . DIRECTORY_SEPARATOR . $name . '.php'; } $this->ecran = ob_get_clean(); - - } - + } } diff --git a/application/class/VueVide.php b/application/class/VueVide.php index 29547b0..e392203 100644 --- a/application/class/VueVide.php +++ b/application/class/VueVide.php @@ -2,14 +2,11 @@ namespace MVC\Classe; - class VueVide { - public $ecran; public function __construct() { } - } diff --git a/application/config/define-constantes.php b/application/config/define-constantes.php index a1a6476..e02e5a5 100644 --- a/application/config/define-constantes.php +++ b/application/config/define-constantes.php @@ -5,6 +5,7 @@ define("CONDUIT_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRE define("CONTROLLERS_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs"); define("CONFIG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "config"); define("LOG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "logs"); +define("LAYOUT_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "layout"); define("ACTION_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "actions"); define("MODELS_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "modeles"); define("VIEW_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "vues"); @@ -12,4 +13,10 @@ define("CONTROLLER_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . D define("TRAITEMENT_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "traitements"); define("PUBLIC_PATH", dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "public"); define("CONSOLE_PATH", dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "console"); -define("DATA_PATH", dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "data"); \ No newline at end of file +define("DATA_PATH", dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "data"); + +// De base laisser vide, +// sauf si l'application est hebergé sur de multiples sous-repertoire en ajoutant le slash_final +// par exemple : "my-app/" +// ou : "my-app/dev/ +define("BASE_SERVER_DIRECTORY", ""); diff --git a/application/include/vues/system/system.blade.php b/application/include/vues/system/system.blade.php index b297a18..dafc74c 100644 --- a/application/include/vues/system/system.blade.php +++ b/application/include/vues/system/system.blade.php @@ -9,9 +9,9 @@ @section('top-css') - - - + + + @show @@ -24,11 +24,11 @@ @yield('body') @section('bottom-javascript') - - - + + + - + @show diff --git a/application/include/vues/view/beers.blade.php b/application/include/vues/view/beers.blade.php index ad9a33e..b25da27 100644 --- a/application/include/vues/view/beers.blade.php +++ b/application/include/vues/view/beers.blade.php @@ -31,7 +31,7 @@ Donate via PayPal - + @endsection \ No newline at end of file diff --git a/application/include/vues/view/cgu.blade.php b/application/include/vues/view/cgu.blade.php index f9d069e..9c6b246 100644 --- a/application/include/vues/view/cgu.blade.php +++ b/application/include/vues/view/cgu.blade.php @@ -7,9 +7,10 @@ @section('content')

Conditions Générale de l'application:

- +
+

1. Cette application est en phase de test et n'est qu'un test.


2. Si cela est autre chose se référer au point 1.


-

3. Cette application permet le developpement d'un frame-work propre dont la documentation sera écrite en MarkDown et publié par un moteur interne à l'application


+

3. Cette application peut permettre le développement du framework (SAND) dont la documentation sera écrite en MarkDown et publié par un moteur interne au framework.


@endsection \ No newline at end of file diff --git a/application/include/vues/view/policy.blade.php b/application/include/vues/view/policy.blade.php index 2fbee9a..7b51fcd 100644 --- a/application/include/vues/view/policy.blade.php +++ b/application/include/vues/view/policy.blade.php @@ -7,11 +7,16 @@ @section('content')

Politique Générale de Sécurité

+
+
+

1. Ce FrameWork est le fruit d'un travail personnel.


+

2. Certaines Parties du Framework sont le fruit d'un travail aboutit d'autres personnes


+

3. Ce Framework sera publié en open-source sous licence CC Universal ou licence CC-by-SA suivant la disponibilité de l'auteur.

+
+ ... +
+
-

1. Ce FrameWork est le fruit d'un travail personnel.


-

2. Ce Framework est le fruit du travail aboutit de plusieurs personnes


-

3. Ce Framework sera open-source sous licence CC Universal.



- -

Si cela ne vous plait pas veuillez envoyer un courriel à emmanuel.roy@infoartsmedia.fr et nous en parlerons le plus calmement possible.

+

Si cela ne vous plait pas veuillez envoyer un courriel à l'auteur et nous en parlerons le plus calmement possible.

@endsection \ No newline at end of file