Esempio n. 1
0
<?php

use HttpStub\Settings;
use HttpStub\Storage\FileStorage;
require_once __DIR__ . '/vendor/autoload.php';
\HttpStub\Settings::set(\HttpStub\Settings::PATH, __DIR__ . '/.data');
$storage = new \HttpStub\Storage\FileStorage('users');
$key = $storage->insert(['full_name' => 'Test Test', 'email' => '*****@*****.**']);
var_dump($storage->read($key));
Esempio n. 2
0
<?php

use HttpStub\Storage\FileStorage;
require_once __DIR__ . '/config.php';
require_once 'functions.php';
$storage = new FileStorage('posts');
if ($key = getValue($_GET, 'key')) {
    $data = $storage->read($key);
} else {
    $data = [];
}
$errors = [];
if ($_POST) {
    $data = $_POST;
    if (!getValue($data, 'title')) {
        $errors[] = 'Title is required!';
    }
    if (!getValue($data, 'content')) {
        $errors[] = 'Content of the article is required!';
    }
    if (!$errors) {
        if ($key) {
            $storage->update($key, $data);
        } else {
            $storage->insert($data);
        }
        header('Location: index.php');
        die;
    }
}
$data = (array) $data;
Esempio n. 3
0
<?php

use HttpStub\Storage\FileStorage;
require_once __DIR__ . '/config.php';
require_once 'functions.php';
$input = [];
$storage = new FileStorage('users');
$data = $storage->read('1');
$errors = [];
if ($_POST) {
    $input = $_POST;
    if (!getValue($input, 'username')) {
        $errors[] = 'Username is required';
    }
    if (!getValue($input, 'password')) {
        $errors[] = 'Password is required';
    }
    if (getValue($input, 'username') !== $data['username'] || getValue($input, 'password') !== $data['password']) {
        $errors[] = 'Wrong username or password';
    }
    if (!$errors) {
        header('Location: blogs.php');
        die;
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">