cvs: peardoc /en/package/php/php-compatinfo basic.xml

From: Date: Sat, 05 Jul 2008 14:10:56 +0000
Subject: cvs: peardoc /en/package/php/php-compatinfo basic.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-10942@lists.php.net to get a copy of this message
farell Sat Jul 5 14:10:56 2008 UTC Added files: /peardoc/en/package/php/php-compatinfo basic.xml Log: second chapter of tutorial (basic detection) -inital commit http://cvs.php.net/viewvc.cgi/peardoc/en/package/php/php-compatinfo/basic.xml?view=markup&rev=1.1 Index: peardoc/en/package/php/php-compatinfo/basic.xml +++ peardoc/en/package/php/php-compatinfo/basic.xml <!-- $Revision: 1.1 $ --> <refentry id="package.php.php-compatinfo.basic"> <refnamediv> <refname>Basic detection</refname> <refpurpose>parse data source with default options</refpurpose> </refnamediv> <refsect1 id="package.php.php-compatinfo.basic.file"> <title>Detection of a single file</title> <para> In most case, the basic detection is enough. But sometimes, we will need to adjust accuracy of parser to give the best result. It is possible with <parameter>$option</parameter>, the second parameter of each parser method. See parser options list for details. </para> <para> Suppose we have to detect which PHP version we need to run this script named &quot;math.php&quot; </para> <para> <programlisting role="php"> <![CDATA[ <?php $nb = bcsub(1.234, 5, 4); if (preg_match('/^-/', $nb)) { echo 'minus'; } ?> ]]> </programlisting> </para> <para> We will use this very simple detection script. <programlisting role="php"> <![CDATA[ <?php require_once 'PHP/CompatInfo.php'; $source = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'math.php'; $info = new PHP_CompatInfo(); $info->parseFile($source); // you may also use unified method: $info->parseData($source); ?> ]]> </programlisting> </para> <para> Default output used the Array renderer (we will talk about it and other renderers later; don't be afraid if you don't know what is it yet). Here are the raw results we got on standard output : <screen> array ( 'ignored_files' => array ( ), 'ignored_functions' => array ( ), 'ignored_extensions' => array ( ), 'ignored_constants' => array ( ), 'max_version' => '', 'version' => '4.0.0', 'extensions' => array ( 0 => 'bcmath', 1 => 'pcre', ), 'constants' => array ( ), 'tokens' => array ( ), 'cond_code' => array ( 0 => 0, ), ) </screen> It means that we need at least PHP 4.0.0 to run the &quot;math.php&quot; script. with two PHP extensions <simplelist type='inline'> <member>bcmath</member> <member>pcre</member> </simplelist> loaded. </para> </refsect1> <refsect1 id="package.php.php-compatinfo.basic.dir"> <title>Detection of a directory</title> <para> Rather than parsing file after file of an application, you my give the root of your application path as the main directory to parse. Default is recursive parsing: that mean each directory children will be also parsed. And only files with extension <simplelist type='inline'> <member>php</member> <member>php4</member> <member>inc</member> <member>phtml</member> </simplelist> will be proceed. </para> <para> Suppose we have to detect which PHP version we need to run the PEAR::File_Find package release 1.3.0 </para> <para> First begin to download the archive from <ulink url="http://pear.php.net/package/File_Find/download/1.3.0"> http://pear.php.net/package/File_Find/download/1.3.0 </ulink> and extract the full contents to a temporary directory (in our example its '/tmp') </para> <para> We will use this very simple detection script. <programlisting role="php"> <![CDATA[ <?php require_once 'PHP/CompatInfo.php'; $source = '/tmp/File_Find-1.3.0'; $info = new PHP_CompatInfo(); $info->parseDir($source); // you may also use unified method: $info->parseData($source); ?> ]]> </programlisting> </para> <para> Results displayed: <screen> array ( 'ignored_files' => array ( 0 => '/tmp/File_Find-1.3.0/package.xml', 1 => '/tmp/File_Find-1.3.0/tests/01glob.phpt', 2 => '/tmp/File_Find-1.3.0/tests/02maptree.phpt', 3 => '/tmp/File_Find-1.3.0/tests/03maptreemultiple.phpt', 4 => '/tmp/File_Find-1.3.0/tests/04search.phpt', 5 => '/tmp/File_Find-1.3.0/tests/05search_inside.phpt', 6 => '/tmp/File_Find-1.3.0/tests/06match_shell.phpt', 7 => '/tmp/File_Find-1.3.0/tests/bug2773.phpt', ), 'ignored_functions' => array ( ), 'ignored_extensions' => array ( ), 'ignored_constants' => array ( ), 'max_version' => '', 'version' => '4.3.0', 'extensions' => array ( 0 => 'pcre', ), 'constants' => array ( 0 => '__FILE__', ), 'tokens' => array ( ), 'cond_code' => array ( 0 => 4, ), '/tmp/File_Find-1.3.0/Find.php' => array ( 'ignored_functions' => array ( ), 'ignored_extensions' => array ( ), 'ignored_constants' => array ( ), 'max_version' => '', 'version' => '4.3.0', 'extensions' => array ( 0 => 'pcre', ), 'constants' => array ( ), 'tokens' => array ( ), 'cond_code' => array ( 0 => 4, ), ), '/tmp/File_Find-1.3.0/tests/setup.php' => array ( 'ignored_functions' => array ( ), 'ignored_extensions' => array ( ), 'ignored_constants' => array ( ), 'max_version' => '', 'version' => '4.0.0', 'extensions' => array ( ), 'constants' => array ( 0 => '__FILE__', ), 'tokens' => array ( ), 'cond_code' => array ( 0 => 0, ), ), ) </screen> means that package PEAR::File_Find 1.3.0 need at least PHP 4.3.0 with extension pcre. </para> <para> <caution> <para> <literal>cond_cond</literal> offset 0 is set to 4. That means there are conditional code (constant condition) implemented in source code (with php <ulink url="&url.php;defined">defined</ulink> function). </para> <para> If you have a look on source code, you will see that all conditions referred to private package constant <literal>FILE_FIND_DEBUG</literal> </para> </caution> </para> <para> <tip> <para> You may avoid to read the source code to know the constant name, if you specify the <literal>debug</literal> option when parsing the directory. </para> <para> <programlisting role="php"> <![CDATA[ <?php require_once 'PHP/CompatInfo.php'; $source = '/tmp/File_Find-1.3.0'; $info = new PHP_CompatInfo(); $info->parseDir($source, array('debug' => true)); ?> ]]> </programlisting> </para> </tip> And you will see in displayed results, something like : <screen> 'cond_code' => array ( 0 => 4, 1 => array ( 0 => array ( ), 1 => array ( ), 2 => array ( 0 => 'FILE_FIND_DEBUG', ), ), </screen> <literal>cond_code</literal> offset 1 is an array available only when debug mode is set to true. In this array : <itemizedlist> <listitem> <para> <emphasis role="bold">offset 0</emphasis>, give name of function conditions </para> </listitem> <listitem> <para> <emphasis role="bold">offset 1</emphasis>, give name of extension conditions </para> </listitem> <listitem> <para> <emphasis role="bold">offset 2</emphasis>, give name of constant conditions </para> </listitem> </itemizedlist> </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 sgml-parent-document:nil sgml-default-dtd-file:"../../../../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 -->

« previous php.pear.doc (#10942) next »