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