pull/6/head
maxime.batista 1 year ago
parent 5fe901253c
commit b1da73b743

8
.gitignore vendored

@ -1,11 +1,13 @@
.idea
.vs
.code
.*
vendor
composer.lock
*.phar
/dist
# sqlite database files
*.sqlite
views-mappings.php
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

@ -102,6 +102,7 @@ the file is replaced with `prod-config-file.php` by the CI when deploying to the
The two profiles declares an `_asset(string $uri)` function, used by the `/config.php::asset` method, but with different implementations :
### Development profile
```php
$hostname = getHostName();
$front_url = "http://$hostname:5173";
@ -110,8 +111,6 @@ function _asset(string $assetURI): string {
global $front_url;
return $front_url . "/" . $assetURI;
}
```
The simplest profile, simply redirect all assets to the development server

@ -48,5 +48,5 @@ steps:
- echo "$SERVER_PRIVATE_KEY" > ~/.ssh/id_rsa
- 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
- rsync -rvz -e "ssh -p 80 -o 'StrictHostKeyChecking=no'" --delete /outputs/* iqball@maxou.dev:/server/nginx/IQBall/$DRONE_BRANCH

@ -6,6 +6,8 @@
},
"require": {
"altorouter/altorouter": "1.2.0",
"ext-json": "*"
"ext-json": "*",
"ext-pdo": "*",
"ext-pdo_sqlite": "*"
}
}

@ -16,4 +16,8 @@ function asset(string $assetURI): string {
return _asset($assetURI);
}
global $_data_source_name;
$data_source_name = $_data_source_name;
const DATABASE_USER = _DATABASE_USER;
const DATABASE_PASSWORD = _DATABASE_PASSWORD;

@ -4,9 +4,17 @@ $hostname = getHostName();
$front_url = "http://$hostname:5173";
const _SUPPORTS_FAST_REFRESH = true;
$_data_source_name = "sqlite:${_SERVER['DOCUMENT_ROOT']}/../dev-database.sqlite";
function _asset(string $assetURI): string {
// no user and password needed for sqlite databases
const _DATABASE_USER = null;
const _DATABASE_PASSWORD = null;
function _asset(string $assetURI): string
{
global $front_url;
return $front_url . "/" . $assetURI;
}

@ -5,6 +5,12 @@
require "../views-mappings.php";
const _SUPPORTS_FAST_REFRESH = false;
$database_file = __DIR__ . "/../database.sqlite";
$_data_source_name = "sqlite:/$database_file";
// no user and password needed for sqlite databases
const _DATABASE_USER = null;
const _DATABASE_PASSWORD = null;
function _asset(string $assetURI): string {

@ -2,6 +2,7 @@
require "../vendor/autoload.php";
require "../config.php";
require "../sql/database.php";
use App\Controller\SampleFormController;
@ -21,6 +22,7 @@ function get_base_path() {
}
$basePath = get_base_path();
$pdo = get_database();
// routes initialization
$router = new AltoRouter();

@ -0,0 +1,32 @@
<?php
function get_database()
{
global $data_source_name;
// The presence of the .guard file says that the database has already been initialized.
$database_exists = file_exists(__DIR__ . "/.guard");
$pdo = new PDO($data_source_name, DATABASE_USER, DATABASE_PASSWORD);
if ($database_exists) {
return $pdo;
}
foreach (scandir(__DIR__) as $file) {
if (preg_match("/.*\.sql$/i", $file)) {
$content = file_get_contents(__DIR__ . "/" . $file);
foreach (preg_split("/;\s*/", $content) as $req) {
if ($req === "")
break;
$pdo->query($req);
}
}
}
touch(__DIR__ . "/.guard");
return $pdo;
}

@ -0,0 +1,8 @@
-- drop tables here
DROP TABLE IF EXISTS FormEntries;
CREATE TABLE FormEntries(name varchar, description varchar);
Loading…
Cancel
Save