See Release Notes
Long Term Support Release
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\Model; 19 20 use ArrayAccess; 21 use MongoDB\Exception\BadMethodCallException; 22 use ReturnTypeWillChange; 23 24 use function array_key_exists; 25 26 /** 27 * Database information model class. 28 * 29 * This class models the database information returned by the listDatabases 30 * command. It provides methods to access common database properties. 31 * 32 * @api 33 * @see \MongoDB\Client::listDatabases() 34 * @see https://mongodb.com/docs/manual/reference/command/listDatabases/ 35 */ 36 class DatabaseInfo implements ArrayAccess 37 { 38 /** @var array */ 39 private $info; 40 41 /** 42 * @param array $info Database info 43 */ 44 public function __construct(array $info) 45 { 46 $this->info = $info; 47 } 48 49 /** 50 * Return the database info as an array. 51 * 52 * @see https://php.net/oop5.magic#language.oop5.magic.debuginfo 53 * @return array 54 */ 55 public function __debugInfo() 56 { 57 return $this->info; 58 } 59 60 /** 61 * Return the database name. 62 * 63 * @return string 64 */ 65 public function getName() 66 { 67 return (string) $this->info['name']; 68 } 69 70 /** 71 * Return the databases size on disk (in bytes). 72 * 73 * @return integer 74 */ 75 public function getSizeOnDisk() 76 { 77 /* The MongoDB server might return this number as an integer or float */ 78 return (integer) $this->info['sizeOnDisk']; 79 } 80 81 /** 82 * Return whether the database is empty. 83 * 84 * @return boolean 85 */ 86 public function isEmpty() 87 { 88 return (boolean) $this->info['empty']; 89 } 90 91 /** 92 * Check whether a field exists in the database information. 93 * 94 * @see https://php.net/arrayaccess.offsetexists 95 * @param mixed $key 96 * @return boolean 97 */ 98 #[ReturnTypeWillChange] 99 public function offsetExists($key) 100 { 101 return array_key_exists($key, $this->info); 102 } 103 104 /** 105 * Return the field's value from the database information. 106 * 107 * @see https://php.net/arrayaccess.offsetget 108 * @param mixed $key 109 * @return mixed 110 */ 111 #[ReturnTypeWillChange] 112 public function offsetGet($key) 113 { 114 return $this->info[$key]; 115 } 116 117 /** 118 * Not supported. 119 * 120 * @see https://php.net/arrayaccess.offsetset 121 * @param mixed $key 122 * @param mixed $value 123 * @throws BadMethodCallException 124 * @return void 125 */ 126 #[ReturnTypeWillChange] 127 public function offsetSet($key, $value) 128 { 129 throw BadMethodCallException::classIsImmutable(self::class); 130 } 131 132 /** 133 * Not supported. 134 * 135 * @see https://php.net/arrayaccess.offsetunset 136 * @param mixed $key 137 * @throws BadMethodCallException 138 * @return void 139 */ 140 #[ReturnTypeWillChange] 141 public function offsetUnset($key) 142 { 143 throw BadMethodCallException::classIsImmutable(self::class); 144 } 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body