Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401]

   1  <?php
   2  /*
   3   * Copyright 2015-2017 MongoDB, Inc.
   4   *
   5   * Licensed under the Apache License, Version 2.0 (the "License");
   6   * you may not use this file except in compliance with the License.
   7   * You may obtain a copy of the License at
   8   *
   9   *   http://www.apache.org/licenses/LICENSE-2.0
  10   *
  11   * Unless required by applicable law or agreed to in writing, software
  12   * distributed under the License is distributed on an "AS IS" BASIS,
  13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14   * See the License for the specific language governing permissions and
  15   * limitations under the License.
  16   */
  17  
  18  namespace MongoDB\Model;
  19  
  20  use function current;
  21  use function key;
  22  use function next;
  23  use function reset;
  24  
  25  /**
  26   * DatabaseInfoIterator for inline listDatabases command results.
  27   *
  28   * This iterator may be used to wrap the array returned within the listDatabases
  29   * command's single-document result.
  30   *
  31   * @internal
  32   * @see \MongoDB\Client::listDatabases()
  33   * @see http://docs.mongodb.org/manual/reference/command/listDatabases/
  34   */
  35  class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
  36  {
  37      /** @var array */
  38      private $databases;
  39  
  40      /**
  41       * @param array $databases
  42       */
  43      public function __construct(array $databases)
  44      {
  45          $this->databases = $databases;
  46      }
  47  
  48      /**
  49       * Return the current element as a DatabaseInfo instance.
  50       *
  51       * @see DatabaseInfoIterator::current()
  52       * @see http://php.net/iterator.current
  53       * @return DatabaseInfo
  54       */
  55      public function current()
  56      {
  57          return new DatabaseInfo(current($this->databases));
  58      }
  59  
  60      /**
  61       * Return the key of the current element.
  62       *
  63       * @see http://php.net/iterator.key
  64       * @return integer
  65       */
  66      public function key()
  67      {
  68          return key($this->databases);
  69      }
  70  
  71      /**
  72       * Move forward to next element.
  73       *
  74       * @see http://php.net/iterator.next
  75       */
  76      public function next()
  77      {
  78          next($this->databases);
  79      }
  80  
  81      /**
  82       * Rewind the Iterator to the first element.
  83       *
  84       * @see http://php.net/iterator.rewind
  85       */
  86      public function rewind()
  87      {
  88          reset($this->databases);
  89      }
  90  
  91      /**
  92       * Checks if current position is valid.
  93       *
  94       * @see http://php.net/iterator.valid
  95       * @return boolean
  96       */
  97      public function valid()
  98      {
  99          return key($this->databases) !== null;
 100      }
 101  }