<?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;
<?php use HttpStub\Storage\FileStorage; require_once __DIR__ . '/config.php'; $storage = new FileStorage('subjects'); $subject = []; if (isset($_POST['subject']) && !empty($_POST['subject'])) { $subject = $_POST; $storage->insert($subject); }
<?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));
<?php use HttpStub\Storage\FileStorage; require_once __DIR__ . '/config.php'; require_once 'functions.php'; $storage = new FileStorage('users'); $key = getValue($_GET, 'key', 0); $success = false; if ($storage->keyExists($key)) { $storage->delete($key); $success = true; } $message = $success ? 'The record was deleted' : 'Record not found'; header(sprintf('Location: index.php?message=%s&status=%d', $message, $success));
<?php use HttpStub\Storage\FileStorage; require_once __DIR__ . '/config.php'; require_once 'functions.php'; $storage = new FileStorage('posts'); $category = getValue($_GET, 'category'); $data = $storage->readAll(); $data = (array) $data; end($data); //moving the internal pointer to the last element of the array $last = key($data); //getting the value of the index of the last element of the array require 'views/header.php'; require 'views/browse.php'; require 'views/footer.php';
<?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">
<?php use HttpStub\Storage\FileStorage; require_once __DIR__ . '/config.php'; require_once 'functions.php'; $blogDate = date("d.m.Y H:i"); $blogsStorage = new FileStorage('blogs'); $subjectsStorage = new FileStorage('subjects'); $subjects = $subjectsStorage->readAll(); $data = []; $errors = []; if ($_POST) { $data = $_POST; if (!getValue($data, 'title') || mb_strlen(getValue($data, 'title'), 'UTF-8') < 5) { $errors[] = 'Title at last 5 characters is required'; } if (!getValue($data, 'text')) { $errors[] = 'Text is required'; } if (!$errors) { $blogsStorage->insert($data); header('Location: blogs.php'); die; } } $data = (array) $data; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8">
<?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 = []; } $data = (array) $data; require 'views/header.php'; require 'views/viewArticle.php'; require 'views/footer.php';