Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $documents = [
[ 'string' => 'foo' ],
[ 'int32' => 123 ],
[ 'int64' => 4294967295 ],
[ 'double' => 1.0, ],
[ 'double' => 1.0 ],
[ 'nan' => NAN ],
[ 'pos_inf' => INF ],
[ 'neg_inf' => -INF ],
Expand Down
2 changes: 1 addition & 1 deletion reference/mongodb/bson/document/torelaxedextendedjson.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $documents = [
[ 'string' => 'foo' ],
[ 'int32' => 123 ],
[ 'int64' => 4294967295 ],
[ 'double' => 1.0, ],
[ 'double' => 1.0 ],
[ 'nan' => NAN ],
[ 'pos_inf' => INF ],
[ 'neg_inf' => -INF ],
Expand Down
116 changes: 116 additions & 0 deletions reference/mongodb/bson/packedarray/fromjson.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="mongodb-bson-packedarray.fromjson" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Please don't put a blank line in new files :)

Suggested change
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongodb-bson-packedarray.fromjson" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongodb-bson-packedarray.fromjson" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">

Copy link
Member Author

@jmikola jmikola Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted! I wasn't aware of that convention. Out of curiosity, is it mentioned anywhere on http://doc.php.net/tutorial/?

@Girgias: Also, I noticed you didn't suggest removing blank lines between <refsect1> blocks. Are those still permitted for readability?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah between <refsect1> is OK. I don't think it is mentioned in the tutorial as that hasn't been updated in a while :/

<refnamediv>
<refname>MongoDB\BSON\PackedArray::fromJSON</refname>
<refpurpose>Construct a new BSON array instance from a JSON string</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>final</modifier> <modifier>static</modifier> <modifier>public</modifier> <type>MongoDB\BSON\PackedArray</type><methodname>MongoDB\BSON\PackedArray::fromJSON</methodname>
<methodparam><type>string</type><parameter>json</parameter></methodparam>
</methodsynopsis>
<para>
Converts an
<link xlink:href="&url.mongodb.docs.extendedjson;">extended JSON</link>
string to its BSON representation.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>json</parameter> (<type>string</type>)</term>
<listitem>
<para>
JSON value to be converted.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<simplelist>
&mongodb.throws.argumentparsing;
<member>Throws <classname>MongoDB\Driver\Exception\UnexpectedValueException</classname> if <parameter>json</parameter> is not a valid array.</member>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible mistake?

Suggested change
<member>Throws <classname>MongoDB\Driver\Exception\UnexpectedValueException</classname> if <parameter>json</parameter> is not a valid array.</member>
<member>Throws <classname>MongoDB\Driver\Exception\UnexpectedValueException</classname> if <parameter>json</parameter> is invalid JSON.</member>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was adapted from the Document::fromJSON() method, which says "is not a valid document". I'll change both to say "if $json cannot be parsed as a document" (or "an array").

It's not just a matter of the JSON being valid. PackedArray::fromJSON() requires an actual array (i.e. outermost brackets) or an object with sequential numeric keys. There's some more context in mongodb/mongo-php-driver#1703.

</simplelist>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title><methodname>MongoDB\BSON\PackedArray::fromJSON</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php

$json = '[ "foo", { "$numberInt" : "123" }, { "$numberLong" : "4294967295" }, { "$oid" : "56315a7c6118fd1b920270b1" } ]';
$packedArray = MongoDB\BSON\PackedArray::fromJSON($json);
var_dump($packedArray);

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(MongoDB\BSON\PackedArray)#1 (2) {
["data"]=>
string(68) "MQAAAAIwAAQAAABmb28AEDEAewAAABIyAP////8AAAAABzMAVjFafGEY/RuSAnCxAA=="
["value"]=>
array(4) {
[0]=>
string(3) "foo"
[1]=>
int(123)
[2]=>
int(4294967295)
[3]=>
object(MongoDB\BSON\ObjectId)#2 (1) {
["oid"]=>
string(24) "56315a7c6118fd1b920270b1"
}
}
}
]]>
</screen>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>MongoDB\BSON\PackedArray::fromPHP</methodname></member>
<member><link xlink:href="&url.mongodb.docs.extendedjson;">MongoDB Extended JSON</link></member>
<member><link xlink:href="&url.mongodb.docs.bson;">BSON Types</link></member>
</simplelist>
</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
-->
93 changes: 93 additions & 0 deletions reference/mongodb/bson/packedarray/tocanonicalextendedjson.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="mongodb-bson-packedarray.tocanonicalextendedjson" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoDB\BSON\PackedArray::toCanonicalExtendedJSON</refname>
<refpurpose>Returns the Canonical Extended JSON representation of the BSON array</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <type>string</type><methodname>MongoDB\BSON\PackedArray::toCanonicalExtendedJSON</methodname>
<void/>
</methodsynopsis>
<para>
Converts the BSON array to its
<link xlink:href="&url.mongodb.specs.extendedjson;#canonical-extended-json-example">Canonical Extended JSON</link>
representation. The canonical format prefers type fidelity at the expense of
concise output and is most suited for producing output that can be converted
back to BSON without any loss of type information (e.g. numeric types will
remain differentiated).
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title><methodname>MongoDB\BSON\PackedArray::toCanonicalExtendedJSON</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php

$array = [
'foo',
123,
4294967295,
new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1'),
];

$packedArray = MongoDB\BSON\PackedArray::fromPHP($array);
echo $packedArray->toCanonicalExtendedJSON(), "\n";

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
[ "foo", { "$numberInt" : "123" }, { "$numberLong" : "4294967295" }, { "$oid" : "56315a7c6118fd1b920270b1" } ]
]]>
</screen>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>MongoDB\BSON\PackedArray::fromJSON</methodname></member>
<member><methodname>MongoDB\BSON\PackedArray::toRelaxedExtendedJSON</methodname></member>
<member><function>MongoDB\BSON\toCanonicalExtendedJSON</function></member>
<member><link xlink:href="&url.mongodb.specs.extendedjson;">Extended JSON Specification</link></member>
<member><link xlink:href="&url.mongodb.docs.bson;">BSON Types</link></member>
</simplelist>
</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
-->
92 changes: 92 additions & 0 deletions reference/mongodb/bson/packedarray/torelaxedextendedjson.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="mongodb-bson-packedarray.torelaxedextendedjson" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoDB\BSON\PackedArray::toRelaxedExtendedJSON</refname>
<refpurpose>Returns the Relaxed Extended JSON representation of the BSON array</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <type>string</type><methodname>MongoDB\BSON\PackedArray::toRelaxedExtendedJSON</methodname>
<void/>
</methodsynopsis>
<para>
Converts the BSON array to its
<link xlink:href="&url.mongodb.specs.extendedjson;#relaxed-extended-json-example">Relaxed Extended JSON</link>
representation. The relaxed format prefers use of JSON type primitives at the
expense of type fidelity and is most suited for producing output that can be
easily consumed by web APIs and humans.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title><methodname>MongoDB\BSON\PackedArray::toRelaxedExtendedJSON</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php

$array = [
'foo',
123,
4294967295,
new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1'),
];

$packedArray = MongoDB\BSON\PackedArray::fromPHP($array);
echo $packedArray->toRelaxedExtendedJSON(), "\n";

?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
[ "foo", 123, 4294967295, { "$oid" : "56315a7c6118fd1b920270b1" } ]
]]>
</screen>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>MongoDB\BSON\PackedArray::fromJSON</methodname></member>
<member><methodname>MongoDB\BSON\PackedArray::toCanonicalExtendedJSON</methodname></member>
<member><function>MongoDB\BSON\toRelaxedExtendedJSON</function></member>
<member><link xlink:href="&url.mongodb.specs.extendedjson;">Extended JSON Specification</link></member>
<member><link xlink:href="&url.mongodb.docs.bson;">BSON Types</link></member>
</simplelist>
</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
-->
3 changes: 3 additions & 0 deletions reference/mongodb/versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
<function name='mongodb\bson\packedarray' from='mongodb &gt;=1.16.0'/>
<function name='mongodb\bson\packedarray::__construct' from='mongodb &gt;=1.16.0'/>
<function name='mongodb\bson\packedarray::__tostring' from='mongodb &gt;=1.16.0'/>
<function name='mongodb\bson\packedarray::fromjson' from='mongodb &gt;=1.20.0'/>
<function name='mongodb\bson\packedarray::fromphp' from='mongodb &gt;=1.16.0'/>
<function name='mongodb\bson\packedarray::get' from='mongodb &gt;=1.16.0'/>
<function name='mongodb\bson\packedarray::getiterator' from='mongodb &gt;=1.16.0'/>
Expand All @@ -465,7 +466,9 @@
<function name='mongodb\bson\packedarray::offsetset' from='mongodb &gt;=1.17.0'/>
<function name='mongodb\bson\packedarray::offsetunset' from='mongodb &gt;=1.17.0'/>
<function name='mongodb\bson\packedarray::serialize' from='mongodb &gt;=1.16.0'/>
<function name='mongodb\bson\packedarray::tocanonicalextendedjson' from='mongodb &gt;=1.20.0'/>
<function name='mongodb\bson\packedarray::tophp' from='mongodb &gt;=1.16.0'/>
<function name='mongodb\bson\packedarray::torelaxedextendedjson' from='mongodb &gt;=1.20.0'/>
<function name='mongodb\bson\packedarray::unserialize' from='mongodb &gt;=1.16.0'/>

<function name='mongodb\bson\regex' from='mongodb &gt;=1.0.0'/>
Expand Down