Merge branch 'master' into doc/conception-bdd
continuous-integration/drone/push Build is passing Details

pull/9/head
Vivien DUFOUR 1 year ago
commit a45f4d818b

@ -0,0 +1,12 @@
@startuml
class Connexion
class Modele
class Account
class AccountGateway
@enduml

@ -44,8 +44,6 @@ steps:
SERVER_PRIVATE_KEY: SERVER_PRIVATE_KEY:
from_secret: SERVER_PRIVATE_KEY from_secret: SERVER_PRIVATE_KEY
commands: commands:
- mkdir ~/.ssh - chmod +x ci/deploy.sh
- echo "$SERVER_PRIVATE_KEY" > ~/.ssh/id_rsa - ci/deploy.sh
- chmod 0600 ~/.ssh
- chmod 0500 ~/.ssh/id_rsa*
- rsync -avz -e "ssh -p 80 -o 'StrictHostKeyChecking=no'" --delete /outputs/* iqball@maxou.dev:/server/nginx/IQBall/$DRONE_BRANCH

@ -0,0 +1,9 @@
set -e
mkdir ~/.ssh
echo "$SERVER_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 0600 ~/.ssh
chmod 0500 ~/.ssh/id_rsa*
ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev mkdir -p /server/nginx/IQBall/$DRONE_BRANCH
rsync -avz -e "ssh -p 80 -o 'StrictHostKeyChecking=no'" --delete /outputs/* iqball@maxou.dev:/server/nginx/IQBall/$DRONE_BRANCH
ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev "chmod 770 /server/nginx/IQBall/$DRONE_BRANCH; chgrp www-data /server/nginx/IQBall/$DRONE_BRANCH"

@ -8,6 +8,7 @@
"altorouter/altorouter": "1.2.0", "altorouter/altorouter": "1.2.0",
"ext-json": "*", "ext-json": "*",
"ext-pdo": "*", "ext-pdo": "*",
"ext-pdo_sqlite": "*" "ext-pdo_sqlite": "*",
"twig/twig":"^2.0"
} }
} }

@ -4,6 +4,7 @@ require "../vendor/autoload.php";
require "../config.php"; require "../config.php";
require "../sql/database.php"; require "../sql/database.php";
use \Twig\Loader\FilesystemLoader;
use App\Connexion; use App\Connexion;
use App\Controller\SampleFormController; use App\Controller\SampleFormController;
use App\Gateway\FormResultGateway; use App\Gateway\FormResultGateway;
@ -23,6 +24,9 @@ function get_base_path() {
return $basePath; return $basePath;
} }
$loader = new FilesystemLoader('../src/Views/');
$twig = new \Twig\Environment($loader);
$basePath = get_base_path(); $basePath = get_base_path();
$con = new Connexion(get_database()); $con = new Connexion(get_database());
@ -30,9 +34,11 @@ $con = new Connexion(get_database());
$router = new AltoRouter(); $router = new AltoRouter();
$router->setBasePath($basePath); $router->setBasePath($basePath);
$sampleFormController = new SampleFormController(new FormResultGateway($con)); $sampleFormController = new SampleFormController(new FormResultGateway($con), $twig);
$router->map("GET", "/", fn() => $sampleFormController->displayForm()); $router->map("GET", "/", fn() => $sampleFormController->displayForm());
$router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST)); $router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST));
$router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig());
$router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST));
$match = $router->match(); $match = $router->match();

@ -6,7 +6,7 @@
function get_database(): PDO { function get_database(): PDO {
// defined by profiles. // defined by profiles.
global $data_source_name; global $data_source_name;
$pdo = new PDO($data_source_name, DATABASE_USER, DATABASE_PASSWORD); $pdo = new PDO($data_source_name, DATABASE_USER, DATABASE_PASSWORD, [PDO::ERRMODE_EXCEPTION]);
$database_exists = $pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'")->fetchColumn() > 0; $database_exists = $pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'")->fetchColumn() > 0;

@ -22,10 +22,7 @@ class Connexion {
* @return void * @return void
*/ */
public function exec(string $query, array $args) { public function exec(string $query, array $args) {
$stmnt = $this->pdo->prepare($query); $stmnt = $this->prepare($query, $args);
foreach ($args as $name => $value) {
$stmnt->bindValue($name, $value[0], $value[1]);
}
$stmnt->execute(); $stmnt->execute();
} }
@ -36,12 +33,17 @@ class Connexion {
* @return array the returned rows of the request * @return array the returned rows of the request
*/ */
public function fetch(string $query, array $args): array { public function fetch(string $query, array $args): array {
$stmnt = $this->prepare($query, $args);
$stmnt->execute();
return $stmnt->fetchAll(PDO::FETCH_ASSOC);
}
private function prepare(string $query, array $args): \PDOStatement {
$stmnt = $this->pdo->prepare($query); $stmnt = $this->pdo->prepare($query);
foreach ($args as $name => $value) { foreach ($args as $name => $value) {
$stmnt->bindValue($name, $value[0], $value[1]); $stmnt->bindValue($name, $value[0], $value[1]);
} }
$stmnt->execute(); return $stmnt;
return $stmnt->fetchAll();
} }
} }

@ -4,17 +4,23 @@ namespace App\Controller;
require_once __DIR__ . "/../react-display.php"; require_once __DIR__ . "/../react-display.php";
use App\Gateway\FormResultGateway; use App\Gateway\FormResultGateway;
use \Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
class SampleFormController { class SampleFormController {
private FormResultGateway $gateway; private FormResultGateway $gateway;
private Environment $twig;
/** /**
* @param FormResultGateway $gateway * @param FormResultGateway $gateway
*/ */
public function __construct(FormResultGateway $gateway) public function __construct(FormResultGateway $gateway, Environment $twig)
{ {
$this->gateway = $gateway; $this->gateway = $gateway;
$this->twig = $twig;
} }
@ -27,4 +33,22 @@ class SampleFormController {
$results = ["results" => $this->gateway->listResults()]; $results = ["results" => $this->gateway->listResults()];
send_react_front("views/DisplayResults.tsx", $results); send_react_front("views/DisplayResults.tsx", $results);
} }
public function displayFormTwig() {
try {
echo $this->twig->render('sample_form.html.twig', []);
} catch (LoaderError | RuntimeError | SyntaxError $e) {
echo "Twig error: $e";
}
}
public function submitFormTwig(array $request) {
$this->gateway->insert($request["name"], $request["description"]);
try {
$results = $this->gateway->listResults();
echo $this->twig->render('display_results.html.twig', ['results' => $results]);
} catch (LoaderError | RuntimeError | SyntaxError $e) {
echo "Twig error: $e";
}
}
} }

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twig view</title>
</head>
<body>
<h1>Hello world</h1>
{% for v in results %}
<p>username: {{ v.name }}</p>
<p>description: {{ v.description }}</p>
{% endfor %}
</body>
</html>

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twig view</title>
</head>
<body>
<h1>Hello, this is a sample form made in Twig !</h1>
<form action="submit-twig" method="POST">
<label for="name">your name: </label>
<input type="text" id="name" name="name"/>
<label for="password">a little description about yourself: </label>
<input type="text" id="password" name="description"/>
<input type="submit" value="click me to submit!"/>
</form>
</body>
</html>

@ -14,7 +14,6 @@
"; ";
} }
?> ?>
</script> </script>
<link rel="icon" href="<?= asset("assets/favicon.ico") ?>"> <link rel="icon" href="<?= asset("assets/favicon.ico") ?>">

Loading…
Cancel
Save