-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHistory.php
More file actions
40 lines (34 loc) · 767 Bytes
/
History.php
File metadata and controls
40 lines (34 loc) · 767 Bytes
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
<?php
namespace Imaarov\Patterns\Behavioral\Memento;
class History {
private array $states;
/**
* Push some value in states array
*
* @param BrowserState $browserState
* @return void
*/
public function push(BrowserState $browserState) {
$this->states[] = $browserState;
}
/**
* Remove last element and return it.
*
* @return BrowserState
*/
public function pop() : BrowserState
{
$last_value = $this->states[count($this->states) - 1];
array_pop($this->states);
return $last_value;
}
/**
* Show all saved history
*
* @return array
*/
public function showAllHistory() : array
{
return $this->states;
}
}