-
Notifications
You must be signed in to change notification settings - Fork 820
PackedArray::fromJSON() and toJSON methods #3806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
1d4133c
6c3e381
3e305b8
cc5d523
cfb5417
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"> | ||||||
<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"> | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
&reftitle.errors; | ||||||
<simplelist> | ||||||
&mongodb.throws.argumentparsing; | ||||||
<member>Throws <classname>MongoDB\Driver\Exception\UnexpectedValueException</classname> if <parameter>json</parameter> is not a valid array.</member> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible mistake?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was adapted from the It's not just a matter of the JSON being valid. |
||||||
</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 | ||||||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 | ||||||
--> |
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"> | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<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"> | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&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: | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
--> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- $Revision$ --> | ||
|
||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<refentry xml:id="mongodb-bson-packedarray.torelaxedextendedjson" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<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"> | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&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> | ||
|
||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<!-- Keep this comment at the end of the file | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
--> |
There was a problem hiding this comment.
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 :)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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 :/