diff --git a/fluxRSS/DAL/Connection.php b/fluxRSS/DAL/Connection.php index 8be3ee1..dc58de2 100755 --- a/fluxRSS/DAL/Connection.php +++ b/fluxRSS/DAL/Connection.php @@ -2,7 +2,9 @@ namespace DAL; +use Exception; use PDO; +use Twig\Error\Error; class Connection extends PDO { @@ -12,26 +14,39 @@ class Connection extends PDO * @param string $dsn * @param string $username * @param string $password + * @throws Exception */ 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 (\PDOException $e){ + throw new Exception("PDO error con"); + } + catch (Error $e){ + throw new Error("Error PDO"); + } } /** * @param string $query to execute * @param array $parameters to bind * @return bool Returns `true` on success, `false` otherwise + * @throws Exception */ public function executeQuery(string $query, array $parameters = []): bool { - $this->stmt = parent::prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); - } + try{ + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } - return $this->stmt->execute(); + return $this->stmt->execute(); + }catch (\PDOException $e){ + throw new Exception("PDO error"); + } } /** diff --git a/fluxRSS/composer.lock b/fluxRSS/composer.lock old mode 100644 new mode 100755 diff --git a/fluxRSS/controleur/Controleur.php b/fluxRSS/controleur/Controleur.php index 5fbf48a..86ef927 100755 --- a/fluxRSS/controleur/Controleur.php +++ b/fluxRSS/controleur/Controleur.php @@ -51,12 +51,12 @@ class Controleur public function Reinit() { global $twig; // nécessaire pour utiliser variables globales - $dVue = [ 'nom' => '', 'age' => 0, + 'data' => ArticleModel::getArticles() ]; - echo $twig->render('vuephp1.html', [ + echo $twig->render('listArticle.html', [ 'dVue' => $dVue ]); } @@ -78,7 +78,7 @@ class Controleur $dVue = [ 'nom' => $nom, 'age' => $age, - 'data' => $data, + //'data' => $data, ]; echo $twig->render('vuephp1.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); diff --git a/fluxRSS/index.php b/fluxRSS/index.php index 0e8dfd4..fd16b5b 100755 --- a/fluxRSS/index.php +++ b/fluxRSS/index.php @@ -1,5 +1,4 @@ getAllArticles(); foreach($res as $row){ diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php index 6e61732..a965433 100755 --- a/fluxRSS/model/Parser.php +++ b/fluxRSS/model/Parser.php @@ -49,6 +49,9 @@ class Parser } + /** + * @throws Exception + */ public function parseAll($fluxes){ foreach ($fluxes as $flux){ $tabArticles[] =$this->parseArticles($flux); @@ -56,6 +59,9 @@ class Parser return $tabArticles; } + /** + * @throws Exception + */ public function addAllArticles(){ $allFlux = $this->fluxGateway->findAllFlux();