summaryrefslogtreecommitdiff
path: root/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/Revisions.php
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2021-10-19 20:42:50 -0300
committerYaco <franco@reevo.org>2021-10-19 20:42:50 -0300
commit1dc109c979d7788e8811b4eecfb8bfdf3b6ea6e2 (patch)
tree21d2a3bd6706af9eeb3e9d1def5a6ab8d8a67e93 /bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/Revisions.php
parent8c201ace3699b4928daf41eb7b4cdcb4565c6f3b (diff)
adds reevotech scripts
Diffstat (limited to 'bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/Revisions.php')
-rw-r--r--bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/Revisions.php102
1 files changed, 102 insertions, 0 deletions
diff --git a/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/Revisions.php b/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/Revisions.php
new file mode 100644
index 00000000..c6d2f436
--- /dev/null
+++ b/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/Revisions.php
@@ -0,0 +1,102 @@
+<?php
+
+namespace Mediawiki\DataModel;
+
+use InvalidArgumentException;
+use RuntimeException;
+
+/**
+ * Represents a collection or revisions
+ * @author Addshore
+ */
+class Revisions {
+
+ /**
+ * @var Revision[]
+ */
+ private $revisions;
+
+ /**
+ * @param Revisions[] $revisions
+ */
+ public function __construct( $revisions = array() ) {
+ $this->revisions = array();
+ $this->addRevisions( $revisions );
+ }
+
+ /**
+ * @param Revision[]|Revisions $revisions
+ *
+ * @throws InvalidArgumentException
+ */
+ public function addRevisions( $revisions ) {
+ if( !is_array( $revisions ) && !$revisions instanceof Revisions ) {
+ throw new InvalidArgumentException( '$revisions needs to either be an array or a Revisions object' );
+ }
+ if( $revisions instanceof Revisions ) {
+ $revisions = $revisions->toArray();
+ }
+ foreach( $revisions as $revision ) {
+ $this->addRevision( $revision );
+ }
+ }
+
+ /**
+ * @param Revision $revision
+ */
+ public function addRevision( Revision $revision ) {
+ $this->revisions[$revision->getId()] = $revision;
+ }
+
+ /**
+ * @param int $id
+ *
+ * @return bool
+ */
+ public function hasRevisionWithId( $id ){
+ return array_key_exists( $id, $this->revisions );
+ }
+
+ /**
+ * @param Revision $revision
+ *
+ * @return bool
+ */
+ public function hasRevision( Revision $revision ){
+ return array_key_exists( $revision->getId(), $this->revisions );
+ }
+
+ /**
+ * @return Revision|null Revision or null if there is no revision
+ */
+ public function getLatest() {
+ if( empty( $this->revisions ) ) {
+ return null;
+ }
+ return $this->revisions[ max( array_keys( $this->revisions ) ) ];
+ }
+
+ /**
+ * @param int $revid
+ *
+ * @throws RuntimeException
+ * @throws InvalidArgumentException
+ * @return Revision
+ */
+ public function get( $revid ){
+ if( !is_int( $revid ) ) {
+ throw new InvalidArgumentException( '$revid needs to be an int' );
+ }
+ if( $this->hasRevisionWithId( $revid ) ){
+ return $this->revisions[$revid];
+ }
+ throw new RuntimeException( 'No such revision loaded in Revisions object' );
+ }
+
+ /**
+ * @return Revision[]
+ */
+ public function toArray() {
+ return $this->revisions;
+ }
+} \ No newline at end of file