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