Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 401] [Versions 39 and 311]

   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\Operation;
  19  
  20  use MongoDB\Command\ListDatabases as ListDatabasesCommand;
  21  use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
  22  use MongoDB\Driver\Server;
  23  use MongoDB\Exception\InvalidArgumentException;
  24  use MongoDB\Exception\UnexpectedValueException;
  25  use MongoDB\Model\DatabaseInfoIterator;
  26  use MongoDB\Model\DatabaseInfoLegacyIterator;
  27  
  28  /**
  29   * Operation for the ListDatabases command.
  30   *
  31   * @api
  32   * @see \MongoDB\Client::listDatabases()
  33   * @see http://docs.mongodb.org/manual/reference/command/ListDatabases/
  34   */
  35  class ListDatabases implements Executable
  36  {
  37      /** @var ListDatabasesCommand */
  38      private $listDatabases;
  39  
  40      /**
  41       * Constructs a listDatabases command.
  42       *
  43       * Supported options:
  44       *
  45       *  * authorizedDatabases (boolean): Determines which databases are returned
  46       *    based on the user privileges.
  47       *
  48       *    For servers < 4.0.5, this option is ignored.
  49       *
  50       *  * filter (document): Query by which to filter databases.
  51       *
  52       *    For servers < 3.6, this option is ignored.
  53       *
  54       *  * maxTimeMS (integer): The maximum amount of time to allow the query to
  55       *    run.
  56       *
  57       *  * session (MongoDB\Driver\Session): Client session.
  58       *
  59       *    Sessions are not supported for server versions < 3.6.
  60       *
  61       * @param array $options Command options
  62       * @throws InvalidArgumentException for parameter/option parsing errors
  63       */
  64      public function __construct(array $options = [])
  65      {
  66          $this->listDatabases = new ListDatabasesCommand(['nameOnly' => false] + $options);
  67      }
  68  
  69      /**
  70       * Execute the operation.
  71       *
  72       * @see Executable::execute()
  73       * @param Server $server
  74       * @return DatabaseInfoIterator
  75       * @throws UnexpectedValueException if the command response was malformed
  76       * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
  77       */
  78      public function execute(Server $server)
  79      {
  80          return new DatabaseInfoLegacyIterator($this->listDatabases->execute($server));
  81      }
  82  }