mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-26 01:42:09 +01:00
209 lines
5.3 KiB
XML
Executable File
209 lines
5.3 KiB
XML
Executable File
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 82c84a325ea8d03f45669988e4f6ed53221ebd8f Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<refentry xml:id="function.token-get-all" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>token_get_all</refname>
|
|
<refpurpose>Scinde un code source en éléments de base</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>token_get_all</methodname>
|
|
<methodparam><type>string</type><parameter>code</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>token_get_all</function> analyse la chaîne donnée
|
|
<parameter>source</parameter> en utilisant l'analyseur lexical du moteur Zend.
|
|
</para>
|
|
<para>
|
|
Pour une liste des tokens, voir <xref linkend="tokens"/>, ou utilisez la fonction
|
|
<function>token_name</function> pour traduire une valeur token dans une
|
|
représentation sous forme de chaîne de caractères.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>code</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Le source PHP à analyser.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Drapeaux valides :
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>TOKEN_PARSE</constant> - Reconnait la possibilité d'utiliser
|
|
les mots réservés dans des contextes spécifiques.
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Un tableau contenant la liste des descriptions des éléments. Chaque élément
|
|
du tableau peut être un caractère unique (i.e.: <literal>;</literal>,
|
|
<literal>.</literal>, <literal>></literal>, <literal>!</literal>, etc.),
|
|
ou un tableau contenant un identifiant de token dans l'élément 0,
|
|
la représentation textuelle originale de ce token dans l'élément 1,
|
|
et le numéro de la ligne dans l'élément 2.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>token_get_all</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$tokens = token_get_all('<?php echo; ?>');
|
|
|
|
foreach ($tokens as $token) {
|
|
if (is_array($token)) {
|
|
echo "Line {$token[2]}: ", token_name($token[0]), " ('{$token[1]}')", PHP_EOL;
|
|
}
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Line 1: T_OPEN_TAG ('<?php ')
|
|
Line 1: T_ECHO ('echo')
|
|
Line 1: T_WHITESPACE (' ')
|
|
Line 1: T_CLOSE_TAG ('?>')
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Exemple d'utilisation incorrecte de la fonction <function>token_get_all</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$tokens = token_get_all('/* commentaire */');
|
|
|
|
foreach ($tokens as $token) {
|
|
if (is_array($token)) {
|
|
echo "Ligne {$token[2]} : ", token_name($token[0]), " ('{$token[1]}')", PHP_EOL;
|
|
}
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Ligne 1 : T_INLINE_HTML ('/* comment */')
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
Notez que dans le précédent exemple la chaîne est analsée comme une
|
|
<constant>T_INLINE_HTML</constant> plutôt que <constant>T_COMMENT</constant>,
|
|
ce qui aurait pu être attendu. Ceci est dû au fait qu'aucune balise ouvrante n'a été
|
|
utilisée dans le code fourni. Cela correspond à mettre une commentaire en dehors
|
|
des balises PHP dans un fichier classique.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>
|
|
<function>token_get_all</function> dans une classe en utilisant un mot réservé
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$source = <<<'code'
|
|
<?php
|
|
|
|
class A
|
|
{
|
|
const PUBLIC = 1;
|
|
}
|
|
code;
|
|
|
|
$tokens = token_get_all($source, TOKEN_PARSE);
|
|
|
|
foreach ($tokens as $token) {
|
|
if (is_array($token)) {
|
|
echo token_name($token[0]) , PHP_EOL;
|
|
}
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
T_OPEN_TAG
|
|
T_WHITESPACE
|
|
T_CLASS
|
|
T_WHITESPACE
|
|
T_STRING
|
|
T_CONST
|
|
T_WHITESPACE
|
|
T_STRING
|
|
T_LNUMBER
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
Sans le drapeau <constant>TOKEN_PARSE</constant>, le pénultième jeton
|
|
(<constant>T_STRING</constant>) aurait du être
|
|
<constant>T_PUBLIC</constant>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>PhpToken::tokenize</function></member>
|
|
<member><function>token_name</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</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
|
|
-->
|