Updated translation.

git-svn-id: https://svn.php.net/repository/phpdoc/ru/trunk@327205 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Max Chaban
2012-08-21 10:58:54 +00:00
parent 0cb44da425
commit 3ccecde3cb
10 changed files with 215 additions and 84 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 8b6d169424ff189bb563ef4c3f35f8adff3f42c5 Maintainer: mch Status: ready -->
<!-- EN-Revision: 589ebcb6d54e699c3eed82b1f72c9d70a83dcfcd Maintainer: mch Status: ready -->
<!-- Reviewed: yes -->
<refentry xml:id="jsonserializable.jsonserialize" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>JsonSerializable::jsonSerialize</refname>
<refpurpose>Уточняет данные, которые должны быть сериализованы в JSON</refpurpose>
<refpurpose>Задает данные, которые должны быть сериализованы в JSON</refpurpose>
</refnamediv>
<refsect1 role="description">
@ -16,11 +16,9 @@
<void />
</methodsynopsis>
<para>
Сериализует объект в значение, которое в свою очередь может быть сериализовано
функицей <function>json_encode</function>.
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">
@ -31,11 +29,141 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает данные, которые должны быть сериализованы <function>json_encode</function>.
Возвращает данные, которые могут быть сериализованы <function>json_encode</function>,
которые являются значением любого типа, отличным от типа <type>resource</type>.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>
Пример использования <methodname>JsonSerializable::jsonSerialize</methodname>,
возвращающий массив (<type>array</type>)
</title>
<programlisting role="php">
<![CDATA[
<?php
class ArrayValue implements JsonSerializable {
public function __construct(array $array) {
$this->array = $array;
}
public function jsonSerialize() {
return $this->array;
}
}
$array = [1, 2, 3];
echo json_encode(new ArrayValue($array), JSON_PRETTY_PRINT);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
[
1,
2,
3
]
]]>
</screen>
</example>
<example>
<title>
Пример использования <methodname>JsonSerializable::jsonSerialize</methodname>,
возвращающий ассоциативный массив (<type>array</type>)
</title>
<programlisting role="php">
<![CDATA[
<?php
class ArrayValue implements JsonSerializable {
public function __construct(array $array) {
$this->array = $array;
}
public function jsonSerialize() {
return $this->array;
}
}
$array = ['foo' => 'bar', 'quux' => 'baz'];
echo json_encode(new ArrayValue($array), JSON_PRETTY_PRINT);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
{
"foo": "bar",
"quux": "baz"
}
]]>
</screen>
</example>
<example>
<title>
Пример использования <methodname>JsonSerializable::jsonSerialize</methodname>,
возвращающий целое значение (<type>integer</type>)
</title>
<programlisting role="php">
<![CDATA[
<?php
class IntegerValue implements JsonSerializable {
public function __construct($number) {
$this->number = (integer) $number;
}
public function jsonSerialize() {
return $this->number;
}
}
echo json_encode(new IntegerValue(1), JSON_PRETTY_PRINT);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
1
]]>
</screen>
</example>
<example>
<title>
Пример использования <methodname>JsonSerializable::jsonSerialize</methodname>,
возвращающий строку (<type>string</type>)
</title>
<programlisting role="php">
<![CDATA[
<?php
class StringValue implements JsonSerializable {
public function __construct($string) {
$this->string = (string) $string;
}
public function jsonSerialize() {
return $this->string;
}
}
echo json_encode(new StringValue('Hello!'), JSON_PRETTY_PRINT);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
"Hello!"
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file