<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="phar.buildfromdirectory" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>Phar::buildFromDirectory</refname>
  <refpurpose>Construct a phar archive from the files within a directory</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="Phar">
   <modifier>public</modifier> <type>array</type><methodname>Phar::buildFromDirectory</methodname>
   <methodparam><type>string</type><parameter>directory</parameter></methodparam>
   <methodparam choice="opt"><type>string</type><parameter>pattern</parameter><initializer>""</initializer></methodparam>
  </methodsynopsis>
  &phar.write;
  <para>
   Populate a phar archive from directory contents.  The optional second
   parameter is a regular expression (pcre) that is used to exclude files.
   Any filename that matches the regular expression will be included, all others will be
   excluded.  For more fine-grained control, use <function>Phar::buildFromIterator</function>.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>directory</parameter></term>
     <listitem>
      <para>
       The full or relative path to the directory that contains all files
       to add to the archive.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>pattern</parameter></term>
     <listitem>
      <para>
       An optional pcre regular expression that is used to filter the
       list of files.  Only file paths matching the regular expression
       will be included in the archive.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>

 </refsect1>
 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   <function>Phar::buildFromDirectory</function> returns an associative array
   mapping internal path of file to the full path of the file on the
   filesystem.
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  <para>
   This method throws <classname>BadMethodCallException</classname> when unable
   to instantiate the internal directory iterators,
   or a <classname>PharException</classname> if there were errors
   saving the phar archive.
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <informaltable>
   <tgroup cols="2">
    <thead>
     <row>
      <entry>&Version;</entry>
      <entry>&Description;</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>8.1.0</entry>
      <entry>
       <methodname>Phar::buildFromDirectory</methodname> no longer returns &false;.
      </entry>
     </row>
    </tbody>
   </tgroup>
  </informaltable>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
    <title>A <function>Phar::buildFromDirectory</function> example</title>
  <para>
   
  </para>
  <para>
   <programlisting role="php">
    <![CDATA[
<?php
// create with alias "project.phar"
$phar = new Phar('project.phar', 0, 'project.phar');
// add all files in the project
$phar->buildFromDirectory(dirname(__FILE__) . '/project');
$phar->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php'));

$phar2 = new Phar('project2.phar', 0, 'project2.phar');
// add all files in the project, only include php files
$phar2->buildFromDirectory(dirname(__FILE__) . '/project', '/\.php$/');
$phar2->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php'));
?>
    ]]>
   </programlisting>
  </para>
  </example>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>Phar::buildFromIterator</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
-->
