Commit d77b7fc2 authored by Jeremy Mikola's avatar Jeremy Mikola

Create functions.php file for utility functions

parent 9c108d5a
......@@ -13,7 +13,8 @@
"ext-mongodb": ">=0.6.0"
},
"autoload": {
"psr-4": { "MongoDB\\": "src/" }
"psr-4": { "MongoDB\\": "src/" },
"files": [ "src/functions.php" ]
},
"extra": {
"branch-alias": {
......
<?php
namespace MongoDB;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Return whether the first key in the document starts with a "$" character.
*
* This is used for differentiating update and replacement documents.
*
* @internal
* @param array|object $document Update or replacement document
* @return boolean
* @throws InvalidArgumentTypeException
*/
function is_first_key_operator($document)
{
if (is_object($document)) {
$document = get_object_vars($document);
}
if ( ! is_array($document)) {
throw new InvalidArgumentTypeException('$document', $document, 'array or object');
}
$firstKey = (string) key($document);
return (isset($firstKey[0]) && $firstKey[0] == '$');
}
/**
* Generate an index name from a key specification.
*
* @internal
* @param array|object $document Document containing fields mapped to values,
* which denote order or an index type
* @return string
* @throws InvalidArgumentTypeException
*/
function generate_index_name($document)
{
if (is_object($document)) {
$document = get_object_vars($document);
}
if ( ! is_array($document)) {
throw new InvalidArgumentTypeException('$document', $document, 'array or object');
}
$name = '';
foreach ($document as $field => $type) {
$name .= ($name != '' ? '_' : '') . $field . '_' . $type;
}
return $name;
}
/**
* Return whether the server supports a particular feature.
*
* @internal
* @param Server $server Server to check
* @param integer $feature Feature constant (i.e. wire protocol version)
* @return boolean
*/
function server_supports_feature(Server $server, $feature)
{
$info = $server->getInfo();
$maxWireVersion = isset($info['maxWireVersion']) ? (integer) $info['maxWireVersion'] : 0;
$minWireVersion = isset($info['minWireVersion']) ? (integer) $info['minWireVersion'] : 0;
return ($minWireVersion <= $feature && $maxWireVersion >= $feature);
}
......@@ -62,6 +62,10 @@ class PedantryTest extends \PHPUnit_Framework_TestCase
$files = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir)), '/\.php$/i');
foreach ($files as $file) {
if ($file->getFilename() === 'functions.php') {
continue;
}
$classNames[][] = 'MongoDB\\' . str_replace(DIRECTORY_SEPARATOR, '\\', substr($file->getRealPath(), strlen($srcDir) + 1, -4));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment