<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<phpdoc:classref xml:id="class.mongodb-driver-serverapi" xmlns:phpdoc="http://php.net/ns/phpdoc" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">

 <title>The MongoDB\Driver\ServerApi class</title>
 <titleabbrev>MongoDB\Driver\ServerApi</titleabbrev>

 <partintro>

<!-- {{{ MongoDB\Driver\ServerApi intro -->
  <section xml:id="mongodb-driver-serverapi.intro">
   &reftitle.intro;
   <para>

   </para>
  </section>
<!-- }}} -->

  <section xml:id="mongodb-driver-serverapi.synopsis">
   &reftitle.classsynopsis;

<!-- {{{ Synopsis -->
   <classsynopsis>
    <ooclass><classname>MongoDB\Driver\ServerApi</classname></ooclass>

<!-- {{{ Class synopsis -->
    <classsynopsisinfo>
     <modifier>final</modifier>
     <ooclass>
      <classname>MongoDB\Driver\ServerApi</classname>
     </ooclass>
     <oointerface>
      <interfacename>MongoDB\BSON\Serializable</interfacename>
     </oointerface>

     <oointerface>
      <interfacename>Serializable</interfacename>
     </oointerface>
    </classsynopsisinfo>
<!-- }}} -->
    <classsynopsisinfo role="comment">&Constants;</classsynopsisinfo>
    <fieldsynopsis>
     <modifier>const</modifier>
     <type>string</type>
     <varname linkend="mongodb-driver-serverapi.constants.v1">MongoDB\Driver\ServerAPI::V1</varname>
     <initializer>"1"</initializer>
    </fieldsynopsis>

    <classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
    <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.mongodb-driver-serverapi')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])" />
   </classsynopsis>
<!-- }}} -->

  </section>

<!-- {{{ MongoDB\Driver\ServerApi constants -->
  <section xml:id="mongodb-driver-serverapi.constants">
   &reftitle.constants;
   <variablelist>

    <varlistentry xml:id="mongodb-driver-serverapi.constants.v1">
     <term><constant>MongoDB\Driver\ServerApi::V1</constant></term>
     <listitem>
      <para>Server API version 1.</para>
     </listitem>
    </varlistentry>

   </variablelist>
  </section>
<!-- }}} -->

  <section xml:id="mongodb-driver-serverapi.examples">
   &reftitle.examples;

   <example>
    <title>Declare an API version on a manager</title>
    <programlisting role="php">
<![CDATA[
<?php

use MongoDB\Driver\Manager;
use MongoDB\Driver\ServerApi;

$v1 = new ServerApi(ServerApi::v1);
$manager = new Manager('mongodb://localhost:27017', [], ['serverApi' => $v1]);

$command = new MongoDB\Driver\Command(['buildInfo' => 1]);

try {
    $cursor = $manager->executeCommand('admin', $command);
} catch(MongoDB\Driver\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

/* The buildInfo command returns a single result document, so we need to access
 * the first result in the cursor. */
$buildInfo = $cursor->toArray()[0];

echo $buildInfo->version, "\n";

?>
]]>
    </programlisting>

    &example.outputs;
    <screen>
<![CDATA[
4.9.0-alpha7-49-gb968ca0
]]>
    </screen>
   </example>

   <example>
    <title>Declare a strict API version on a manager</title>
    <para>
     The following example sets the <parameter>strict</parameter> flag, which
     tells the server to reject any command that is not part of the declared API
     version. This results in an error when running the buildInfo command.
    </para>
    <programlisting role="php">
<![CDATA[
<?php

use MongoDB\Driver\Manager;
use MongoDB\Driver\ServerApi;

$v1 = new ServerApi(ServerApi::v1, true);
$manager = new Manager('mongodb://localhost:27017', [], ['serverApi' => $v1]);

$command = new MongoDB\Driver\Command(['buildInfo' => 1]);

try {
    $cursor = $manager->executeCommand('admin', $command);
} catch(MongoDB\Driver\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

/* The buildInfo command returns a single result document, so we need to access
 * the first result in the cursor. */
$buildInfo = $cursor->toArray()[0];

echo $buildInfo->version, "\n";

?>
]]>
    </programlisting>

    &example.outputs;
    <screen>
<![CDATA[
Provided apiStrict:true, but the command buildInfo is not in API Version 1
]]>
    </screen>
   </example>
  </section>

 </partintro>

 &reference.mongodb.mongodb.driver.entities.serverapi;

</phpdoc:classref>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
