public static serverSupportsFeature ( MongoDB\Driver\Server $server, integer $feature ) : boolean | ||
$server | MongoDB\Driver\Server | Server to check |
$feature | integer | Feature constant (i.e. wire protocol version) |
return | boolean |
public static function serverSupportsFeature(Server $server, $feature)
{
$info = $server->getInfo();
$maxWireVersion = isset($info['maxWireVersion']) ? (int) $info['maxWireVersion'] : 0;
$minWireVersion = isset($info['minWireVersion']) ? (int) $info['minWireVersion'] : 0;
return $minWireVersion <= $feature && $maxWireVersion >= $feature;
}
/** * Execute the operation. * * For servers < 2.6, this will actually perform an insert operation on the * database's "system.indexes" collection. * * @see Executable::execute() * * @param Server $server * * @return string[] The names of the created indexes */ public function execute(Server $server) { if (Functions::serverSupportsFeature($server, self::$wireVersionForCommand)) { $this->executeCommand($server); } else { $this->executeLegacy($server); } return array_map(function (IndexInput $index) { return (string) $index; }, $this->indexes); }