DatabaseInfo.php 1.9 KB
Newer Older
1
<?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright 2015-2017 MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
17 18 19

namespace MongoDB\Model;

20 21 22 23 24 25 26
/**
 * Database information model class.
 *
 * This class models the database information returned by the listDatabases
 * command. It provides methods to access common database properties.
 *
 * @api
27
 * @see \MongoDB\Client::listDatabases()
28 29
 * @see http://docs.mongodb.org/manual/reference/command/listDatabases/
 */
30 31
class DatabaseInfo
{
32
    private $info;
33 34

    /**
Jeremy Mikola's avatar
Jeremy Mikola committed
35 36 37 38
     * Constructor.
     *
     * @param array $info Database info
     */
39 40
    public function __construct(array $info)
    {
41
        $this->info = $info;
42 43
    }

44 45 46 47 48 49 50 51 52 53 54
    /**
     * Return the collection info as an array.
     *
     * @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
     * @return array
     */
    public function __debugInfo()
    {
        return $this->info;
    }

55 56 57 58 59 60 61
    /**
     * Return the database name.
     *
     * @return string
     */
    public function getName()
    {
62
        return (string) $this->info['name'];
63 64 65 66 67 68 69 70 71
    }

    /**
     * Return the databases size on disk (in bytes).
     *
     * @return integer
     */
    public function getSizeOnDisk()
    {
72
        return (integer) $this->info['sizeOnDisk'];
73 74 75 76 77 78 79 80 81
    }

    /**
     * Return whether the database is empty.
     *
     * @return boolean
     */
    public function isEmpty()
    {
82
        return (boolean) $this->info['empty'];
83 84
    }
}