Write database configuration through dev-script.

This commit is contained in:
Yorin Anne De Jong 2016-08-18 23:17:24 +02:00
parent 32c6721ff0
commit 3655883c9f
5 changed files with 17 additions and 9 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
sql_config.php
*.sqlite

1
dev.sh
View File

@ -1,3 +1,4 @@
#!/bin/sh
which -s sqlite3 && test \! -e pvv.sqlite && sqlite3 pvv.sqlite < pvv.sql
test \! -e sql_config.php && cp sql_config_example.php sql_config.php
php -S [::]:1080 -t www/

5
sql_config_example.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$dbDsn = 'sqlite:'.__DIR__.DIRECTORY_SEPARATOR.'pvv.sqlite';
$dbUser = null;
$dbPass = null;

View File

@ -6,9 +6,8 @@ use \PDO;
class DBActivity implements RepeatingActivity {
public function __construct($dsn, $username, $password) {
$this->pdo = new PDO($dsn, $username, $password);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
public function __construct(PDO $pdo) {
$this->pdo = $pdo;
}
public function getNextEventFrom(DateTimeImmutable $date) {

View File

@ -1,7 +1,14 @@
<?php
require '../src/_autoload.php';
date_default_timezone_set('Europe/Oslo');
//include __DIR__.'/../sql_config.php';
require __DIR__ . '/../sql_config.php';
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$agenda = new \pvv\side\Agenda([
new \pvv\side\social\NerdepitsaActivity,
new \pvv\side\social\AnimekveldActivity,
new \pvv\side\DBActivity($pdo),
]); ?>
?><!DOCTYPE html>
<html lang="no">
<title>Programvareverkstedet</title>
@ -44,11 +51,6 @@ date_default_timezone_set('Europe/Oslo');
<?php $translation = ['i dag', 'i morgen', 'denne uka', 'denne måned', 'neste måned'] ?>
<?php $counter1 = 0; ?>
<?php $counter2 = 0; ?>
<?php $agenda = new \pvv\side\Agenda([
new \pvv\side\social\NerdepitsaActivity,
new \pvv\side\social\AnimekveldActivity,
new \pvv\side\DBActivity('sqlite:../pvv.sqlite', null, null),
]); ?>
<?php foreach($agenda->getNextDays() as $period => $events) if ($events && $counter1 < 2 && $counter2 < 10) { $counter1++ ?>
<li><p><?= $translation[$period] ?> <span><?= reset($events)->getStart()->format('Y-m-d'); ?></span></p>
<ul>