Answered step by step
Verified Expert Solution
Question
1 Approved Answer
URGENT!!! all required codes to solve the question are provided recipies.json { Poppy seed roll : [ poppyseed , sugar , milk , egg ,
URGENT!!! all required codes to solve the question are provided
recipies.json
{
"Poppy seed roll": [
"poppyseed",
"sugar",
"milk",
"egg",
"yeast",
"flour"
],
"Gingerbread": [
"flour",
"sugar",
"egg",
"honey",
"butter",
"bakingsoda"
],
"Coconut balls": [
"coconut",
"sugar",
"vanilla",
"butter",
"milk",
"biscuit"
],
"Tiramisu": [
"mascarpone",
"coffee",
"sugar",
"egg",
"cocoa",
"ladyfinger"
],
"Zserb": [
"peach",
"milk",
"sugar",
"yeast",
"flour",
"butter",
"walnut"
]
}
storage.php
interface IFileIO {
function save($data);
function load();
}
abstract class FileIO implements IFileIO {
protected $filepath;
public function __construct($filename) {
if (!is_readable($filename) || !is_writable($filename)) {
throw new Exception("Data source ${filename} is invalid.");
}
$this->filepath = realpath($filename);
}
}
class JsonIO extends FileIO {
public function load($assoc = true) {
$file_content = file_get_contents($this->filepath);
return json_decode($file_content, $assoc) ?: [];
}
public function save($data) {
$json_content = json_encode($data, JSON_PRETTY_PRINT);
file_put_contents($this->filepath, $json_content);
}
}
class SerializeIO extends FileIO {
public function load() {
$file_content = file_get_contents($this->filepath);
return unserialize($file_content) ?: [];
}
public function save($data) {
$serialized_content = serialize($data);
file_put_contents($this->filepath, $serialized_content);
}
}
interface IStorage {
function add($record): string;
function findById(string $id);
function findAll(array $params = []);
function findOne(array $params = []);
function update(string $id, $record);
function delete(string $id);
function findMany(callable $condition);
function updateMany(callable $condition, callable $updater);
function deleteMany(callable $condition);
}
class Storage implements IStorage {
protected $contents;
protected $io;
public function __construct(IFileIO $io, $assoc = true) {
$this->io = $io;
$this->contents = (array)$this->io->load($assoc);
}
public function __destruct() {
$this->io->save($this->contents);
}
public function add($record): string {
$id = uniqid();
if (is_array($record)) {
$record['id'] = $id;
}
else if (is_object($record)) {
$record->id = $id;
}
$this->contents[$id] = $record;
return $id;
}
public function findById(string $id) {
return $this->contents[$id] ?? NULL;
}
public function findAll(array $params = []) {
return array_filter($this->contents, function ($item) use ($params) {
foreach ($params as $key => $value) {
if (((array)$item)[$key] !== $value) {
return FALSE;
}
}
return TRUE;
});
}
public function findOne(array $params = []) {
$found_items = $this->findAll($params);
$first_index = array_keys($found_items)[0] ?? NULL;
return $found_items[$first_index] ?? NULL;
}
public function update(string $id, $record) {
$this->contents[$id] = $record;
}
public function delete(string $id) {
unset($this->contents[$id]);
}
public function findMany(callable $condition) {
return array_filter($this->contents, $condition);
}
public function updateMany(callable $condition, callable $updater) {
array_walk($this->contents, function (&$item) use ($condition, $updater) {
if ($condition($item)) {
$updater($item);
}
});
}
public function deleteMany(callable $condition) {
$this->contents = array_filter($this->contents, function ($item) use ($condition) {
return !$condition($item);
});
}
}
member.php
DOCTYPE html>
html lang="en">
head>
meta charset="UTF-8">
meta http-equiv="X-UA-Compatible" content="IE=edge">
meta name="viewport" content="width=device-width, initial-scale=1.0">
title>Task 3title>
link rel="stylesheet" href="index.css">
head>
body>
h1>Task 3: Gift listh1>
a href="index.php">Back to main pagea>
h2>Ideas for SELECTED FAMILY MEMBERh2>
form action="" method="post">
fieldset>
legend>New idealegend>
Idea: input type="text" name="idea" required>
button name="function-add" type="submit">Add new ideabutton>
fieldset>
form>
details>
summary>
Idea 1 span>span>
summary>
form action="" method="post">
input type="hidden" name="idea-id" value="">
Comment: input type="text" name="comment" required>
button type="submit" name="add-comment">Add commentbutton> br>
form>
form action="" method="post">
input type="hidden" name="idea-id" value="">
button type="submit" name="complete">Completebutton>
button type="submit" name="hide">Hidebutton>
form>
ul>
li>Comment 1li>
li>Comment 2li>
ul>
details>
details>
summary>
Idea 2
summary>
form action="" method="post">
input type="hidden" name="idea-id" value="">
Comment: input type="text" name="comment" required>
button type="submit" name="add-comment">Add commentbutton> br>
form>
form action="" method="post">
input type="hidden" name="idea-id" value="">
button type="submit" name="complete">Completebutton>
button type="submit" name="hide">Hidebutton>
form>
ul>
li>Comment 1li>
li>Comment 2li>
li>Comment 3li>
ul>
details>
body>
html>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started