Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

   1  <?php
   2  /*
   3   * Copyright 2015-present 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   *   https://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 https://mongodb.com/docs/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       *  * authorizedCollections (boolean): Determines which collections are
  48       *    returned based on the user privileges.
  49       *
  50       *    For servers < 4.0, this option is ignored.
  51       *
  52       *  * comment (mixed): BSON value to attach as a comment to this command.
  53       *
  54       *    This is not supported for servers versions < 4.4.
  55       *
  56       *  * filter (document): Query by which to filter collections.
  57       *
  58       *  * maxTimeMS (integer): The maximum amount of time to allow the query to
  59       *    run.
  60       *
  61       *  * session (MongoDB\Driver\Session): Client session.
  62       *
  63       * @param string $databaseName Database name
  64       * @param array  $options      Command options
  65       * @throws InvalidArgumentException for parameter/option parsing errors
  66       */
  67      public function __construct(string $databaseName, array $options = [])
  68      {
  69          $this->databaseName = $databaseName;
  70          $this->listCollections = new ListCollectionsCommand($databaseName, ['nameOnly' => false] + $options);
  71      }
  72  
  73      /**
  74       * Execute the operation.
  75       *
  76       * @see Executable::execute()
  77       * @return CollectionInfoIterator
  78       * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
  79       */
  80      public function execute(Server $server)
  81      {
  82          return new CollectionInfoCommandIterator($this->listCollections->execute($server), $this->databaseName);
  83      }
  84  }