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

<refentry xml:id="mongocode.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>MongoCode::__construct</refname>
  <refpurpose>Creates a new code object</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <modifier>public</modifier> <methodname>MongoCode::__construct</methodname>
   <methodparam><type>string</type><parameter>code</parameter></methodparam>
   <methodparam choice="opt"><type>array</type><parameter>scope</parameter><initializer>array()</initializer></methodparam>
  </methodsynopsis>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term>
      <parameter>code</parameter>
     </term>
     <listitem>
      <para>
       A string of code.
      </para>
     </listitem>
    </varlistentry>   
    <varlistentry>
     <term>
      <parameter>scope</parameter>
     </term>
     <listitem>
      <para>
       The scope to use for the code.
      </para>
     </listitem>
    </varlistentry>   
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns a new code object.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
   <title><methodname>MongoCode::__construct</methodname> example</title>
   <programlisting role="php">
<![CDATA[
<?php

$code = new MongoCode('function() { '.
    'for(i=0;i<10;i++) {'.
        'db.foo.update({z : i}, {z : x});'.
    '}'.
    'return x-1;'.
 '}', array("x" => 4));
var_dump($code);

?>
]]>
   </programlisting>
   &example.outputs.similar;
   <screen>
<![CDATA[
object(MongoCode)#1 (2) {
  ["scope"]=>
  array(1) {
    ["x"]=>
    int(4)
  }
  ["code"]=>
  string(80) "function() { for(i=0;i<10;i++) { db.foo.update({z : i}, {z : x}); } return x-1; }"
}
]]>
   </screen>
  </example>


  <example>
   <title>Using <classname>MongoCode</classname> with $where</title>
   <para>
    This example queries a collection for elements where the 'x' fields is less than $y.  Notice that
    PHP objects can be passed into the JavaScript scope and that the JavaScript function returns a boolean.
   </para>
   <programlisting role="php">
<![CDATA[
<?php

$cursor = $collection->find(array('$where' => new MongoCode('function() { return this.x < y; }', array('y'=>$y))));

?>
]]>
   </programlisting>
  </example>
 </refsect1>
</refentry>

<!-- 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
-->