php-doc-en/reference/mongodb/mongodb/driver/command.xml
2018-04-25 08:36:37 +00:00

196 lines
4.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<phpdoc:classref xml:id="class.mongodb-driver-command" 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\Command class</title>
<titleabbrev>MongoDB\Driver\Command</titleabbrev>
<partintro>
<!-- {{{ MongoDB\Driver\Command intro -->
<section xml:id="mongodb-driver-command.intro">
&reftitle.intro;
<para>
The <classname>MongoDB\Driver\Command</classname> class is a value object
that represents a database command.
</para>
<para>
To provide <quote>Command Helpers</quote> the <classname>MongoDB\Driver\Command</classname> object should be composed.
</para>
</section>
<!-- }}} -->
<section xml:id="mongodb-driver-command.synopsis">
&reftitle.classsynopsis;
<!-- {{{ Synopsis -->
<classsynopsis>
<ooclass><classname>MongoDB\Driver\Command</classname></ooclass>
<!-- {{{ Class synopsis -->
<classsynopsisinfo>
<modifier>final</modifier>
<ooclass>
<classname>MongoDB\Driver\Command</classname>
</ooclass>
</classsynopsisinfo>
<!-- }}} -->
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.mongodb-driver-command')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])" />
</classsynopsis>
<!-- }}} -->
</section>
<section xml:id="mongodb-driver-command.examples">
&reftitle.examples;
<example>
<title>Composing <classname>MongoDB\Driver\Command</classname> to provide a helper to create collections</title>
<programlisting role="php">
<![CDATA[
<?php
class CreateCollection {
protected $cmd = array();
function __construct($collectionName) {
$this->cmd["create"] = (string)$collectionName;
}
function setCappedCollection($maxBytes, $maxDocuments = false) {
$this->cmd["capped"] = true;
$this->cmd["size"] = (int)$maxBytes;
if ($maxDocuments) {
$this->cmd["max"] = (int)$maxDocuments;
}
}
function usePowerOf2Sizes($bool) {
if ($bool) {
$this->cmd["flags"] = 1;
} else {
$this->cmd["flags"] = 0;
}
}
function setFlags($flags) {
$this->cmd["flags"] = (int)$flags;
}
function getCommand() {
return new MongoDB\Driver\Command($this->cmd);
}
function getCollectionName() {
return $this->cmd["create"];
}
}
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$createCollection = new CreateCollection("cappedCollection");
$createCollection->setCappedCollection(64 * 1024);
try {
$command = $createCollection->getCommand();
$cursor = $manager->executeCommand("databaseName", $command);
$response = $cursor->toArray()[0];
var_dump($response);
$collstats = ["collstats" => $createCollection->getCollectionName()];
$cursor = $manager->executeCommand("databaseName", new MongoDB\Driver\Command($collstats));
$response = $cursor->toArray()[0];
var_dump($response);
} catch(MongoDB\Driver\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
object(MongoDB\Driver\Command)#3 (1) {
["command"]=>
array(3) {
["create"]=>
string(16) "cappedCollection"
["capped"]=>
bool(true)
["size"]=>
int(65536)
}
}
array(1) {
["ok"]=>
float(1)
}
array(16) {
["ns"]=>
string(29) "databaseName.cappedCollection"
["count"]=>
int(0)
["size"]=>
int(0)
["numExtents"]=>
int(1)
["storageSize"]=>
int(65536)
["nindexes"]=>
int(1)
["lastExtentSize"]=>
float(65536)
["paddingFactor"]=>
float(1)
["paddingFactorNote"]=>
string(101) "paddingFactor is unused and unmaintained in 2.8. It remains hard coded to 1.0 for compatibility only."
["userFlags"]=>
int(0)
["capped"]=>
bool(true)
["max"]=>
int(9223372036854775807)
["maxSize"]=>
int(65536)
["totalIndexSize"]=>
int(8176)
["indexSizes"]=>
object(stdClass)#4 (1) {
["_id_"]=>
int(8176)
}
["ok"]=>
float(1)
}
]]>
</screen>
</section>
</partintro>
&reference.mongodb.mongodb.driver.entities.command;
</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
-->