Shanty_Mongo_Document::getRequirements PHP Method

getRequirements() public method

Get all requirements. If prefix is provided then only the requirements for the properties that start with prefix will be returned.
public getRequirements ( string $prefix = null )
$prefix string
    public function getRequirements($prefix = null)
    {
        // If no prefix is provided return all requirements
        if (is_null($prefix)) {
            return $this->_docRequirements;
        }
        // Find requirements for all properties starting with prefix
        $properties = array_filter(array_keys($this->_docRequirements), function ($value) use($prefix) {
            return substr_compare($value, $prefix, 0, strlen($prefix)) == 0 && strlen($value) > strlen($prefix);
        });
        $requirements = array_intersect_key($this->_docRequirements, array_flip($properties));
        // Remove prefix from requirement key
        $newRequirements = array();
        array_walk($requirements, function ($value, $key) use($prefix, &$newRequirements) {
            $newRequirements[substr($key, strlen($prefix))] = $value;
        });
        return $newRequirements;
    }