cvs: peardoc /en/package/php/php-compatinfo advanced.xml
| From: | Laurent Laville | Date: | Sat, 05 Jul 2008 17:02:13 +0000 |
| Subject: | cvs: peardoc /en/package/php/php-compatinfo advanced.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-10948@lists.php.net to get a copy of this message | ||
farell Sat Jul 5 17:02:13 2008 UTC
Modified files:
/peardoc/en/package/php/php-compatinfo advanced.xml
Log:
advanced detection of a directory ... to be continue with chapter "conditional code
analysis"
http://cvs.php.net/viewvc.cgi/peardoc/en/package/php/php-compatinfo/advanced.xml?r1=1.2&r2=1.3&diff_format=u
Index: peardoc/en/package/php/php-compatinfo/advanced.xml
diff -u peardoc/en/package/php/php-compatinfo/advanced.xml:1.2
peardoc/en/package/php/php-compatinfo/advanced.xml:1.3
--- peardoc/en/package/php/php-compatinfo/advanced.xml:1.2 Sat Jul 5 16:15:10 2008
+++ peardoc/en/package/php/php-compatinfo/advanced.xml Sat Jul 5 17:02:13 2008
@@ -1,4 +1,4 @@
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
<refentry id="package.php.php-compatinfo.advanced">
<refnamediv>
@@ -136,6 +136,206 @@
</para>
</refsect1>
+ <refsect1 id="package.php.php-compatinfo.advanced.dir">
+ <title>Detection of a directory</title>
+ <simpara>
+ Parsing a full directory, recursively or not, is no more difficult than
+ detect PHP version of a single file.
+ </simpara>
+ <simpara>
+ This new example is based on auto detection of HTML_CSS 1.5.1 distribution.
+ As we will see, basic detection is not accurate as it should be. But with an option
+ we can get the real result (PHP minimum = 4.3.0).
+ </simpara>
+ <para>
+ First begin to download the archive from
+ <ulink url="http://pear.php.net/package/HTML_CSS/download/1.5.1">
+ http://pear.php.net/package/HTML_CSS/download/1.5.1
+ </ulink>
+ and extract the full contents to a temporary directory (in our example its '/tmp')
+ </para>
+ <para>
+ We will focus on two important files:
+ <filename>CSS.php</filename> and <filename>CSS/Error.php</filename>.
+ So we will indicate to PCI to ignore
+ <filename class='directory'>examples/</filename>, and
+ <filename class='directory'>tests/</filename> directories.
+ </para>
+ <para>
+ Here is the detection script:
+ <programlisting role="php">
+ <![CDATA[
+<?php
+require_once 'PHP/CompatInfo.php';
+
+$source = '/tmp/HTML_CSS-1.5.1';
+$options = array('ignore_dirs' => array('examples', 'tests'));
+
+$info = new PHP_CompatInfo();
+$info->parseDir($source, $options);
+// you may also use unified method: $info->parseData($source, $options);
+?>
+ ]]>
+ </programlisting>
+ </para>
+ <para>
+ And displayed results are :
+ <screen>
+array (
+ 'ignored_files' =>
+ array (
+ 0 => '/tmp/HTML_CSS-1.5.1/ChangeLog',
+ 1 => '/tmp/HTML_CSS-1.5.1/package.xml',
+ 2 => '/tmp/HTML_CSS-1.5.1/tests/AllTests.php',
+ 3 => '/tmp/HTML_CSS-1.5.1/tests/HTML_CSS_TestSuite_Bugs.php',
+ 4 => '/tmp/HTML_CSS-1.5.1/tests/HTML_CSS_TestSuite_Standard.php',
+ 5 => '/tmp/HTML_CSS-1.5.1/tests/stylesheet.css',
+ 6 => '/tmp/HTML_CSS-1.5.1/examples/CSS_Advanced.php',
+ 7 => '/tmp/HTML_CSS-1.5.1/examples/CSS_DisplayOnline.php',
+ 8 => '/tmp/HTML_CSS-1.5.1/examples/css_errorstack_custom.php',
+ 9 => '/tmp/HTML_CSS-1.5.1/examples/css_errorstack_logger.php',
+ 10 => '/tmp/HTML_CSS-1.5.1/examples/css_error_custom.php',
+ 11 => '/tmp/HTML_CSS-1.5.1/examples/css_error_ignore.php',
+ 12 => '/tmp/HTML_CSS-1.5.1/examples/css_error_logger.php',
+ 13 => '/tmp/HTML_CSS-1.5.1/examples/CSS_grepStyles.php',
+ 14 => '/tmp/HTML_CSS-1.5.1/examples/CSS_InHeader.php',
+ 15 => '/tmp/HTML_CSS-1.5.1/examples/CSS_Inline.php',
+ 16 => '/tmp/HTML_CSS-1.5.1/examples/CSS_Logger.php',
+ 17 => '/tmp/HTML_CSS-1.5.1/examples/CSS_parseData.php',
+ 18 => '/tmp/HTML_CSS-1.5.1/examples/CSS_req12194_atrule_api.php',
+ 19 => '/tmp/HTML_CSS-1.5.1/examples/CSS_req12194_atrule_parser.php',
+ 20 => '/tmp/HTML_CSS-1.5.1/examples/CSS_Stylesheet.php',
+ 21 => '/tmp/HTML_CSS-1.5.1/examples/CSS_validate.php',
+ ),
+ 'ignored_functions' =>
+ array (
+ ),
+ 'ignored_extensions' =>
+ array (
+ ),
+ 'ignored_constants' =>
+ array (
+ ),
+ 'max_version' => '',
+ 'version' => '5.0.0',
+ 'extensions' =>
+ array (
+ 0 => 'date',
+ 1 => 'pcre',
+ ),
+ 'constants' =>
+ array (
+ ),
+ 'tokens' =>
+ array (
+ ),
+ 'cond_code' =>
+ array (
+ 0 => 1,
+ ),
+ '/tmp/HTML_CSS-1.5.1/CSS.php' =>
+ array (
+ 'ignored_functions' =>
+ array (
+ ),
+ 'ignored_extensions' =>
+ array (
+ ),
+ 'ignored_constants' =>
+ array (
+ ),
+ 'max_version' => '',
+ 'version' => '5.0.0',
+ 'extensions' =>
+ array (
+ 0 => 'date',
+ 1 => 'pcre',
+ ),
+ 'constants' =>
+ array (
+ ),
+ 'tokens' =>
+ array (
+ ),
+ 'cond_code' =>
+ array (
+ 0 => 1,
+ ),
+ ),
+ '/tmp/HTML_CSS-1.5.1/CSS/Error.php' =>
+ array (
+ 'ignored_functions' =>
+ array (
+ ),
+ 'ignored_extensions' =>
+ array (
+ ),
+ 'ignored_constants' =>
+ array (
+ ),
+ 'max_version' => '',
+ 'version' => '4.3.0',
+ 'extensions' =>
+ array (
+ 0 => 'date',
+ ),
+ 'constants' =>
+ array (
+ ),
+ 'tokens' =>
+ array (
+ ),
+ 'cond_code' =>
+ array (
+ 0 => 0,
+ ),
+ ),
+)
+ </screen>
+ As we can read, PHP 5.0.0 is required to run the package.
+ </para>
+ <para>
+ Yes, but its the wrong result. HTML_CSS 1.5.1 require only PHP 4.3.0 to run.
+ <tip>
+ <para>
+ If you have <literal>cond_code</literal> offset with a value different
+ than zero, you are almost sure that the version given is wrong.
+ </para>
+ </tip>
+ So why we get such result ?
+ </para>
+ <para>
+ Package PEAR::HTML_CSS 1.5.1 as many application/extension use conditional code
+ to emulate function that are unavailable for previous PHP versions. Its means that
+ HTML_CSS use the php function function_exists() to implement such alternative.
+ </para>
+ <para>
+ To illustrate our purpose, we can find in source code (CSS.php) :
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// ...
+ if (function_exists('file_put_contents')) {
+ file_put_contents($filename, $this->toString());
+ } else {
+ $file = fopen($filename, 'wb');
+ fwrite($file, $this->toString());
+ fclose($file);
+ }
+// ...
+?>
+ ]]>
+ </programlisting>
+ PHP function file_put_contents() came with version 5.0.0; That is the reason
+ of wrong parsing result. But we can catch such conditional code.
+ </para>
+
+ <para>
+ Let's see now how to set the good accuracy with
+ conditional code analysis.
+ </para>
+ </refsect1>
+
</refentry>
<!-- Keep this comment at the end of the file
Local variables: