@@ -843,16 +843,16 @@ | |||
}, | |||
{ | |||
"name": "symfony/polyfill-php80", | |||
"version": "v1.23.1", | |||
"version": "v1.24.0", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/symfony/polyfill-php80.git", | |||
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" | |||
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", | |||
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", | |||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9", | |||
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
@@ -906,7 +906,7 @@ | |||
"shim" | |||
], | |||
"support": { | |||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" | |||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0" | |||
}, | |||
"funding": [ | |||
{ | |||
@@ -922,7 +922,7 @@ | |||
"type": "tidelift" | |||
} | |||
], | |||
"time": "2021-07-28T13:41:28+00:00" | |||
"time": "2021-09-13T13:58:33+00:00" | |||
}, | |||
{ | |||
"name": "twig/twig", |
@@ -11,16 +11,17 @@ use Psr\Http\Message\ServerRequestInterface as Request; | |||
use Slim\Factory\AppFactory; | |||
use Blog\DB\User; | |||
use Blog\DB\Blog; | |||
use Blog\View\Twig; | |||
require __DIR__ . '/../vendor/autoload.php'; | |||
$twig = new Twig('../templates'); | |||
require __DIR__ . '/../vendor/autoload.php'; | |||
$app = AppFactory::create(); | |||
$loader = new \Twig\Loader\FilesystemLoader('../templates'); | |||
$twig = new \Twig\Environment($loader, []); | |||
//$db = new DB(); | |||
ini_set('display_errors', 'Off'); | |||
@@ -63,8 +64,7 @@ $app->get('/', function (Request $request, Response $response, array $args) { | |||
]; | |||
global $twig; | |||
$template = $twig->load('index.html.twig'); | |||
$a = $template->render($vars); | |||
$a = $twig->render('index.html.twig', $vars); | |||
$response->getBody()->write($a); | |||
return $response; | |||
}); |
@@ -1,37 +0,0 @@ | |||
<?php | |||
namespace Blog; | |||
use SQLite3; | |||
class DB extends SQLite3 | |||
{ | |||
function __construct() | |||
{ | |||
$this->open('../private/test.db'); | |||
} | |||
public function checkUserPass($user, $pass) | |||
{ | |||
$sql = "SELECT count(*) as count FROM users WHERE username = '" . $user . "' AND password = '" . $pass . "';"; | |||
$ret = $this->query($sql); | |||
$rows = $ret->fetchArray(SQLITE3_ASSOC); | |||
$rowcount = $rows['count']; | |||
if ($rowcount == 1) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
public function createBlog($data) | |||
{ | |||
$this->enableExceptions(false); | |||
$stmt = $this->prepare("INSERT INTO blogs (slug, title, content) VALUES (:slug, :title, :content)"); | |||
$stmt->bindValue(':slug', $data['slug'], SQLITE3_TEXT); | |||
$stmt->bindValue(':title', $data['title'], SQLITE3_TEXT); | |||
$stmt->bindValue(':content', $data['content'], SQLITE3_TEXT); | |||
$res = $stmt->execute(); | |||
return $res; | |||
} | |||
} |
@@ -0,0 +1,36 @@ | |||
<?php | |||
namespace Blog\View; | |||
use Twig\Loader\FilesystemLoader; | |||
use Twig\Environment; | |||
class Twig | |||
{ | |||
protected $twig; | |||
protected $variables; | |||
public function __construct($tmpl_folder) | |||
{ | |||
$loader = new FilesystemLoader($tmpl_folder); | |||
$this->twig = new Environment($loader, []); | |||
} | |||
protected function load($tmpl) | |||
{ | |||
return $this->twig->load($tmpl); | |||
} | |||
public function addToVar($data) | |||
{ | |||
// TODO: Add data to variables | |||
//$this->variables = $data + | |||
} | |||
public function render($tmpl, $vars) | |||
{ | |||
$template = $this->load($tmpl); | |||
$variables = $vars; // TODO: add global variables | |||
return $template->render($variables); | |||
} | |||
} |