From 8c10efc6495e595405f0219a3233b4432038d9b6 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Tue, 14 Nov 2023 10:11:06 +0100 Subject: [PATCH 01/14] add Admin et Parser changing --- fluxRSS/metier/Admin.php | 0 fluxRSS/model/Parser.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 fluxRSS/metier/Admin.php mode change 100644 => 100755 fluxRSS/model/Parser.php diff --git a/fluxRSS/metier/Admin.php b/fluxRSS/metier/Admin.php old mode 100644 new mode 100755 diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php old mode 100644 new mode 100755 From 08b0a4d9061c72e3a4c75f3a1064b3ce2497b987 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 10:09:52 +0100 Subject: [PATCH 02/14] modification ArticleGateway, Connection, Controleur and view listArticle --- fluxRSS/DAL/ArticleGateway.php | 19 ++++++++++--------- fluxRSS/DAL/Connection.php | 9 +++++++-- fluxRSS/controleur/Controleur.php | 8 +++++--- fluxRSS/model/ArticleModel.php | 4 ++-- fluxRSS/templates/listArticle.html | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/fluxRSS/DAL/ArticleGateway.php b/fluxRSS/DAL/ArticleGateway.php index a36f565..ad5bba5 100755 --- a/fluxRSS/DAL/ArticleGateway.php +++ b/fluxRSS/DAL/ArticleGateway.php @@ -22,15 +22,16 @@ class ArticleGateway return $this->con->getResults(); } - public function addArticle(Article $article){ + public function addArticle(Article $article) + { $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array( ':id' => array($article->getId(), PDO::PARAM_STR), - ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(),PDO::PARAM_STR), - ':description' => array($article->getDescription(),PDO::PARAM_STR), - ':guid' => array($article->getGuid(),PDO::PARAM_STR), - ':link' => array($article->getLink(),PDO::PARAM_STR), - ':mediaContent' => array($article->getMediaContent(),PDO::PARAM_STR), - ':provenance' => array($article->getProvenance(),PDO::PARAM_INT))); + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + ':title' => array($article->getTitle(), PDO::PARAM_STR), + ':date' => array($article->getDate(), PDO::PARAM_STR), + ':description' => array($article->getDescription(), PDO::PARAM_STR), + ':guid' => array($article->getGuid(), PDO::PARAM_STR), + ':link' => array($article->getLink(), PDO::PARAM_STR), + ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), + ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); } } \ No newline at end of file diff --git a/fluxRSS/DAL/Connection.php b/fluxRSS/DAL/Connection.php index 8be3ee1..1ca9c27 100755 --- a/fluxRSS/DAL/Connection.php +++ b/fluxRSS/DAL/Connection.php @@ -15,8 +15,13 @@ class Connection extends PDO */ public function __construct(string $dsn, string $username, string $password) { - parent::__construct($dsn, $username, $password); - $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + try{ + parent::__construct($dsn, $username, $password); + $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + }catch (Exception $e){ + throw new Exception("PDO error con"); + } + } /** diff --git a/fluxRSS/controleur/Controleur.php b/fluxRSS/controleur/Controleur.php index ca4318e..81a6bee 100755 --- a/fluxRSS/controleur/Controleur.php +++ b/fluxRSS/controleur/Controleur.php @@ -3,13 +3,13 @@ namespace controleur; use model\ArticleModel; + class Controleur { public function __construct() { global $twig; // nécessaire pour utiliser variables globales session_start(); - $tabArticle[] = ArticleModel::getArticles(); //debut //on initialise un tableau d'erreur @@ -30,6 +30,7 @@ class Controleur //mauvaise action default: + $tabArticle[] = ArticleModel::getArticles(); $dVueEreur[] = "Erreur d'appel php"; $dataview = ['Article'=> $tabArticle]; echo $twig->render('listArticle.html', ['tabArticle' => $dataview, 'dVueErreur'=>$dVueEreur]); @@ -55,8 +56,9 @@ class Controleur $dVue = [ 'nom' => '', 'age' => 0, + 'data' => ArticleModel::getArticles(), ]; - echo $twig->render('vuephp1.html', [ + echo $twig->render('listArticle.html', [ 'dVue' => $dVue ]); } @@ -74,7 +76,7 @@ class Controleur $model = new \metier\Simplemodel(); $data = $model->get_data(); */ - + $dVue = [ 'nom' => $nom, 'age' => $age, diff --git a/fluxRSS/model/ArticleModel.php b/fluxRSS/model/ArticleModel.php index 4caf73a..bcb25a1 100755 --- a/fluxRSS/model/ArticleModel.php +++ b/fluxRSS/model/ArticleModel.php @@ -4,17 +4,17 @@ namespace model; use DAL; use metier; -require_once "config/config.php"; class ArticleModel { public static function getArticles() : array { - $gwArticle = new DAL\ArticleGateway(new DAL\Connection( $base, $login, $mdp)); + $gwArticle = new DAL\ArticleGateway(new DAL\Connection( 'mysql:host = localhost; dbname = dbrorossetto', 'rorossetto','tpphp')); $res = $gwArticle->getAllArticles(); foreach($res as $row){ $tabArticle[] = new metier\Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); } return $tabArticle; } + } \ No newline at end of file diff --git a/fluxRSS/templates/listArticle.html b/fluxRSS/templates/listArticle.html index c3dbaa6..b794cb4 100755 --- a/fluxRSS/templates/listArticle.html +++ b/fluxRSS/templates/listArticle.html @@ -5,7 +5,7 @@ All Articles -{% for value in tabArticle.Article %} +{% for value in dataview.tabArticle.Article %}

{{value}}

{% endfor %} From 1d416b1d670c7334c88aac96f2fe91478c2ed422 Mon Sep 17 00:00:00 2001 From: point Date: Wed, 15 Nov 2023 12:37:38 +0100 Subject: [PATCH 03/14] modif composer --- fluxRSS/vendor/composer/autoload_psr4.php | 10 +++++----- fluxRSS/vendor/composer/autoload_static.php | 10 +++++----- fluxRSS/vendor/composer/installed.php | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fluxRSS/vendor/composer/autoload_psr4.php b/fluxRSS/vendor/composer/autoload_psr4.php index 1002bc1..15606d7 100755 --- a/fluxRSS/vendor/composer/autoload_psr4.php +++ b/fluxRSS/vendor/composer/autoload_psr4.php @@ -6,12 +6,12 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( - 'model\\' => array($baseDir . '/model'), - 'metier\\' => array($baseDir . '/metier'), - 'controleur\\' => array($baseDir . '/controleur'), - 'config\\' => array($baseDir . '/config'), + 'model\\' => array($baseDir . '/src/model'), + 'metier\\' => array($baseDir . '/src/metier'), + 'controleur\\' => array($baseDir . '/src/controleur'), + 'config\\' => array($baseDir . '/src/config'), 'Twig\\' => array($vendorDir . '/twig/twig/src'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), - 'DAL\\' => array($baseDir . '/DAL'), + 'DAL\\' => array($baseDir . '/src/DAL'), ); diff --git a/fluxRSS/vendor/composer/autoload_static.php b/fluxRSS/vendor/composer/autoload_static.php index 868aa69..b63d956 100755 --- a/fluxRSS/vendor/composer/autoload_static.php +++ b/fluxRSS/vendor/composer/autoload_static.php @@ -40,19 +40,19 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 public static $prefixDirsPsr4 = array ( 'model\\' => array ( - 0 => __DIR__ . '/../..' . '/model', + 0 => __DIR__ . '/../..' . '/src/model', ), 'metier\\' => array ( - 0 => __DIR__ . '/../..' . '/metier', + 0 => __DIR__ . '/../..' . '/src/metier', ), 'controleur\\' => array ( - 0 => __DIR__ . '/../..' . '/controleur', + 0 => __DIR__ . '/../..' . '/src/controleur', ), 'config\\' => array ( - 0 => __DIR__ . '/../..' . '/config', + 0 => __DIR__ . '/../..' . '/src/config', ), 'Twig\\' => array ( @@ -68,7 +68,7 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ), 'DAL\\' => array ( - 0 => __DIR__ . '/../..' . '/DAL', + 0 => __DIR__ . '/../..' . '/src/DAL', ), ); diff --git a/fluxRSS/vendor/composer/installed.php b/fluxRSS/vendor/composer/installed.php index f85d7f7..4b76349 100755 --- a/fluxRSS/vendor/composer/installed.php +++ b/fluxRSS/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'ad56f74a69d8ff3b81d0d287531c37da6ef273ab', + 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'ad56f74a69d8ff3b81d0d287531c37da6ef273ab', + 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), From dc077c230da502bb8d57c200d856f4e764d6d398 Mon Sep 17 00:00:00 2001 From: mapoint2 Date: Wed, 15 Nov 2023 12:39:13 +0100 Subject: [PATCH 04/14] modif composer --- .idea/sqldialects.xml | 6 ------ fluxRSS/composer.json | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 .idea/sqldialects.xml diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml deleted file mode 100644 index ff83d34..0000000 --- a/.idea/sqldialects.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/fluxRSS/composer.json b/fluxRSS/composer.json index 9ee7dc7..c412f39 100755 --- a/fluxRSS/composer.json +++ b/fluxRSS/composer.json @@ -6,6 +6,7 @@ }, "autoload": { "psr-4": { + "src\\": "src/", "controleur\\": "src/controleur/", "config\\": "src/config/", "model\\": "src/model/", From c39a62aa687268a005c8a72a05ce49d27cfc6f91 Mon Sep 17 00:00:00 2001 From: point Date: Wed, 15 Nov 2023 12:40:09 +0100 Subject: [PATCH 05/14] modif composer --- fluxRSS/vendor/composer/autoload_psr4.php | 1 + fluxRSS/vendor/composer/autoload_static.php | 8 ++++++++ fluxRSS/vendor/composer/installed.php | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fluxRSS/vendor/composer/autoload_psr4.php b/fluxRSS/vendor/composer/autoload_psr4.php index 15606d7..4501883 100755 --- a/fluxRSS/vendor/composer/autoload_psr4.php +++ b/fluxRSS/vendor/composer/autoload_psr4.php @@ -6,6 +6,7 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( + 'src\\' => array($baseDir . '/src'), 'model\\' => array($baseDir . '/src/model'), 'metier\\' => array($baseDir . '/src/metier'), 'controleur\\' => array($baseDir . '/src/controleur'), diff --git a/fluxRSS/vendor/composer/autoload_static.php b/fluxRSS/vendor/composer/autoload_static.php index b63d956..eb5e51a 100755 --- a/fluxRSS/vendor/composer/autoload_static.php +++ b/fluxRSS/vendor/composer/autoload_static.php @@ -12,6 +12,10 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ); public static $prefixLengthsPsr4 = array ( + 's' => + array ( + 'src\\' => 4, + ), 'm' => array ( 'model\\' => 6, @@ -38,6 +42,10 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ); public static $prefixDirsPsr4 = array ( + 'src\\' => + array ( + 0 => __DIR__ . '/../..' . '/src', + ), 'model\\' => array ( 0 => __DIR__ . '/../..' . '/src/model', diff --git a/fluxRSS/vendor/composer/installed.php b/fluxRSS/vendor/composer/installed.php index 4b76349..f9f7468 100755 --- a/fluxRSS/vendor/composer/installed.php +++ b/fluxRSS/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', + 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', + 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), From fa388c96e1b4377bdd971369eea2939da055c499 Mon Sep 17 00:00:00 2001 From: mapoint2 Date: Wed, 15 Nov 2023 12:49:36 +0100 Subject: [PATCH 06/14] gestion d'erreur --- fluxRSS/index.php | 2 +- fluxRSS/{src => }/templates/.DS_Store | Bin fluxRSS/{src => }/templates/erreur.html | 0 fluxRSS/{src => }/templates/listArticle.html | 4 +--- fluxRSS/{src => }/templates/vuephp1.html | 0 5 files changed, 2 insertions(+), 4 deletions(-) rename fluxRSS/{src => }/templates/.DS_Store (100%) rename fluxRSS/{src => }/templates/erreur.html (100%) rename fluxRSS/{src => }/templates/listArticle.html (81%) rename fluxRSS/{src => }/templates/vuephp1.html (100%) diff --git a/fluxRSS/index.php b/fluxRSS/index.php index fd16b5b..f109bd4 100755 --- a/fluxRSS/index.php +++ b/fluxRSS/index.php @@ -1,7 +1,7 @@ {% for value in dVue.data %} -

- {% for article in value} + {% for article in value %}

{{article}}

{% endfor %} -

{% endfor %} \ No newline at end of file diff --git a/fluxRSS/src/templates/vuephp1.html b/fluxRSS/templates/vuephp1.html similarity index 100% rename from fluxRSS/src/templates/vuephp1.html rename to fluxRSS/templates/vuephp1.html From 0bfc92956970a8f2e61bad94cf9065a080f9dbc4 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 14:22:46 +0100 Subject: [PATCH 07/14] add altorouteur --- fluxRSS/.idea/mvc_PSR4_twig.iml | 1 + fluxRSS/AltoRouter.php | 302 ++++++++++++++++++ .../.github/workflows/php.yml | 39 +++ .../AltoRouter.php | 302 ++++++++++++++++++ .../LICENSE.md | 9 + .../README.md | 57 ++++ .../composer.json | 35 ++ .../phpcs.xml | 10 + fluxRSS/src/DAL/FluxGateway.php | 6 + fluxRSS/src/metier/Flux.php | 20 +- fluxRSS/src/model/Parser.php | 17 +- fluxRSS/src/test/test.php | 14 + fluxRSS/vendor/composer/installed.php | 4 +- 13 files changed, 798 insertions(+), 18 deletions(-) create mode 100755 fluxRSS/AltoRouter.php create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml create mode 100755 fluxRSS/src/test/test.php diff --git a/fluxRSS/.idea/mvc_PSR4_twig.iml b/fluxRSS/.idea/mvc_PSR4_twig.iml index c0f9f5d..1323748 100755 --- a/fluxRSS/.idea/mvc_PSR4_twig.iml +++ b/fluxRSS/.idea/mvc_PSR4_twig.iml @@ -9,6 +9,7 @@ + diff --git a/fluxRSS/AltoRouter.php b/fluxRSS/AltoRouter.php new file mode 100755 index 0000000..31aa338 --- /dev/null +++ b/fluxRSS/AltoRouter.php @@ -0,0 +1,302 @@ + + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +class AltoRouter +{ + + /** + * @var array Array of all routes (incl. named routes). + */ + protected $routes = []; + + /** + * @var array Array of all named routes. + */ + protected $namedRoutes = []; + + /** + * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host) + */ + protected $basePath = ''; + + /** + * @var array Array of default match types (regex helpers) + */ + protected $matchTypes = [ + 'i' => '[0-9]++', + 'a' => '[0-9A-Za-z]++', + 'h' => '[0-9A-Fa-f]++', + '*' => '.+?', + '**' => '.++', + '' => '[^/\.]++' + ]; + + /** + * Create router in one call from config. + * + * @param array $routes + * @param string $basePath + * @param array $matchTypes + * @throws Exception + */ + public function __construct(array $routes = [], $basePath = '', array $matchTypes = []) + { + $this->addRoutes($routes); + $this->setBasePath($basePath); + $this->addMatchTypes($matchTypes); + } + + /** + * Retrieves all routes. + * Useful if you want to process or display routes. + * @return array All routes. + */ + public function getRoutes() + { + return $this->routes; + } + + /** + * Add multiple routes at once from array in the following format: + * + * $routes = [ + * [$method, $route, $target, $name] + * ]; + * + * @param array $routes + * @return void + * @author Koen Punt + * @throws Exception + */ + public function addRoutes($routes) + { + if (!is_array($routes) && !$routes instanceof Traversable) { + throw new RuntimeException('Routes should be an array or an instance of Traversable'); + } + foreach ($routes as $route) { + call_user_func_array([$this, 'map'], $route); + } + } + + /** + * Set the base path. + * Useful if you are running your application from a subdirectory. + * @param string $basePath + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + } + + /** + * Add named match types. It uses array_merge so keys can be overwritten. + * + * @param array $matchTypes The key is the name and the value is the regex. + */ + public function addMatchTypes(array $matchTypes) + { + $this->matchTypes = array_merge($this->matchTypes, $matchTypes); + } + + /** + * Map a route to a target + * + * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE) + * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id] + * @param mixed $target The target where this route should point to. Can be anything. + * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application. + * @throws Exception + */ + public function map($method, $route, $target, $name = null) + { + + $this->routes[] = [$method, $route, $target, $name]; + + if ($name) { + if (isset($this->namedRoutes[$name])) { + throw new RuntimeException("Can not redeclare route '{$name}'"); + } + $this->namedRoutes[$name] = $route; + } + + return; + } + + /** + * Reversed routing + * + * Generate the URL for a named route. Replace regexes with supplied parameters + * + * @param string $routeName The name of the route. + * @param array @params Associative array of parameters to replace placeholders with. + * @return string The URL of the route with named parameters in place. + * @throws Exception + */ + public function generate($routeName, array $params = []) + { + + // Check if named route exists + if (!isset($this->namedRoutes[$routeName])) { + throw new RuntimeException("Route '{$routeName}' does not exist."); + } + + // Replace named parameters + $route = $this->namedRoutes[$routeName]; + + // prepend base path to route url again + $url = $this->basePath . $route; + + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + foreach ($matches as $index => $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if ($pre) { + $block = substr($block, 1); + } + + if (isset($params[$param])) { + // Part is found, replace for param value + $url = str_replace($block, $params[$param], $url); + } elseif ($optional && $index !== 0) { + // Only strip preceding slash if it's not at the base + $url = str_replace($pre . $block, '', $url); + } else { + // Strip match block + $url = str_replace($block, '', $url); + } + } + } + + return $url; + } + + /** + * Match a given Request Url against stored routes + * @param string $requestUrl + * @param string $requestMethod + * @return array|boolean Array with route information on success, false on failure (no match). + */ + public function match($requestUrl = null, $requestMethod = null) + { + + $params = []; + + // set Request Url if it isn't passed as parameter + if ($requestUrl === null) { + $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; + } + + // strip base path from request url + $requestUrl = substr($requestUrl, strlen($this->basePath)); + + // Strip query string (?a=b) from Request Url + if (($strpos = strpos($requestUrl, '?')) !== false) { + $requestUrl = substr($requestUrl, 0, $strpos); + } + + $lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : ''; + + // set Request Method if it isn't passed as a parameter + if ($requestMethod === null) { + $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + } + + foreach ($this->routes as $handler) { + list($methods, $route, $target, $name) = $handler; + + $method_match = (stripos($methods, $requestMethod) !== false); + + // Method did not match, continue to next route. + if (!$method_match) { + continue; + } + + if ($route === '*') { + // * wildcard (matches all) + $match = true; + } elseif (isset($route[0]) && $route[0] === '@') { + // @ regex delimiter + $pattern = '`' . substr($route, 1) . '`u'; + $match = preg_match($pattern, $requestUrl, $params) === 1; + } elseif (($position = strpos($route, '[')) === false) { + // No params in url, do string comparison + $match = strcmp($requestUrl, $route) === 0; + } else { + // Compare longest non-param string with url before moving on to regex + // Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241) + if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) { + continue; + } + + $regex = $this->compileRoute($route); + $match = preg_match($regex, $requestUrl, $params) === 1; + } + + if ($match) { + if ($params) { + foreach ($params as $key => $value) { + if (is_numeric($key)) { + unset($params[$key]); + } + } + } + + return [ + 'target' => $target, + 'params' => $params, + 'name' => $name + ]; + } + } + + return false; + } + + /** + * Compile the regex for a given route (EXPENSIVE) + * @param $route + * @return string + */ + protected function compileRoute($route) + { + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + $matchTypes = $this->matchTypes; + foreach ($matches as $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if (isset($matchTypes[$type])) { + $type = $matchTypes[$type]; + } + if ($pre === '.') { + $pre = '\.'; + } + + $optional = $optional !== '' ? '?' : null; + + //Older versions of PCRE require the 'P' in (?P) + $pattern = '(?:' + . ($pre !== '' ? $pre : null) + . '(' + . ($param !== '' ? "?P<$param>" : null) + . $type + . ')' + . $optional + . ')' + . $optional; + + $route = str_replace($block, $pattern, $route); + } + } + return "`^$route$`u"; + } +} diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml new file mode 100755 index 0000000..c428ab7 --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml @@ -0,0 +1,39 @@ +name: PHP + +on: [ push, pull_request ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '7.3', '7.4', '8.0', '8.1' ] + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: composer + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress + + - name: Run test suite + run: composer run-script test \ No newline at end of file diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php new file mode 100755 index 0000000..31aa338 --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php @@ -0,0 +1,302 @@ + + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +class AltoRouter +{ + + /** + * @var array Array of all routes (incl. named routes). + */ + protected $routes = []; + + /** + * @var array Array of all named routes. + */ + protected $namedRoutes = []; + + /** + * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host) + */ + protected $basePath = ''; + + /** + * @var array Array of default match types (regex helpers) + */ + protected $matchTypes = [ + 'i' => '[0-9]++', + 'a' => '[0-9A-Za-z]++', + 'h' => '[0-9A-Fa-f]++', + '*' => '.+?', + '**' => '.++', + '' => '[^/\.]++' + ]; + + /** + * Create router in one call from config. + * + * @param array $routes + * @param string $basePath + * @param array $matchTypes + * @throws Exception + */ + public function __construct(array $routes = [], $basePath = '', array $matchTypes = []) + { + $this->addRoutes($routes); + $this->setBasePath($basePath); + $this->addMatchTypes($matchTypes); + } + + /** + * Retrieves all routes. + * Useful if you want to process or display routes. + * @return array All routes. + */ + public function getRoutes() + { + return $this->routes; + } + + /** + * Add multiple routes at once from array in the following format: + * + * $routes = [ + * [$method, $route, $target, $name] + * ]; + * + * @param array $routes + * @return void + * @author Koen Punt + * @throws Exception + */ + public function addRoutes($routes) + { + if (!is_array($routes) && !$routes instanceof Traversable) { + throw new RuntimeException('Routes should be an array or an instance of Traversable'); + } + foreach ($routes as $route) { + call_user_func_array([$this, 'map'], $route); + } + } + + /** + * Set the base path. + * Useful if you are running your application from a subdirectory. + * @param string $basePath + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + } + + /** + * Add named match types. It uses array_merge so keys can be overwritten. + * + * @param array $matchTypes The key is the name and the value is the regex. + */ + public function addMatchTypes(array $matchTypes) + { + $this->matchTypes = array_merge($this->matchTypes, $matchTypes); + } + + /** + * Map a route to a target + * + * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE) + * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id] + * @param mixed $target The target where this route should point to. Can be anything. + * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application. + * @throws Exception + */ + public function map($method, $route, $target, $name = null) + { + + $this->routes[] = [$method, $route, $target, $name]; + + if ($name) { + if (isset($this->namedRoutes[$name])) { + throw new RuntimeException("Can not redeclare route '{$name}'"); + } + $this->namedRoutes[$name] = $route; + } + + return; + } + + /** + * Reversed routing + * + * Generate the URL for a named route. Replace regexes with supplied parameters + * + * @param string $routeName The name of the route. + * @param array @params Associative array of parameters to replace placeholders with. + * @return string The URL of the route with named parameters in place. + * @throws Exception + */ + public function generate($routeName, array $params = []) + { + + // Check if named route exists + if (!isset($this->namedRoutes[$routeName])) { + throw new RuntimeException("Route '{$routeName}' does not exist."); + } + + // Replace named parameters + $route = $this->namedRoutes[$routeName]; + + // prepend base path to route url again + $url = $this->basePath . $route; + + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + foreach ($matches as $index => $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if ($pre) { + $block = substr($block, 1); + } + + if (isset($params[$param])) { + // Part is found, replace for param value + $url = str_replace($block, $params[$param], $url); + } elseif ($optional && $index !== 0) { + // Only strip preceding slash if it's not at the base + $url = str_replace($pre . $block, '', $url); + } else { + // Strip match block + $url = str_replace($block, '', $url); + } + } + } + + return $url; + } + + /** + * Match a given Request Url against stored routes + * @param string $requestUrl + * @param string $requestMethod + * @return array|boolean Array with route information on success, false on failure (no match). + */ + public function match($requestUrl = null, $requestMethod = null) + { + + $params = []; + + // set Request Url if it isn't passed as parameter + if ($requestUrl === null) { + $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; + } + + // strip base path from request url + $requestUrl = substr($requestUrl, strlen($this->basePath)); + + // Strip query string (?a=b) from Request Url + if (($strpos = strpos($requestUrl, '?')) !== false) { + $requestUrl = substr($requestUrl, 0, $strpos); + } + + $lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : ''; + + // set Request Method if it isn't passed as a parameter + if ($requestMethod === null) { + $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + } + + foreach ($this->routes as $handler) { + list($methods, $route, $target, $name) = $handler; + + $method_match = (stripos($methods, $requestMethod) !== false); + + // Method did not match, continue to next route. + if (!$method_match) { + continue; + } + + if ($route === '*') { + // * wildcard (matches all) + $match = true; + } elseif (isset($route[0]) && $route[0] === '@') { + // @ regex delimiter + $pattern = '`' . substr($route, 1) . '`u'; + $match = preg_match($pattern, $requestUrl, $params) === 1; + } elseif (($position = strpos($route, '[')) === false) { + // No params in url, do string comparison + $match = strcmp($requestUrl, $route) === 0; + } else { + // Compare longest non-param string with url before moving on to regex + // Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241) + if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) { + continue; + } + + $regex = $this->compileRoute($route); + $match = preg_match($regex, $requestUrl, $params) === 1; + } + + if ($match) { + if ($params) { + foreach ($params as $key => $value) { + if (is_numeric($key)) { + unset($params[$key]); + } + } + } + + return [ + 'target' => $target, + 'params' => $params, + 'name' => $name + ]; + } + } + + return false; + } + + /** + * Compile the regex for a given route (EXPENSIVE) + * @param $route + * @return string + */ + protected function compileRoute($route) + { + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + $matchTypes = $this->matchTypes; + foreach ($matches as $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if (isset($matchTypes[$type])) { + $type = $matchTypes[$type]; + } + if ($pre === '.') { + $pre = '\.'; + } + + $optional = $optional !== '' ? '?' : null; + + //Older versions of PCRE require the 'P' in (?P) + $pattern = '(?:' + . ($pre !== '' ? $pre : null) + . '(' + . ($param !== '' ? "?P<$param>" : null) + . $type + . ')' + . $optional + . ')' + . $optional; + + $route = str_replace($block, $pattern, $route); + } + } + return "`^$route$`u"; + } +} diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md new file mode 100755 index 0000000..a1130bb --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2012 Danny van Kooten + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md new file mode 100755 index 0000000..7d6e1fe --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md @@ -0,0 +1,57 @@ +# AltoRouter ![PHP status](https://github.com/dannyvankooten/AltoRouter/workflows/PHP/badge.svg) [![Latest Stable Version](https://poser.pugx.org/altorouter/altorouter/v/stable.svg)](https://packagist.org/packages/altorouter/altorouter) [![License](https://poser.pugx.org/altorouter/altorouter/license.svg)](https://packagist.org/packages/altorouter/altorouter) + +AltoRouter is a small but powerful routing class, heavily inspired by [klein.php](https://github.com/chriso/klein.php/). + +```php +$router = new AltoRouter(); + +// map homepage +$router->map('GET', '/', function() { + require __DIR__ . '/views/home.php'; +}); + +// dynamic named route +$router->map('GET|POST', '/users/[i:id]/', function($id) { + $user = ..... + require __DIR__ . '/views/user/details.php'; +}, 'user-details'); + +// echo URL to user-details page for ID 5 +echo $router->generate('user-details', ['id' => 5]); // Output: "/users/5" +``` + +## Features + +* Can be used with all HTTP Methods +* Dynamic routing with named route parameters +* Reversed routing +* Flexible regular expression routing (inspired by [Sinatra](http://www.sinatrarb.com/)) +* Custom regexes + +## Getting started + +You need PHP >= 5.6 to use AltoRouter, although we highly recommend you [use an officially supported PHP version](https://secure.php.net/supported-versions.php) that is not EOL. + +- [Install AltoRouter](http://altorouter.com/usage/install.html) +- [Rewrite all requests to AltoRouter](http://altorouter.com/usage/rewrite-requests.html) +- [Map your routes](http://altorouter.com/usage/mapping-routes.html) +- [Match requests](http://altorouter.com/usage/matching-requests.html) +- [Process the request your preferred way](http://altorouter.com/usage/processing-requests.html) + +## Contributors +- [Danny van Kooten](https://github.com/dannyvankooten) +- [Koen Punt](https://github.com/koenpunt) +- [John Long](https://github.com/adduc) +- [Niahoo Osef](https://github.com/niahoo) + +## License + +MIT License + +Copyright (c) 2012 Danny van Kooten + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json new file mode 100755 index 0000000..6828248 --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json @@ -0,0 +1,35 @@ +{ + "name": "altorouter/altorouter", + "description": "A lightning fast router for PHP", + "keywords": ["router", "routing", "lightweight"], + "homepage": "https://github.com/dannyvankooten/AltoRouter", + "license": "MIT", + "authors": [ + { + "name": "Danny van Kooten", + "email": "dannyvankooten@gmail.com", + "homepage": "http://dannyvankooten.com/" + }, + { + "name": "Koen Punt", + "homepage": "https://github.com/koenpunt" + }, + { + "name": "niahoo", + "homepage": "https://github.com/niahoo" + } + ], + "require": { + "php": ">=7.0" + }, + "require-dev": { + "phpunit/phpunit": "9.5.*", + "squizlabs/php_codesniffer": "3.6.2" + }, + "autoload": { + "classmap": ["AltoRouter.php"] + }, + "scripts": { + "test": "vendor/bin/phpunit" + } +} diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml new file mode 100755 index 0000000..d59cccf --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml @@ -0,0 +1,10 @@ + + + rules + + + tests + AltoRouter.php + examples/ + + diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 43bbe9f..9344801 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -13,6 +13,12 @@ class FluxGateway $this->con = $con; } + public function getId(): int + { + + return $this->id; + } + public function addFlux($flux){ try{ $query = 'INSERT INTO Flux VALUES (:flux);'; diff --git a/fluxRSS/src/metier/Flux.php b/fluxRSS/src/metier/Flux.php index a167fbe..627d9f2 100755 --- a/fluxRSS/src/metier/Flux.php +++ b/fluxRSS/src/metier/Flux.php @@ -4,9 +4,19 @@ namespace metier; class Flux { - private string $id; + private int $id; private string $flux; + /** + * @param int $id + * @param string $flux + */ + public function __construct(int $id, string $flux) + { + $this->id = $id; + $this->flux = $flux; + } + /** * @return string */ @@ -22,12 +32,4 @@ class Flux { $this->flux = $flux; } - - /** - * @return string - */ - public function getId(): string - { - return $this->id; - } } \ No newline at end of file diff --git a/fluxRSS/src/model/Parser.php b/fluxRSS/src/model/Parser.php index 287e26d..70f8b95 100755 --- a/fluxRSS/src/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -54,7 +54,9 @@ class Parser * @throws Exception */ public function parseAll($fluxes){ + $tabArticles = []; foreach ($fluxes as $flux){ + var_dump($flux); $tabArticles[] =$this->parseArticles($flux); } return $tabArticles; @@ -65,11 +67,15 @@ class Parser */ public function addAllArticles() { + $tabFluxes = []; $this->articleGateway->removeAllArticleForParser(); - $allFlux = $this->fluxGateway->findAllFlux(); - var_dump($allFlux); - $allArticles = $this->parseAll($allFlux); + $allItemFlux = $this->fluxGateway->findAllFlux(); + var_dump($allItemFlux); + foreach ($allItemFlux as $ItemFlux){ + $tabFluxes[] = $ItemFlux[1]; + } + $allArticles = $this->parseAll($tabFluxes); var_dump($allArticles); foreach ($allArticles as $article) { $this->articleGateway->addArticle($article); @@ -78,10 +84,7 @@ class Parser } } -$gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); -$gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); -$pars = new Parser( $gwFl,$gwArt); -var_dump($pars->addAllArticles()); + diff --git a/fluxRSS/src/test/test.php b/fluxRSS/src/test/test.php new file mode 100755 index 0000000..68afbe3 --- /dev/null +++ b/fluxRSS/src/test/test.php @@ -0,0 +1,14 @@ +addAllArticles()); + diff --git a/fluxRSS/vendor/composer/installed.php b/fluxRSS/vendor/composer/installed.php index f9f7468..8b559d3 100755 --- a/fluxRSS/vendor/composer/installed.php +++ b/fluxRSS/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', + 'reference' => 'c39a62aa687268a005c8a72a05ce49d27cfc6f91', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', + 'reference' => 'c39a62aa687268a005c8a72a05ce49d27cfc6f91', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), From 0768066a7b60a441d32e6a15a1f76c55a493727b Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 14:26:42 +0100 Subject: [PATCH 08/14] adding altoRouteur --- fluxRSS/AltoRouter.php | 2 ++ fluxRSS/controleur/FrontControleur.php | 12 ++++++++++++ .../dannyvankooten-AltoRouter-ac028a7/composer.json | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100755 fluxRSS/controleur/FrontControleur.php diff --git a/fluxRSS/AltoRouter.php b/fluxRSS/AltoRouter.php index 31aa338..6c14b90 100755 --- a/fluxRSS/AltoRouter.php +++ b/fluxRSS/AltoRouter.php @@ -11,6 +11,8 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +namespace vendor; + class AltoRouter { diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/controleur/FrontControleur.php new file mode 100755 index 0000000..bfceb74 --- /dev/null +++ b/fluxRSS/controleur/FrontControleur.php @@ -0,0 +1,12 @@ +=7.0" + "php": ">=5.6.0" }, "require-dev": { "phpunit/phpunit": "9.5.*", From a160974d61cd7792a341b533ace7909598c9e4cc Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 14:33:37 +0100 Subject: [PATCH 09/14] directory modification --- fluxRSS/{ => src}/controleur/FrontControleur.php | 2 ++ 1 file changed, 2 insertions(+) rename fluxRSS/{ => src}/controleur/FrontControleur.php (98%) diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php similarity index 98% rename from fluxRSS/controleur/FrontControleur.php rename to fluxRSS/src/controleur/FrontControleur.php index bfceb74..af7b2b3 100755 --- a/fluxRSS/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -9,4 +9,6 @@ class FrontControleur public function __construct(){ $altoRouteur = new AltoRouter(); } + + } \ No newline at end of file From 54091b41ff06453d775f869aefa05e63bff98ccf Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 15:20:52 +0100 Subject: [PATCH 10/14] modification of controllers added --- ...8a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php | 6 +++--- fluxRSS/src/controleur/Controleur.php | 2 +- fluxRSS/src/controleur/FrontControleur.php | 4 +++- fluxRSS/templates/{vuephp1.html => Connection.html} | 0 4 files changed, 7 insertions(+), 5 deletions(-) rename fluxRSS/templates/{vuephp1.html => Connection.html} (100%) diff --git a/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php b/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php index 1dcc316..aa56ec3 100755 --- a/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php +++ b/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php @@ -12,7 +12,7 @@ use Twig\Sandbox\SecurityNotAllowedFunctionError; use Twig\Source; use Twig\Template; -/* vuephp1.html */ +/* Connection.html */ class __TwigTemplate_2ce784f5b9085065b66af58be97997ff169e0f0d71d95a1d280acea4a24fd4e6 extends Template { private $source; @@ -165,7 +165,7 @@ utilisation anormale de la vuephp public function getTemplateName() { - return "vuephp1.html"; + return "Connection.html"; } public function isTraitable() @@ -180,6 +180,6 @@ utilisation anormale de la vuephp public function getSourceContext() { - return new Source("", "vuephp1.html", "/Applications/MAMP/htdocs/phptwig/templates/vuephp1.html"); + return new Source("", "Connection.html", "/Applications/MAMP/htdocs/phptwig/templates/Connection.html"); } } diff --git a/fluxRSS/src/controleur/Controleur.php b/fluxRSS/src/controleur/Controleur.php index 86ef927..e94eb78 100755 --- a/fluxRSS/src/controleur/Controleur.php +++ b/fluxRSS/src/controleur/Controleur.php @@ -81,6 +81,6 @@ class Controleur //'data' => $data, ]; - echo $twig->render('vuephp1.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); + echo $twig->render('Connection.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); } }//fin class diff --git a/fluxRSS/src/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php index af7b2b3..791bfc3 100755 --- a/fluxRSS/src/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -7,7 +7,9 @@ use vendor\AltoRouter; class FrontControleur { public function __construct(){ - $altoRouteur = new AltoRouter(); + $routeur = new AltoRouter(); + + } diff --git a/fluxRSS/templates/vuephp1.html b/fluxRSS/templates/Connection.html similarity index 100% rename from fluxRSS/templates/vuephp1.html rename to fluxRSS/templates/Connection.html From 12913ba1e72bd36a1d400fce4ce913d8960fd479 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Thu, 16 Nov 2023 15:09:16 +0100 Subject: [PATCH 11/14] parser fixed, there's a connection problem to load articles into database --- fluxRSS/src/DAL/ArticleGateway.php | 6 +-- fluxRSS/src/DAL/Connection.php | 11 ++++- fluxRSS/src/DAL/FluxGateway.php | 5 ++- fluxRSS/src/controleur/FrontControleur.php | 3 -- fluxRSS/src/metier/Article.php | 18 +++++--- fluxRSS/src/metier/Flux.php | 8 ++++ fluxRSS/src/model/FluxModel.php | 14 +++--- fluxRSS/src/model/Parser.php | 52 +++++++++++++++++----- 8 files changed, 84 insertions(+), 33 deletions(-) diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php index 89e43ec..2bb7da7 100755 --- a/fluxRSS/src/DAL/ArticleGateway.php +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -35,10 +35,10 @@ class ArticleGateway */ public function addArticle(Article $article){ try { - $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + $query = 'INSERT INTO Article VALUES (:id,:title,datePub,:description,:guid,:link,:mediaContent,:provenance);'; + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_INT), ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(), PDO::PARAM_STR), + ':datePub' => array($article->getDate(), PDO::PARAM_STR), ':description' => array($article->getDescription(), PDO::PARAM_STR), ':guid' => array($article->getGuid(), PDO::PARAM_STR), ':link' => array($article->getLink(), PDO::PARAM_STR), diff --git a/fluxRSS/src/DAL/Connection.php b/fluxRSS/src/DAL/Connection.php index dc58de2..00952cf 100755 --- a/fluxRSS/src/DAL/Connection.php +++ b/fluxRSS/src/DAL/Connection.php @@ -42,10 +42,17 @@ class Connection extends PDO foreach ($parameters as $name => $value) { $this->stmt->bindValue($name, $value[0], $value[1]); } + if($this->stmt->execute()){ + return true; + } else { + $error = $this->stmt->errorInfo(); + throw new Exception("PDO error: ".$error[2]); + } - return $this->stmt->execute(); }catch (\PDOException $e){ - throw new Exception("PDO error"); + throw new Exception("PDO error: ".$e->getMessage()); + }catch (\Error $r){ + throw new Error("executionQuery not possible : ".$r->getMessage()); } } diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 9344801..35b61a9 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -41,7 +41,10 @@ class FluxGateway try{ $query = 'SELECT * FROM Flux;'; $this->con->executeQuery($query); - return $this->con->getResults(); + $results = $this->con->getResults(); + print("result findAllFlux Gateway"); + var_dump($results); + return $results; }catch (\PDOException $e){ throw new \Exception("PDO error"); } diff --git a/fluxRSS/src/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php index 1419941..a98e6e0 100755 --- a/fluxRSS/src/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -11,11 +11,9 @@ require 'AltoRouter.php'; class FrontControleur { public function __construct(){ -<<<<<<< HEAD:fluxRSS/src/controleur/FrontControleur.php $routeur = new AltoRouter(); -======= global $twig; @@ -52,7 +50,6 @@ class FrontControleur echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } } ->>>>>>> pre-master:fluxRSS/controleur/FrontControleur.php } diff --git a/fluxRSS/src/metier/Article.php b/fluxRSS/src/metier/Article.php index 809c3d1..d4a2cf0 100755 --- a/fluxRSS/src/metier/Article.php +++ b/fluxRSS/src/metier/Article.php @@ -4,26 +4,34 @@ namespace metier; class Article { - private string $id; + private int $id; private string $title; private string $date; private string $description; private string $guid; private string $link; private string $mediaContent; - private string $provenance; + private int $provenance; /** - * @param string $id + * @param int $id * @param string $title * @param string $date * @param string $description * @param string $guid * @param string $link * @param string $mediaContent - * @param string $provenance + * @param int $provenance */ - public function __construct(string $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, string $provenance) + public function __construct( + int $id, + string $title, + string $date, + string $description, + string $guid, + string $link, + string $mediaContent, + int $provenance) { $this->id = $id; $this->title = $title; diff --git a/fluxRSS/src/metier/Flux.php b/fluxRSS/src/metier/Flux.php index 627d9f2..70a07ad 100755 --- a/fluxRSS/src/metier/Flux.php +++ b/fluxRSS/src/metier/Flux.php @@ -32,4 +32,12 @@ class Flux { $this->flux = $flux; } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } } \ No newline at end of file diff --git a/fluxRSS/src/model/FluxModel.php b/fluxRSS/src/model/FluxModel.php index 5116de9..1cf740e 100755 --- a/fluxRSS/src/model/FluxModel.php +++ b/fluxRSS/src/model/FluxModel.php @@ -10,7 +10,7 @@ require_once "config/config.php"; class FluxModel { public function FindAllFlux(){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findAllFlux(); @@ -21,7 +21,7 @@ class FluxModel } public function addFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = $this->findFlux($flux); if ($data == array()) { $gateway->addFlux($flux); @@ -29,26 +29,26 @@ class FluxModel } public function addFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->addFlux($newFlux); return $newFlux; } public function removeFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $gateway->removeFlux($flux); } public function removeFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->removeFlux($newFlux); return $newFlux; } public function findFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFlux($flux); @@ -59,7 +59,7 @@ class FluxModel } public function findFluxBySrc(string $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFluxBySrc($flux); diff --git a/fluxRSS/src/model/Parser.php b/fluxRSS/src/model/Parser.php index 70f8b95..722a06a 100755 --- a/fluxRSS/src/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -21,26 +21,44 @@ class Parser } public function parseArticles(Flux $flux): array { + print("debut parseArticles******************
"); $dom = new DOMDocument(); + print("creation du dom
"); $tabArticle = array(); if ($dom->load($flux->getFlux())){ $items = $dom->getElementsByTagName('item'); - + print("après avoir getElementByTagName
"); + var_dump($items); foreach ($items as $item) { $title = $item->getElementsByTagName('title')[0]->nodeValue; + print("le titre
"); + var_dump($title); $date = $item->getElementsByTagName('pubDate')[0]->nodeValue; + print("la date
"); + var_dump($date); $guid = $item->getElementsByTagName('guid')[0]->nodeValue; $link = $item->getElementsByTagName('link')[0]->nodeValue; $description = $item->getElementsByTagName('description')[0]->nodeValue; - $media = $item->getElementsByTagName('media:content'); + print("media :
"); + var_dump($media); $mediaUrl = null; if ($media->length > 0){ $mediaUrl = $media->item(0)->getAttribute('url'); } - $tabArticle[] = new Article((int)null, $title, $date, $description, $guid, $link, $mediaUrl, $flux->getId()); + $tabArticle[] = new Article( + (int)null, + $title, + $date, + $description, + $guid, + $link, + ($mediaUrl !== null) ? (string)$mediaUrl : '', + $flux->getId()); + print("Tableau de l'article"); + var_dump($tabArticle); } return $tabArticle; } else { @@ -55,10 +73,16 @@ class Parser */ public function parseAll($fluxes){ $tabArticles = []; + print("debut parseAll
"); foreach ($fluxes as $flux){ - var_dump($flux); - $tabArticles[] =$this->parseArticles($flux); + $fluxx = new Flux($flux[0],$flux[1]); + print("flux de parseAll
"); + var_dump($fluxx); + $tabArticles[] = $this->parseArticles($fluxx); + print("fin parsqeAll
"); + } + var_dump($tabArticles); return $tabArticles; } @@ -71,16 +95,20 @@ class Parser $this->articleGateway->removeAllArticleForParser(); $allItemFlux = $this->fluxGateway->findAllFlux(); - var_dump($allItemFlux); foreach ($allItemFlux as $ItemFlux){ $tabFluxes[] = $ItemFlux[1]; - } - $allArticles = $this->parseAll($tabFluxes); - var_dump($allArticles); - foreach ($allArticles as $article) { - $this->articleGateway->addArticle($article); } - return $allArticles; + print("tableau de flux
"); + var_dump($tabFluxes); + + $allTabArticles = $this->parseAll($allItemFlux); + + foreach ($allTabArticles as $tabArticle) { + foreach ($tabArticle as $item) { + $this->articleGateway->addArticle($item); + } + + } } } From 0dd3beac7585570f15d0fc6a9d42b1f6cab2752e Mon Sep 17 00:00:00 2001 From: Rossetto Date: Thu, 16 Nov 2023 16:22:03 +0100 Subject: [PATCH 12/14] parser is workiiiiing :DDD! All data get in DB --- fluxRSS/src/DAL/ArticleGateway.php | 2 +- fluxRSS/src/metier/Article.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php index 2bb7da7..233dfa5 100755 --- a/fluxRSS/src/DAL/ArticleGateway.php +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -35,7 +35,7 @@ class ArticleGateway */ public function addArticle(Article $article){ try { - $query = 'INSERT INTO Article VALUES (:id,:title,datePub,:description,:guid,:link,:mediaContent,:provenance);'; + $query = 'INSERT INTO Article VALUES (:id,:title,:datePub,:description,:guid,:link,:mediaContent,:provenance);'; $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_INT), ':title' => array($article->getTitle(), PDO::PARAM_STR), ':datePub' => array($article->getDate(), PDO::PARAM_STR), diff --git a/fluxRSS/src/metier/Article.php b/fluxRSS/src/metier/Article.php index d4a2cf0..6a2c8b2 100755 --- a/fluxRSS/src/metier/Article.php +++ b/fluxRSS/src/metier/Article.php @@ -24,7 +24,7 @@ class Article * @param int $provenance */ public function __construct( - int $id, + ?int $id, string $title, string $date, string $description, From 61981d5aa0b8d502171e35e6123682f44b6ba3f5 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Sat, 18 Nov 2023 12:48:41 +0100 Subject: [PATCH 13/14] adminGateway modification --- fluxRSS/src/DAL/FluxGateway.php | 2 -- fluxRSS/src/model/Parser.php | 21 --------------------- fluxRSS/src/test/test.php | 1 - 3 files changed, 24 deletions(-) diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 35b61a9..87d27a9 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -42,8 +42,6 @@ class FluxGateway $query = 'SELECT * FROM Flux;'; $this->con->executeQuery($query); $results = $this->con->getResults(); - print("result findAllFlux Gateway"); - var_dump($results); return $results; }catch (\PDOException $e){ throw new \Exception("PDO error"); diff --git a/fluxRSS/src/model/Parser.php b/fluxRSS/src/model/Parser.php index 722a06a..cce7f32 100755 --- a/fluxRSS/src/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -21,28 +21,17 @@ class Parser } public function parseArticles(Flux $flux): array { - print("debut parseArticles******************
"); $dom = new DOMDocument(); - print("creation du dom
"); $tabArticle = array(); - if ($dom->load($flux->getFlux())){ $items = $dom->getElementsByTagName('item'); - print("après avoir getElementByTagName
"); - var_dump($items); foreach ($items as $item) { $title = $item->getElementsByTagName('title')[0]->nodeValue; - print("le titre
"); - var_dump($title); $date = $item->getElementsByTagName('pubDate')[0]->nodeValue; - print("la date
"); - var_dump($date); $guid = $item->getElementsByTagName('guid')[0]->nodeValue; $link = $item->getElementsByTagName('link')[0]->nodeValue; $description = $item->getElementsByTagName('description')[0]->nodeValue; $media = $item->getElementsByTagName('media:content'); - print("media :
"); - var_dump($media); $mediaUrl = null; if ($media->length > 0){ $mediaUrl = $media->item(0)->getAttribute('url'); @@ -57,8 +46,6 @@ class Parser $link, ($mediaUrl !== null) ? (string)$mediaUrl : '', $flux->getId()); - print("Tableau de l'article"); - var_dump($tabArticle); } return $tabArticle; } else { @@ -73,16 +60,11 @@ class Parser */ public function parseAll($fluxes){ $tabArticles = []; - print("debut parseAll
"); foreach ($fluxes as $flux){ $fluxx = new Flux($flux[0],$flux[1]); - print("flux de parseAll
"); - var_dump($fluxx); $tabArticles[] = $this->parseArticles($fluxx); - print("fin parsqeAll
"); } - var_dump($tabArticles); return $tabArticles; } @@ -98,9 +80,6 @@ class Parser foreach ($allItemFlux as $ItemFlux){ $tabFluxes[] = $ItemFlux[1]; } - print("tableau de flux
"); - var_dump($tabFluxes); - $allTabArticles = $this->parseAll($allItemFlux); foreach ($allTabArticles as $tabArticle) { diff --git a/fluxRSS/src/test/test.php b/fluxRSS/src/test/test.php index 68afbe3..ff5c34a 100755 --- a/fluxRSS/src/test/test.php +++ b/fluxRSS/src/test/test.php @@ -10,5 +10,4 @@ require '../../vendor/autoload.php'; $gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $pars = new Parser( $gwFl,$gwArt); -var_dump($pars->addAllArticles()); From d6b7c623061a1a3187c1c00d4c2267389ab7cd7c Mon Sep 17 00:00:00 2001 From: Rossetto Date: Sat, 18 Nov 2023 14:44:07 +0100 Subject: [PATCH 14/14] little correction --- fluxRSS/src/DAL/ArticleGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php index 233dfa5..027711e 100755 --- a/fluxRSS/src/DAL/ArticleGateway.php +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -54,7 +54,7 @@ class ArticleGateway $query = 'DELETE FROM Article;'; $this->con->executeQuery($query); }catch(\PDOException $p){ - throw new Exception("Data is not delete."); + throw new Exception("Data is not deleted."); } } } \ No newline at end of file