CollectionInfo.php 2 KB
Newer Older
1 2 3 4
<?php

namespace MongoDB\Model;

5 6 7 8 9 10 11 12 13 14 15
/**
 * Collection information model class.
 *
 * This class models the collection information returned by the listCollections
 * command or, for legacy servers, queries on the "system.namespaces"
 * collection. It provides methods to access options for the collection.
 *
 * @api
 * @see MongoDB\Database::listCollections()
 * @see https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst
 */
16 17
class CollectionInfo
{
18
    private $info;
19 20 21 22 23 24 25 26

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

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

41
    /**
42
     * Return the maximum number of documents to keep in the capped collection.
43
     *
44
     * @return integer|null
45
     */
46
    public function getCappedMax()
47
    {
48
        return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
49 50 51
    }

    /**
52
     * Return the maximum size (in bytes) of the capped collection.
53
     *
54
     * @return integer|null
55
     */
56
    public function getCappedSize()
57
    {
58
        return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
59 60 61
    }

    /**
62
     * Return the collection name.
63
     *
64
     * @return string
65
     */
66
    public function getName()
67
    {
68
        return (string) $this->info['name'];
69 70 71
    }

    /**
72
     * Return the collection options.
73
     *
74
     * @return array
75
     */
76
    public function getOptions()
77
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
78
        return isset($this->info['options']) ? (array) $this->info['options'] : [];
79 80 81
    }

    /**
82
     * Return whether the collection is a capped collection.
83
     *
84
     * @return boolean
85
     */
86
    public function isCapped()
87
    {
88
        return ! empty($this->info['options']['capped']);
89 90
    }
}