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 ArrayAccess; 21 use MongoDB\Exception\BadMethodCallException; 22 use function array_key_exists; 23 24 /** 25 * Collection information model class. 26 * 27 * This class models the collection information returned by the listCollections 28 * command or, for legacy servers, queries on the "system.namespaces" 29 * collection. It provides methods to access options for the collection. 30 * 31 * @api 32 * @see \MongoDB\Database::listCollections() 33 * @see https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst 34 */ 35 class CollectionInfo implements ArrayAccess 36 { 37 /** @var array */ 38 private $info; 39 40 /** 41 * @param array $info Collection info 42 */ 43 public function __construct(array $info) 44 { 45 $this->info = $info; 46 } 47 48 /** 49 * Return the collection info as an array. 50 * 51 * @see http://php.net/oop5.magic#language.oop5.magic.debuginfo 52 * @return array 53 */ 54 public function __debugInfo() 55 { 56 return $this->info; 57 } 58 59 /** 60 * Return the maximum number of documents to keep in the capped collection. 61 * 62 * @return integer|null 63 */ 64 public function getCappedMax() 65 { 66 /* The MongoDB server might return this number as an integer or float */ 67 return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null; 68 } 69 70 /** 71 * Return the maximum size (in bytes) of the capped collection. 72 * 73 * @return integer|null 74 */ 75 public function getCappedSize() 76 { 77 /* The MongoDB server might return this number as an integer or float */ 78 return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null; 79 } 80 81 /** 82 * Return the collection name. 83 * 84 * @return string 85 */ 86 public function getName() 87 { 88 return (string) $this->info['name']; 89 } 90 91 /** 92 * Return the collection options. 93 * 94 * @return array 95 */ 96 public function getOptions() 97 { 98 return isset($this->info['options']) ? (array) $this->info['options'] : []; 99 } 100 101 /** 102 * Return whether the collection is a capped collection. 103 * 104 * @return boolean 105 */ 106 public function isCapped() 107 { 108 return ! empty($this->info['options']['capped']); 109 } 110 111 /** 112 * Check whether a field exists in the collection information. 113 * 114 * @see http://php.net/arrayaccess.offsetexists 115 * @param mixed $key 116 * @return boolean 117 */ 118 public function offsetExists($key) 119 { 120 return array_key_exists($key, $this->info); 121 } 122 123 /** 124 * Return the field's value from the collection information. 125 * 126 * @see http://php.net/arrayaccess.offsetget 127 * @param mixed $key 128 * @return mixed 129 */ 130 public function offsetGet($key) 131 { 132 return $this->info[$key]; 133 } 134 135 /** 136 * Not supported. 137 * 138 * @see http://php.net/arrayaccess.offsetset 139 * @param mixed $key 140 * @param mixed $value 141 * @throws BadMethodCallException 142 */ 143 public function offsetSet($key, $value) 144 { 145 throw BadMethodCallException::classIsImmutable(self::class); 146 } 147 148 /** 149 * Not supported. 150 * 151 * @see http://php.net/arrayaccess.offsetunset 152 * @param mixed $key 153 * @throws BadMethodCallException 154 */ 155 public function offsetUnset($key) 156 { 157 throw BadMethodCallException::classIsImmutable(self::class); 158 } 159 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body