summaryrefslogtreecommitdiff
path: root/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/LogList.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/LogList.php
parent8c201ace3699b4928daf41eb7b4cdcb4565c6f3b (diff)
adds reevotech scripts
Diffstat (limited to 'bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/LogList.php')
-rw-r--r--bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/LogList.php138
1 files changed, 138 insertions, 0 deletions
diff --git a/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/LogList.php b/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/LogList.php
new file mode 100644
index 00000000..9ce30263
--- /dev/null
+++ b/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/LogList.php
@@ -0,0 +1,138 @@
+<?php
+
+namespace Mediawiki\DataModel;
+
+use InvalidArgumentException;
+use JsonSerializable;
+use RuntimeException;
+
+/**
+ * Represents a collection of Log classes
+ * @author Addshore
+ */
+class LogList implements JsonSerializable {
+
+ /**
+ * @var Log[]
+ */
+ private $logs;
+
+ /**
+ * @param Log[] $logs
+ */
+ public function __construct( $logs = array() ) {
+ $this->logs = array();
+ $this->addLogs( $logs );
+ }
+
+ /**
+ * @param Log[]|LogList $logs
+ *
+ * @throws InvalidArgumentException
+ */
+ public function addLogs( $logs ) {
+ if( !is_array( $logs ) && !$logs instanceof LogList ) {
+ throw new InvalidArgumentException( '$logs needs to either be an array or a LogList object' );
+ }
+ if( $logs instanceof LogList ) {
+ $logs = $logs->toArray();
+ }
+ foreach( $logs as $log ) {
+ $this->addLog( $log );
+ }
+ }
+
+ /**
+ * @param Log $log
+ */
+ public function addLog( Log $log ) {
+ $this->logs[$log->getId()] = $log;
+ }
+
+ /**
+ * @param int $id
+ *
+ * @return bool
+ */
+ public function hasLogWithId( $id ){
+ return array_key_exists( $id, $this->logs );
+ }
+
+ /**
+ * @param Log $log
+ *
+ * @return bool
+ */
+ public function hasLog( Log $log ){
+ return array_key_exists( $log->getId(), $this->logs );
+ }
+
+ /**
+ * @return Log|null Log or null if there is no log
+ */
+ public function getLatest() {
+ if( empty( $this->logs ) ) {
+ return null;
+ }
+ return $this->logs[ max( array_keys( $this->logs ) ) ];
+ }
+
+ /**
+ * @since 0.6
+ * @return Log|null Log or null if there is no log
+ */
+ public function getOldest() {
+ if( empty( $this->logs ) ) {
+ return null;
+ }
+ return $this->logs[ min( array_keys( $this->logs ) ) ];
+ }
+
+ /**
+ * @since 0.6
+ * @return bool
+ */
+ public function isEmpty() {
+ return empty( $this->logs );
+ }
+
+ /**
+ * @param int $id
+ *
+ * @throws RuntimeException
+ * @return Log
+ */
+ public function get( $id ){
+ if( $this->hasLogWithId( $id ) ){
+ return $this->logs[$id];
+ }
+ throw new RuntimeException( 'No such Log loaded in LogList object' );
+ }
+
+ /**
+ * @return Log[]
+ */
+ public function toArray() {
+ return $this->logs;
+ }
+
+ /**
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ */
+ public function jsonSerialize() {
+ return $this->toArray();
+ }
+
+ /**
+ * @param array $json
+ *
+ * @return self
+ */
+ public static function jsonDeserialize( $json ) {
+ $self = new LogList();
+ foreach ( $json as $logJson ) {
+ $self->addLog( Log::jsonDeserialize( $logJson ) );
+ }
+ return $self;
+ }
+} \ No newline at end of file