CollectionInfo.php 2.59 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 27
/**
 * 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
28
 * @see \MongoDB\Database::listCollections()
29 30
 * @see https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst
 */
31 32
class CollectionInfo
{
33
    private $info;
34 35

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

45 46 47 48 49 50 51 52 53 54 55
    /**
     * 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;
    }

56
    /**
57
     * Return the maximum number of documents to keep in the capped collection.
58
     *
59
     * @return integer|null
60
     */
61
    public function getCappedMax()
62
    {
63
        return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
64 65 66
    }

    /**
67
     * Return the maximum size (in bytes) of the capped collection.
68
     *
69
     * @return integer|null
70
     */
71
    public function getCappedSize()
72
    {
73
        return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
74 75 76
    }

    /**
77
     * Return the collection name.
78
     *
79
     * @return string
80
     */
81
    public function getName()
82
    {
83
        return (string) $this->info['name'];
84 85 86
    }

    /**
87
     * Return the collection options.
88
     *
89
     * @return array
90
     */
91
    public function getOptions()
92
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
93
        return isset($this->info['options']) ? (array) $this->info['options'] : [];
94 95 96
    }

    /**
97
     * Return whether the collection is a capped collection.
98
     *
99
     * @return boolean
100
     */
101
    public function isCapped()
102
    {
103
        return ! empty($this->info['options']['capped']);
104 105
    }
}