-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.php
42 lines (35 loc) · 1.02 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
use Imaarov\Patterns\Behavioral\Memento\Browser;
use Imaarov\Patterns\Behavioral\Memento\History;
class Main {
# Init the dependenies class (The history and state classes)
public function __construct(
private $browser = new Browser(),
private $history = new History()
)
{ }
public function setDataToTab(string $data, bool $saveToHistory = true)
{
# Set some data for tab
$this->browser->setTab($data);
# Create State and pass it to history
if($saveToHistory)
$this->history->push($this->browser->createState());
return true;
}
public function undo()
{
$this->browser->restore($this->history->pop());
return $this->browser->getTab();
}
public function showAllHistory() : array
{
return $this->history->showAllHistory();
}
}
$m = new Main();
$m->setDataToTab("some 1");
$m->setDataToTab("some 2");
$m->setDataToTab("lkanfldknalksdf");
echo $m->undo() . PHP_EOL;
print_r($m->showAllHistory());