DatabaseInfo.php 1.31 KB
Newer Older
1 2 3 4
<?php

namespace MongoDB\Model;

5 6 7 8 9 10 11 12 13 14
/**
 * Database information model class.
 *
 * This class models the database information returned by the listDatabases
 * command. It provides methods to access common database properties.
 *
 * @api
 * @see MongoDB\Client::listDatabases()
 * @see http://docs.mongodb.org/manual/reference/command/listDatabases/
 */
15 16
class DatabaseInfo
{
17
    private $info;
18 19 20 21 22 23 24 25

    /**
    * Constructor.
    *
    * @param array $info Database info
    */
    public function __construct(array $info)
    {
26
        $this->info = $info;
27 28
    }

29 30 31 32 33 34 35 36 37 38 39
    /**
     * 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;
    }

40 41 42 43 44 45 46
    /**
     * Return the database name.
     *
     * @return string
     */
    public function getName()
    {
47
        return (string) $this->info['name'];
48 49 50 51 52 53 54 55 56
    }

    /**
     * Return the databases size on disk (in bytes).
     *
     * @return integer
     */
    public function getSizeOnDisk()
    {
57
        return (integer) $this->info['sizeOnDisk'];
58 59 60 61 62 63 64 65 66
    }

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