ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
RevisionCollection.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
6use LogicException;
7
14{
15
19 private $revisions = [];
24
25
33 {
34 $this->identification = $identification;
35 $this->revisions = $revisions;
36 }
37
38
39 public function add(Revision $revision) : void
40 {
41 if ($this->identification->serialize() !== $revision->getIdentification()->serialize()) {
42 throw new LogicException("Can't add Revision sice it'ss not the same ResourceIdentification");
43 }
44 foreach ($this->revisions as $r) {
45 if ($r->getVersionNumber() === $revision->getVersionNumber()) {
46 throw new LogicException(sprintf("Can't add already existing version number: %s", $revision->getVersionNumber()));
47 }
48 }
49 $this->revisions[$revision->getVersionNumber()] = $revision;
50 sort($this->revisions);
51 }
52
53
54 public function remove(Revision $revision) : void
55 {
56 foreach ($this->revisions as $k => $revision_e) {
57 if ($revision->getVersionNumber() === $revision_e->getVersionNumber()) {
58 $revision_e->setUnavailable();
59
60 return;
61 }
62 }
63 }
64
65
66 public function replace(Revision $revision) : void
67 {
68 foreach ($this->revisions as $k => $revision_e) {
69 $revision_e->setUnavailable();
70 }
71 $this->add($revision);
72 }
73
74
75 public function getCurrent() : Revision
76 {
77 $current = end($this->revisions);
78 if (!$current instanceof Revision) {
79 $current = new NullRevision($this->identification);
80 }
81
82 return $current;
83 }
84
85
89 public function getAll() : array
90 {
91 return $this->revisions;
92 }
93}
An exception for terminatinating execution or to throw for unit testing.
__construct(ResourceIdentification $identification, array $revisions=[])
RevisionCollection constructor.