Location: PHPKode > projects > Cgiapp.class.php > Cgiapp2-2.0.0/doc/__filesource/fsource_Cgiapp2__Cgiapp2.class.php.html
<html>
<head>
<title>File Source for Cgiapp2.class.php</title>
<link rel="stylesheet" type="text/css" href="../media/style.css">
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  <tr>
    <td class="header_top">Cgiapp2</td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
  <tr>
    <td class="header_menu">
  		  [ <a href="../classtrees_Cgiapp2.html" class="menu">class tree: Cgiapp2</a> ]
		  [ <a href="../elementindex_Cgiapp2.html" class="menu">index: Cgiapp2</a> ]
		  [ <a href="../elementindex.html" class="menu">all elements</a> ]
    </td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="200" class="menu">
	<div id="ric">
					<p><a href="../ric_Changelog.html">Changelog</a></p>
					<p><a href="../ric_README.html">README</a></p>
			</div>
      <b>Packages:</b><br />
              <a href="../li_Cgiapp2.html">Cgiapp2</a><br />
            <br /><br />
                  
                </td>
    <td>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1 align="center">Source for file Cgiapp2.class.php</h1>
<p>Documentation is available at <a href="../Cgiapp2/_Cgiapp2_class_php.html">Cgiapp2.class.php</a></p>
<div class="php">
<div class="listing"><pre><ol><li><a name="a1"></a><span class="src-php">&lt;?php</span></li>
<li><a name="a2"></a><span class="src-doc">/**</span></li>
<li><a name="a3"></a><span class="src-doc"> * Cgiapp2 - Framework for building reusable web-applications</span></li>
<li><a name="a4"></a><span class="src-doc"> *</span></li>
<li><a name="a5"></a><span class="src-doc"> * A PHP5 port of perl's CGI::Application, a framework for building reusable web</span></li>
<li><a name="a6"></a><span class="src-doc"> * applications.</span></li>
<li><a name="a7"></a><span class="src-doc"> *</span></li>
<li><a name="a8"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@package</span><span class="src-doc"> Cgiapp2</span></li>
<li><a name="a9"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@author</span><span class="src-doc"> Matthew Weier O'Phinney &lt;hide@address.com&gt;; based on</span></li>
<li><a name="a10"></a><span class="src-doc"> *  CGI::Application, by Jesse Erlbaum &lt;hide@address.com&gt;, et. al.</span></li>
<li><a name="a11"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@copyright</span><span class="src-doc"> (c) 2004 - present, Matthew Weier O'Phinney</span></li>
<li><a name="a12"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@license</span><span class="src-doc"> BSD License (http://www.opensource.org/licenses/bsd-license.php)</span></li>
<li><a name="a13"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@category</span><span class="src-doc"> Tools and Utilities</span></li>
<li><a name="a14"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@tutorial</span><span class="src-doc"> Cgiapp2/Cgiapp2.cls</span></li>
<li><a name="a15"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@version</span><span class="src-doc"> $Id:$</span></li>
<li><a name="a16"></a><span class="src-doc"> */</span></li>
<li><a name="a17"></a>&nbsp;</li>
<li><a name="a18"></a><span class="src-doc">/**</span></li>
<li><a name="a19"></a><span class="src-doc"> * PHP &gt;= 5.0.0 only</span></li>
<li><a name="a20"></a><span class="src-doc"> */</span></li>
<li><a name="a21"></a><span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/version_compare">version_compare</a><span class="src-sym">(</span><a href="http://www.php.net/phpversion">phpversion</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-str">'5.0.0'</span><span class="src-sym">, </span><span class="src-str">'lt'</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a22"></a>    <a href="http://www.php.net/trigger_error">trigger_error</a><span class="src-sym">(</span></li>
<li><a name="a23"></a>        <span class="src-str">'This version of Cgiapp2 requires PHP5 or greater'</span><span class="src-sym">, </span></li>
<li><a name="a24"></a>        <span class="src-id">E_USER_ERROR</span></li>
<li><a name="a25"></a>    <span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a26"></a><span class="src-sym">}</span></li>
<li><a name="a27"></a>&nbsp;</li>
<li><a name="a28"></a><span class="src-doc">/**</span></li>
<li><a name="a29"></a><span class="src-doc"> * Set include_path to ensure the directory in which Cgiapp2 sits is in it</span></li>
<li><a name="a30"></a><span class="src-doc"> */</span></li>
<li><a name="a31"></a><span class="src-var">$_CGIAPP_PATH </span>= <a href="http://www.php.net/ini_get">ini_get</a><span class="src-sym">(</span><span class="src-str">'include_path'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a32"></a><a href="http://www.php.net/ini_set">ini_set</a><span class="src-sym">(</span><span class="src-str">'include_path'</span><span class="src-sym">, </span><a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span>__FILE__<span class="src-sym">) </span>. <span class="src-str">':' </span>. <span class="src-var">$_CGIAPP_PATH</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a33"></a>unset<span class="src-sym">(</span><span class="src-var">$_CGIAPP_PATH</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a34"></a>&nbsp;</li>
<li><a name="a35"></a><span class="src-doc">/**</span></li>
<li><a name="a36"></a><span class="src-doc"> * Cgiapp2_Exception_Error: Handle PHP errors as exceptions during run mode</span></li>
<li><a name="a37"></a><span class="src-doc"> * execution</span></li>
<li><a name="a38"></a><span class="src-doc"> */</span></li>
<li><a name="a39"></a><span class="src-inc">require_once </span><span class="src-str">'Cgiapp2/Exception/Error.class.php'</span><span class="src-sym">;</span></li>
<li><a name="a40"></a>&nbsp;</li>
<li><a name="a41"></a><span class="src-doc">/**</span></li>
<li><a name="a42"></a><span class="src-doc"> * Cgiapp2 - Framework for building reusable web-applications</span></li>
<li><a name="a43"></a><span class="src-doc"> *</span></li>
<li><a name="a44"></a><span class="src-doc"> * A PHP5 port of perl's CGI::Application, a framework for building reusable web</span></li>
<li><a name="a45"></a><span class="src-doc"> * applications.</span></li>
<li><a name="a46"></a><span class="src-doc"> * </span></li>
<li><a name="a47"></a><span class="src-doc"> * &lt;b&gt;SYNOPSIS&lt;/b&gt;</span></li>
<li><a name="a48"></a><span class="src-doc"> *</span></li>
<li><a name="a49"></a><span class="src-doc"> * &lt;code&gt;</span></li>
<li><a name="a50"></a><span class="src-doc"> * // In &quot;WebApp.class.php&quot;...</span></li>
<li><a name="a51"></a><span class="src-doc"> * require_once 'Cgiapp2.class.php';</span></li>
<li><a name="a52"></a><span class="src-doc"> * class WebApp extends Cgiapp2</span></li>
<li><a name="a53"></a><span class="src-doc"> * {</span></li>
<li><a name="a54"></a><span class="src-doc"> *     function setup()</span></li>
<li><a name="a55"></a><span class="src-doc"> *     {</span></li>
<li><a name="a56"></a><span class="src-doc"> *         $this-&gt;start_mode('mode1');</span></li>
<li><a name="a57"></a><span class="src-doc"> *         $this-&gt;mode_param('rm');</span></li>
<li><a name="a58"></a><span class="src-doc"> *         $this-&gt;run_modes(array(</span></li>
<li><a name="a59"></a><span class="src-doc"> *             'mode1' =&gt; 'do_stuff',</span></li>
<li><a name="a60"></a><span class="src-doc"> *             'mode2' =&gt; 'do_more_stuff',</span></li>
<li><a name="a61"></a><span class="src-doc"> *             'mode3' =&gt; 'do_something_else'</span></li>
<li><a name="a62"></a><span class="src-doc"> *         ));</span></li>
<li><a name="a63"></a><span class="src-doc"> *     }</span></li>
<li><a name="a64"></a><span class="src-doc"> *     function do_stuff() { ... }</span></li>
<li><a name="a65"></a><span class="src-doc"> *     function do_more_stuff() { ... }</span></li>
<li><a name="a66"></a><span class="src-doc"> *     function do_something_else() { ... }</span></li>
<li><a name="a67"></a><span class="src-doc"> * }</span></li>
<li><a name="a68"></a><span class="src-doc"> * </span></li>
<li><a name="a69"></a><span class="src-doc"> * </span></li>
<li><a name="a70"></a><span class="src-doc"> * // In &quot;webapp.php&quot;...</span></li>
<li><a name="a71"></a><span class="src-doc"> * require_once 'WebApp.class.php';</span></li>
<li><a name="a72"></a><span class="src-doc"> * $webapp = new WebApp();</span></li>
<li><a name="a73"></a><span class="src-doc"> * $webapp-&gt;run();</span></li>
<li><a name="a74"></a><span class="src-doc"> * &lt;/code&gt;</span></li>
<li><a name="a75"></a><span class="src-doc"> * </span></li>
<li><a name="a76"></a><span class="src-doc"> * For more information, see the </span><span class="src-doc-inlinetag">{@tutorial Cgiapp2/Cgiapp2.cls tutorials}</span><span class="src-doc">.</span></li>
<li><a name="a77"></a><span class="src-doc"> * </span></li>
<li><a name="a78"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@package</span><span class="src-doc"> Cgiapp2</span></li>
<li><a name="a79"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@tutorial</span><span class="src-doc"> Cgiapp2/Cgiapp2.cls</span></li>
<li><a name="a80"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@version</span><span class="src-doc"> @release-version@</span></li>
<li><a name="a81"></a><span class="src-doc"> */</span></li>
<li><a name="a82"></a><span class="src-key">abstract </span><span class="src-key">class </span><a href="../Cgiapp2/Cgiapp2.html">Cgiapp2</a></li>
<li><a name="a83"></a><span class="src-sym">{</span></li>
<li><a name="a84"></a>    <span class="src-doc">/**</span></li>
<li><a name="a85"></a><span class="src-doc">     * Array of $_GET and $_POST variables; see also </span><span class="src-doc-inlinetag">{@link query()}</span></li>
<li><a name="a86"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a87"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a88"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> protected</span></li>
<li><a name="a89"></a><span class="src-doc">     */</span></li>
<li><a name="a90"></a>    <span class="src-key">private </span><span class="src-key">static </span><span class="src-var">$CGIAPP_REQUEST </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a91"></a>&nbsp;</li>
<li><a name="a92"></a>    <span class="src-doc">/**</span></li>
<li><a name="a93"></a><span class="src-doc">     * Array of PATH_INFO elements; see also </span><span class="src-doc-inlinetag">{@link path_info()}</span></li>
<li><a name="a94"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a95"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a96"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> protected</span></li>
<li><a name="a97"></a><span class="src-doc">     */</span></li>
<li><a name="a98"></a>    <span class="src-key">private </span><span class="src-key">static </span><span class="src-var">$CGIAPP_PATH_INFO </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a99"></a>&nbsp;</li>
<li><a name="a100"></a>    <span class="src-doc-template">/**#@+</span></li>
<li><a name="a101"></a><span class="src-doc-template">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc-template"> private</span></li>
<li><a name="a102"></a><span class="src-doc-template">     */</span></li>
<li><a name="a103"></a>&nbsp;</li>
<li><a name="a104"></a>    <span class="src-doc">/**</span></li>
<li><a name="a105"></a><span class="src-doc">     * Generated body content</span></li>
<li><a name="a106"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a107"></a><span class="src-doc">     */</span></li>
<li><a name="a108"></a>    <span class="src-key">private </span><span class="src-var">$__body</span><span class="src-sym">;</span></li>
<li><a name="a109"></a>&nbsp;</li>
<li><a name="a110"></a>    <span class="src-doc">/**</span></li>
<li><a name="a111"></a><span class="src-doc">     * Array containing class hierarchy in reverse order</span></li>
<li><a name="a112"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a113"></a><span class="src-doc">     */</span></li>
<li><a name="a114"></a>    <span class="src-key">private </span><span class="src-var">$_CALLBACK_CLASSES </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a115"></a>&nbsp;</li>
<li><a name="a116"></a>    <span class="src-doc">/**</span></li>
<li><a name="a117"></a><span class="src-doc">     * Array of installed callbacks. Hooks allowed are:</span></li>
<li><a name="a118"></a><span class="src-doc">     * &lt;ul&gt;</span></li>
<li><a name="a119"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;init&lt;/b&gt; - hooks called during initialization; see</span></li>
<li><a name="a120"></a><span class="src-doc">     *     </span><span class="src-doc-inlinetag">{@link cgiapp_init()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a121"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;prerun&lt;/b&gt; - hooks called during prerun; see</span></li>
<li><a name="a122"></a><span class="src-doc">     *     </span><span class="src-doc-inlinetag">{@link cgiapp_prerun()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a123"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;postrun&lt;/b&gt; - hooks called during postrun; see</span></li>
<li><a name="a124"></a><span class="src-doc">     *     </span><span class="src-doc-inlinetag">{@link cgiapp_postrun()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a125"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;teardown&lt;/b&gt; - hooks called during teardown; see</span></li>
<li><a name="a126"></a><span class="src-doc">     *     </span><span class="src-doc-inlinetag">{@link teardown()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a127"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;tmpl_path&lt;/b&gt; - hooks called during </span><span class="src-doc-inlinetag">{@link tmpl_path()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a128"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;tmpl_assign&lt;/b&gt; - hooks called during</span></li>
<li><a name="a129"></a><span class="src-doc">     *     </span><span class="src-doc-inlinetag">{@link tmpl_assign()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a130"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;tmpl_fetch&lt;/b&gt; - hooks called during </span><span class="src-doc-inlinetag">{@link load_tmpl()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a131"></a><span class="src-doc">     *     &lt;li&gt;&lt;b&gt;error&lt;/b&gt; - hooks called prior to calling the error mode</span></li>
<li><a name="a132"></a><span class="src-doc">     *     during application </span><span class="src-doc-inlinetag">{@link run()}</span><span class="src-doc">&lt;/li&gt;</span></li>
<li><a name="a133"></a><span class="src-doc">     * &lt;/ul&gt;</span></li>
<li><a name="a134"></a><span class="src-doc">     * See </span><span class="src-doc-inlinetag">{@link add_callback()}</span><span class="src-doc"> for more information.</span></li>
<li><a name="a135"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a136"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a137"></a><span class="src-doc">     */</span></li>
<li><a name="a138"></a>    <span class="src-key">private </span><span class="src-key">static </span><span class="src-var">$_INSTALLED_CALLBACKS </span>= <span class="src-key">array</span><span class="src-sym">(</span></li>
<li><a name="a139"></a>        <span class="src-comm">// hook name        package             sub</span></li>
<li><a name="a140"></a>                <span class="src-str">'init'        </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span></li>
<li><a name="a141"></a>        <span class="src-str">'prerun'      </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span></li>
<li><a name="a142"></a>        <span class="src-str">'postrun'     </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span></li>
<li><a name="a143"></a>        <span class="src-str">'teardown'    </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span></li>
<li><a name="a144"></a>        <span class="src-str">'tmpl_path'   </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span></li>
<li><a name="a145"></a>        <span class="src-str">'tmpl_assign' </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span></li>
<li><a name="a146"></a>        <span class="src-str">'tmpl_fetch'  </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">,</span></li>
<li><a name="a147"></a>        <span class="src-str">'error'       </span>=&gt; <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span></li>
<li><a name="a148"></a>    <span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a149"></a>&nbsp;</li>
<li><a name="a150"></a>    <span class="src-doc">/**</span></li>
<li><a name="a151"></a><span class="src-doc">     * Array matching hook name to where the object instance will be called in</span></li>
<li><a name="a152"></a><span class="src-doc">     * the argument list. 'true' means at beginning, 'false' means at end.</span></li>
<li><a name="a153"></a><span class="src-doc">     * See </span><span class="src-doc-inlinetag">{@link call_hook()}</span><span class="src-doc"> for more information.</span></li>
<li><a name="a154"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a155"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a156"></a><span class="src-doc">     */</span></li>
<li><a name="a157"></a>    <span class="src-key">private </span><span class="src-key">static </span><span class="src-var">$_HOOK_ARG_PLACEMENT </span>= <span class="src-key">array</span><span class="src-sym">(</span></li>
<li><a name="a158"></a>        <span class="src-str">'init'        </span>=&gt; <span class="src-id">false</span><span class="src-sym">,</span></li>
<li><a name="a159"></a>        <span class="src-str">'prerun'      </span>=&gt; <span class="src-id">false</span><span class="src-sym">,</span></li>
<li><a name="a160"></a>        <span class="src-str">'postrun'     </span>=&gt; <span class="src-id">false</span><span class="src-sym">,</span></li>
<li><a name="a161"></a>        <span class="src-str">'teardown'    </span>=&gt; <span class="src-id">true</span><span class="src-sym">,</span></li>
<li><a name="a162"></a>        <span class="src-str">'tmpl_path'   </span>=&gt; <span class="src-id">true</span><span class="src-sym">,</span></li>
<li><a name="a163"></a>        <span class="src-str">'tmpl_fetch'  </span>=&gt; <span class="src-id">true</span><span class="src-sym">,</span></li>
<li><a name="a164"></a>        <span class="src-str">'tmpl_assign' </span>=&gt; <span class="src-id">true</span><span class="src-sym">,</span></li>
<li><a name="a165"></a>        <span class="src-str">'error'       </span>=&gt; <span class="src-id">true</span></li>
<li><a name="a166"></a>    <span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a167"></a>&nbsp;</li>
<li><a name="a168"></a>    <span class="src-doc">/**</span></li>
<li><a name="a169"></a><span class="src-doc">     * Array of template hooks. Template hooks can only keep a single registered</span></li>
<li><a name="a170"></a><span class="src-doc">     * callback at a time.</span></li>
<li><a name="a171"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a172"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a173"></a><span class="src-doc">     */</span></li>
<li><a name="a174"></a>    <span class="src-key">private </span><span class="src-key">static </span><span class="src-var">$_TMPL_HOOKS </span>= <span class="src-key">array</span><span class="src-sym">(</span></li>
<li><a name="a175"></a>        <span class="src-str">'tmpl_path'</span><span class="src-sym">, </span></li>
<li><a name="a176"></a>        <span class="src-str">'tmpl_assign'</span><span class="src-sym">,</span></li>
<li><a name="a177"></a>        <span class="src-str">'tmpl_fetch'</span></li>
<li><a name="a178"></a>    <span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a179"></a>&nbsp;</li>
<li><a name="a180"></a>    <span class="src-doc">/**</span></li>
<li><a name="a181"></a><span class="src-doc">     * Array of Cgiapp2 internal methods; used by </span><span class="src-doc-inlinetag">{@link run()}</span><span class="src-doc"> to determine if a</span></li>
<li><a name="a182"></a><span class="src-doc">     * mode parameter that is a method name should call the method or retrieve</span></li>
<li><a name="a183"></a><span class="src-doc">     * the CGI value instead.</span></li>
<li><a name="a184"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a185"></a><span class="src-doc">     */</span></li>
<li><a name="a186"></a>    <span class="src-key">private </span><span class="src-var">$_CGIAPP_METHODS </span>= <span class="src-key">array</span><span class="src-sym">(</span></li>
<li><a name="a187"></a>        <span class="src-str">'cap_hash'</span><span class="src-sym">,</span></li>
<li><a name="a188"></a>        <span class="src-str">'_send_headers'</span><span class="src-sym">,</span></li>
<li><a name="a189"></a>        <span class="src-str">'add_callback'</span><span class="src-sym">,</span></li>
<li><a name="a190"></a>        <span class="src-str">'array_to_hash'</span><span class="src-sym">,</span></li>
<li><a name="a191"></a>        <span class="src-str">'call_hook'</span><span class="src-sym">,</span></li>
<li><a name="a192"></a>        <span class="src-str">'cgiapp_init'</span><span class="src-sym">,</span></li>
<li><a name="a193"></a>        <span class="src-str">'cgiapp_postrun'</span><span class="src-sym">,</span></li>
<li><a name="a194"></a>        <span class="src-str">'cgiapp_prerun'</span><span class="src-sym">,</span></li>
<li><a name="a195"></a>        <span class="src-str">'_class_hierarchy'</span><span class="src-sym">,</span></li>
<li><a name="a196"></a>        <span class="src-str">'delete'</span><span class="src-sym">,</span></li>
<li><a name="a197"></a>        <span class="src-str">'error_mode'</span><span class="src-sym">,</span></li>
<li><a name="a198"></a>        <span class="src-str">'get_current_runmode'</span><span class="src-sym">,</span></li>
<li><a name="a199"></a>        <span class="src-str">'header_props'</span><span class="src-sym">,</span></li>
<li><a name="a200"></a>        <span class="src-str">'header_type'</span><span class="src-sym">,</span></li>
<li><a name="a201"></a>        <span class="src-str">'is_assoc_array'</span><span class="src-sym">,</span></li>
<li><a name="a202"></a>        <span class="src-str">'load_tmpl'</span><span class="src-sym">,</span></li>
<li><a name="a203"></a>        <span class="src-str">'mode_param'</span><span class="src-sym">,</span></li>
<li><a name="a204"></a>        <span class="src-str">'new_hook'</span><span class="src-sym">,</span></li>
<li><a name="a205"></a>        <span class="src-str">'param'</span><span class="src-sym">,</span></li>
<li><a name="a206"></a>        <span class="src-str">'prerun_mode'</span><span class="src-sym">,</span></li>
<li><a name="a207"></a>        <span class="src-str">'query'</span><span class="src-sym">,</span></li>
<li><a name="a208"></a>        <span class="src-str">'run'</span><span class="src-sym">,</span></li>
<li><a name="a209"></a>        <span class="src-str">'run_modes'</span><span class="src-sym">,</span></li>
<li><a name="a210"></a>        <span class="src-str">'s_delete'</span><span class="src-sym">,</span></li>
<li><a name="a211"></a>        <span class="src-str">'s_param'</span><span class="src-sym">,</span></li>
<li><a name="a212"></a>        <span class="src-str">'setup'</span><span class="src-sym">,</span></li>
<li><a name="a213"></a>        <span class="src-str">'start_mode'</span><span class="src-sym">,</span></li>
<li><a name="a214"></a>        <span class="src-str">'teardown'</span><span class="src-sym">,</span></li>
<li><a name="a215"></a>        <span class="src-str">'tmpl_assign'</span><span class="src-sym">,</span></li>
<li><a name="a216"></a>        <span class="src-str">'tmpl_path'</span></li>
<li><a name="a217"></a>    <span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a218"></a>&nbsp;</li>
<li><a name="a219"></a>    <span class="src-doc">/**</span></li>
<li><a name="a220"></a><span class="src-doc">     * Return content instead of echoing to screen; useful if your Cgiapp2-based</span></li>
<li><a name="a221"></a><span class="src-doc">     * application will be used in a larger application. You can set it in your</span></li>
<li><a name="a222"></a><span class="src-doc">     * PARAMS list, if desired.</span></li>
<li><a name="a223"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">bool </span></li>
<li><a name="a224"></a><span class="src-doc">     */</span></li>
<li><a name="a225"></a>    <span class="src-key">private </span><span class="src-var">$_CGIAPP_RETURN_ONLY</span><span class="src-sym">;</span></li>
<li><a name="a226"></a>&nbsp;</li>
<li><a name="a227"></a>    <span class="src-doc">/**</span></li>
<li><a name="a228"></a><span class="src-doc">     * The current run mode being processed.</span></li>
<li><a name="a229"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a230"></a><span class="src-doc">     */</span></li>
<li><a name="a231"></a>    <span class="src-key">private </span><span class="src-var">$_CURRENT_RUNMODE</span><span class="src-sym">;</span></li>
<li><a name="a232"></a>&nbsp;</li>
<li><a name="a233"></a>    <span class="src-doc">/**</span></li>
<li><a name="a234"></a><span class="src-doc">     * Your </span><span class="src-doc-inlinetag">{@link error_mode()}</span><span class="src-doc"> should set this if called; if set,</span></li>
<li><a name="a235"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link run()}</span><span class="src-doc"> will use this value as the return value from the run mode.</span></li>
<li><a name="a236"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a237"></a><span class="src-doc">     */</span></li>
<li><a name="a238"></a>    <span class="src-key">private </span><span class="src-var">$_ERROR_BODY</span><span class="src-sym">;</span></li>
<li><a name="a239"></a>&nbsp;</li>
<li><a name="a240"></a>    <span class="src-doc">/**</span></li>
<li><a name="a241"></a><span class="src-doc">     * When set, indicates the class method to use to handle errors that occur</span></li>
<li><a name="a242"></a><span class="src-doc">     * during execution of the run mode.</span></li>
<li><a name="a243"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a244"></a><span class="src-doc">     */</span></li>
<li><a name="a245"></a>    <span class="src-key">private </span><span class="src-var">$_ERROR_MODE</span><span class="src-sym">;</span></li>
<li><a name="a246"></a>&nbsp;</li>
<li><a name="a247"></a>    <span class="src-doc">/**</span></li>
<li><a name="a248"></a><span class="src-doc">     * Array of header types =&gt; values.</span></li>
<li><a name="a249"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a250"></a><span class="src-doc">     */</span></li>
<li><a name="a251"></a>    <span class="src-key">private </span><span class="src-var">$_HEADER_PROPS</span><span class="src-sym">;</span></li>
<li><a name="a252"></a>&nbsp;</li>
<li><a name="a253"></a>    <span class="src-doc">/**</span></li>
<li><a name="a254"></a><span class="src-doc">     * Valid values are 'none', 'redirect', and 'header'; used to determine</span></li>
<li><a name="a255"></a><span class="src-doc">     * what, if any, HTTP headers to send.</span></li>
<li><a name="a256"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a257"></a><span class="src-doc">     */</span></li>
<li><a name="a258"></a>    <span class="src-key">private </span><span class="src-var">$_HEADER_TYPE</span><span class="src-sym">;</span></li>
<li><a name="a259"></a>&nbsp;</li>
<li><a name="a260"></a>    <span class="src-doc">/**</span></li>
<li><a name="a261"></a><span class="src-doc">     * The CGI parameter indicating what run mode to call.</span></li>
<li><a name="a262"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a263"></a><span class="src-doc">     */</span></li>
<li><a name="a264"></a>    <span class="src-key">private </span><span class="src-var">$_MODE_PARAM</span><span class="src-sym">;</span></li>
<li><a name="a265"></a>&nbsp;</li>
<li><a name="a266"></a>    <span class="src-doc">/**</span></li>
<li><a name="a267"></a><span class="src-doc">     * Array of parameters handled by param() method; typically, these should be</span></li>
<li><a name="a268"></a><span class="src-doc">     * the only object properties allowed, and they will be normalized with</span></li>
<li><a name="a269"></a><span class="src-doc">     * UPPERCASE keys. </span><span class="src-doc-inlinetag">{@link param()}</span></li>
<li><a name="a270"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a271"></a><span class="src-doc">     */</span></li>
<li><a name="a272"></a>    <span class="src-key">private </span><span class="src-var">$_PARAMS</span><span class="src-sym">;</span></li>
<li><a name="a273"></a>&nbsp;</li>
<li><a name="a274"></a>    <span class="src-doc">/**</span></li>
<li><a name="a275"></a><span class="src-doc">     * Flag indicating whether the generated body content can be changed</span></li>
<li><a name="a276"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">bool </span></li>
<li><a name="a277"></a><span class="src-doc">     */</span></li>
<li><a name="a278"></a>    <span class="src-key">private </span><span class="src-var">$_POSTRUN_MODE_LOCKED</span><span class="src-sym">;</span></li>
<li><a name="a279"></a>&nbsp;</li>
<li><a name="a280"></a>    <span class="src-doc">/**</span></li>
<li><a name="a281"></a><span class="src-doc">     * When set, indicates that the run mode passed should be overridden with</span></li>
<li><a name="a282"></a><span class="src-doc">     * the run mode provided in this property.</span></li>
<li><a name="a283"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a284"></a><span class="src-doc">     */</span></li>
<li><a name="a285"></a>    <span class="src-key">private </span><span class="src-var">$_PRERUN_MODE</span><span class="src-sym">;</span></li>
<li><a name="a286"></a>&nbsp;</li>
<li><a name="a287"></a>    <span class="src-doc">/**</span></li>
<li><a name="a288"></a><span class="src-doc">     * Flag indicating whether the current run mode can be changed.</span></li>
<li><a name="a289"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">bool </span></li>
<li><a name="a290"></a><span class="src-doc">     */</span></li>
<li><a name="a291"></a>    <span class="src-key">private </span><span class="src-var">$_PRERUN_MODE_LOCKED</span><span class="src-sym">;</span></li>
<li><a name="a292"></a>&nbsp;</li>
<li><a name="a293"></a>    <span class="src-doc">/**</span></li>
<li><a name="a294"></a><span class="src-doc">     * Array of allowed run modes for this application.</span></li>
<li><a name="a295"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">array </span></li>
<li><a name="a296"></a><span class="src-doc">     */</span></li>
<li><a name="a297"></a>    <span class="src-key">private </span><span class="src-var">$_RUN_MODES</span><span class="src-sym">;</span></li>
<li><a name="a298"></a>&nbsp;</li>
<li><a name="a299"></a>    <span class="src-doc">/**</span></li>
<li><a name="a300"></a><span class="src-doc">     * Name of the session ID to set or use to prepend to all session variables;</span></li>
<li><a name="a301"></a><span class="src-doc">     * see </span><span class="src-doc-inlinetag">{@link s_param()}</span><span class="src-doc"> for more information.</span></li>
<li><a name="a302"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a303"></a><span class="src-doc">     */</span></li>
<li><a name="a304"></a>    <span class="src-key">private </span><span class="src-var">$_SESSION_ID</span><span class="src-sym">;</span></li>
<li><a name="a305"></a>&nbsp;</li>
<li><a name="a306"></a>    <span class="src-doc">/**</span></li>
<li><a name="a307"></a><span class="src-doc">     * Indicates which run mode to run by default.</span></li>
<li><a name="a308"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a309"></a><span class="src-doc">     */</span></li>
<li><a name="a310"></a>    <span class="src-key">private </span><span class="src-var">$_START_MODE</span><span class="src-sym">;</span></li>
<li><a name="a311"></a>&nbsp;</li>
<li><a name="a312"></a>    <span class="src-doc">/**</span></li>
<li><a name="a313"></a><span class="src-doc">     * Base template directory; typically, base Smarty working directory.</span></li>
<li><a name="a314"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a315"></a><span class="src-doc">     */</span></li>
<li><a name="a316"></a>    <span class="src-key">private </span><span class="src-var">$_TMPL_PATH</span><span class="src-sym">;</span></li>
<li><a name="a317"></a>&nbsp;</li>
<li><a name="a318"></a>    <span class="src-doc-close-template">/**#@-*/</span></li>
<li><a name="a319"></a>&nbsp;</li>
<li><a name="a320"></a>    <span class="src-doc">/**</span></li>
<li><a name="a321"></a><span class="src-doc">     * Constructor</span></li>
<li><a name="a322"></a><span class="src-doc">     * </span></li>
<li><a name="a323"></a><span class="src-doc">     * The constructor sets up default values for </span><span class="src-doc-inlinetag">{@link _HEADER_TYPE}</span><span class="src-doc">,</span></li>
<li><a name="a324"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link _MODE_PARAM}</span><span class="src-doc">, and </span><span class="src-doc-inlinetag">{@link _START_MODE}</span><span class="src-doc">. If an associative array has</span></li>
<li><a name="a325"></a><span class="src-doc">     * been passed to it as an argument, it processes it. The array should have</span></li>
<li><a name="a326"></a><span class="src-doc">     * one or more of the following elements:</span></li>
<li><a name="a327"></a><span class="src-doc">     * &lt;ul&gt;</span></li>
<li><a name="a328"></a><span class="src-doc">     * &lt;li&gt;TMPL_PATH: an optional path argument passed to </span><span class="src-doc-inlinetag">{@link tmpl_path()}</span></li>
<li><a name="a329"></a><span class="src-doc">     *   along with _TMPL_ARGS (if given) to instantiate the</span></li>
<li><a name="a330"></a><span class="src-doc">     *   template object. This should be the path to the base template</span></li>
<li><a name="a331"></a><span class="src-doc">     *   directory; if using Smarty, this would be the directory holding the</span></li>
<li><a name="a332"></a><span class="src-doc">     *   templates, templates_c, configs, and cache directories.&lt;/li&gt;</span></li>
<li><a name="a333"></a><span class="src-doc">     * &lt;li&gt;TMPL_ARGS: an optional associative array of arguments to pass to the</span></li>
<li><a name="a334"></a><span class="src-doc">     *   template object constructor. These can include any valid arguments to</span></li>
<li><a name="a335"></a><span class="src-doc">     *   the template object constructor.&lt;/li&gt;</span></li>
<li><a name="a336"></a><span class="src-doc">     * &lt;li&gt;PARAMS: an optional associative array of parameters that your</span></li>
<li><a name="a337"></a><span class="src-doc">     *   application needs for setup purposes. These might include a database</span></li>
<li><a name="a338"></a><span class="src-doc">     *   DSN, template file names, or specific environment selectors. Keys will</span></li>
<li><a name="a339"></a><span class="src-doc">     *   be normalized using </span><span class="src-doc-inlinetag">{@link cap_hash}</span><span class="src-doc">, and all parameters will be made</span></li>
<li><a name="a340"></a><span class="src-doc">     *   into class variables using the </span><span class="src-doc-inlinetag">{@link param()}</span><span class="src-doc"> method.&lt;/li&gt;</span></li>
<li><a name="a341"></a><span class="src-doc">     * &lt;/ul&gt;</span></li>
<li><a name="a342"></a><span class="src-doc">     * Once the above have been processed, Cgiapp2 calls the</span></li>
<li><a name="a343"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link cgiapp_init()}</span><span class="src-doc"> method, followed by the </span><span class="src-doc-inlinetag">{@link setup()}</span><span class="src-doc"> method;</span></li>
<li><a name="a344"></a><span class="src-doc">     * both of these should be overridden in your class extension.</span></li>
<li><a name="a345"></a><span class="src-doc">     *</span></li>
<li><a name="a346"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$args </span><span class="src-doc">Optional, an associative array; see method and class</span></li>
<li><a name="a347"></a><span class="src-doc">     *  intro notes for details</span></li>
<li><a name="a348"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">bool </span><span class="src-doc">success</span></li>
<li><a name="a349"></a><span class="src-doc">     */</span></li>
<li><a name="a350"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#method__construct">__construct</a><span class="src-sym">(</span><span class="src-var">$args </span>= <span class="src-id">null</span><span class="src-sym">)</span></li>
<li><a name="a351"></a>    <span class="src-sym">{</span></li>
<li><a name="a352"></a>        <span class="src-comm">// SET UP DEFAULT VALUES</span></li>
<li><a name="a353"></a>        <span class="src-comm">// We set them up here and not in the setup() because a subclass which</span></li>
<li><a name="a354"></a>        <span class="src-comm">// implements setup() still needs default values!</span></li>
<li><a name="a355"></a>&nbsp;</li>
<li><a name="a356"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodheader_type">header_type</a><span class="src-sym">(</span><span class="src-str">'header'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a357"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodmode_param">mode_param</a><span class="src-sym">(</span><span class="src-str">'rm'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a358"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodstart_mode">start_mode</a><span class="src-sym">(</span><span class="src-str">'start'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a359"></a>&nbsp;</li>
<li><a name="a360"></a>        <span class="src-comm">// Setup some default hooks</span></li>
<li><a name="a361"></a>        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">add_callback</span><span class="src-sym">(</span><span class="src-str">'init'</span><span class="src-sym">, </span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-str">'cgiapp_init'</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a362"></a>        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">add_callback</span><span class="src-sym">(</span><span class="src-str">'prerun'</span><span class="src-sym">, </span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-str">'cgiapp_prerun'</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a363"></a>        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">add_callback</span><span class="src-sym">(</span><span class="src-str">'postrun'</span><span class="src-sym">, </span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-str">'cgiapp_postrun'</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a364"></a>        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">add_callback</span><span class="src-sym">(</span><span class="src-str">'teardown'</span><span class="src-sym">, </span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-str">'teardown'</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a365"></a>&nbsp;</li>
<li><a name="a366"></a>        <span class="src-comm">// Process optional new() parameters</span></li>
<li><a name="a367"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a368"></a>            <span class="src-var">$rprops </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">cap_hash</span><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a369"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a370"></a>            <span class="src-var">$rprops </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a371"></a>        <span class="src-sym">}</span></li>
<li><a name="a372"></a>&nbsp;</li>
<li><a name="a373"></a>        <span class="src-comm">// Set tmpl_path using TMPL_PATH. If TMPL_ARGS has been passed, pass</span></li>
<li><a name="a374"></a>        <span class="src-comm">// that to tmpl_path() as well.</span></li>
<li><a name="a375"></a>        <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'TMPL_PATH'</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a376"></a>            <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'TMPL_ARGS'</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a377"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_TMPL_ARGS </span>= <span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'TMPL_ARGS'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a378"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodtmpl_path">tmpl_path</a><span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'TMPL_PATH'</span><span class="src-sym">]</span><span class="src-sym">, </span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'TMPL_ARGS'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a379"></a>            <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a380"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodtmpl_path">tmpl_path</a><span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'TMPL_PATH'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a381"></a>            <span class="src-sym">}</span></li>
<li><a name="a382"></a>        <span class="src-sym">}</span></li>
<li><a name="a383"></a>&nbsp;</li>
<li><a name="a384"></a>        <span class="src-comm">// Set up init param() values</span></li>
<li><a name="a385"></a>        <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'PARAMS'</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a386"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'PARAMS'</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a387"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;PARAMS is not an associative array&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a388"></a>            <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a389"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">[</span><span class="src-str">'PARAMS'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a390"></a>            <span class="src-sym">}</span></li>
<li><a name="a391"></a>        <span class="src-sym">}</span></li>
<li><a name="a392"></a>&nbsp;</li>
<li><a name="a393"></a>        <span class="src-comm">// Lock prerun_mode from being changed until cgiapp_prerun()</span></li>
<li><a name="a394"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE_LOCKED </span>= <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a395"></a>&nbsp;</li>
<li><a name="a396"></a>        <span class="src-comm">// Lock postrun_body from being called until cgiapp_postrun()</span></li>
<li><a name="a397"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_POSTRUN_MODE_LOCKED </span>= <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a398"></a>&nbsp;</li>
<li><a name="a399"></a>        <span class="src-comm">// Call init hook, which may be implemented in the sub-class or another</span></li>
<li><a name="a400"></a>        <span class="src-comm">// class entirely. Pass all constructor args forward.  This will allow</span></li>
<li><a name="a401"></a>        <span class="src-comm">// flexible usage down the line.</span></li>
<li><a name="a402"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-str">'init'</span><span class="src-sym">, </span><span class="src-var">$args</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a403"></a>&nbsp;</li>
<li><a name="a404"></a>        <span class="src-comm">// Call setup() method, which should be implemented in the sub-class!</span></li>
<li><a name="a405"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodsetup">setup</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a406"></a>&nbsp;</li>
<li><a name="a407"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a408"></a>    <span class="src-sym">}</span></li>
<li><a name="a409"></a>&nbsp;</li>
<li><a name="a410"></a>    <span class="src-doc">/**</span></li>
<li><a name="a411"></a><span class="src-doc">     * Run the application</span></li>
<li><a name="a412"></a><span class="src-doc">     * </span></li>
<li><a name="a413"></a><span class="src-doc">     * The run() method is called upon your Application object, from</span></li>
<li><a name="a414"></a><span class="src-doc">     * your Instance Script.  When called, it executes the functionality</span></li>
<li><a name="a415"></a><span class="src-doc">     * in your Application Class.</span></li>
<li><a name="a416"></a><span class="src-doc">     * </span></li>
<li><a name="a417"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a418"></a><span class="src-doc">     *     $webapp = new WebApp();</span></li>
<li><a name="a419"></a><span class="src-doc">     *     $webapp-&gt;run();</span></li>
<li><a name="a420"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a421"></a><span class="src-doc">     * </span></li>
<li><a name="a422"></a><span class="src-doc">     * This method first determines the application state by looking at the</span></li>
<li><a name="a423"></a><span class="src-doc">     * value of the CGI parameter specified by </span><span class="src-doc-inlinetag">{@link mode_param()}</span><span class="src-doc"> (defaults to</span></li>
<li><a name="a424"></a><span class="src-doc">     * 'rm' for &quot;Run Mode&quot;), which is expected to contain the name of the mode</span></li>
<li><a name="a425"></a><span class="src-doc">     * of operation.  If not specified, the state defaults to the value of</span></li>
<li><a name="a426"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link start_mode()}</span><span class="src-doc">.</span></li>
<li><a name="a427"></a><span class="src-doc">     * </span></li>
<li><a name="a428"></a><span class="src-doc">     * Once the mode has been determined, run() looks at the dispatch table</span></li>
<li><a name="a429"></a><span class="src-doc">     * stored in </span><span class="src-doc-inlinetag">{@link run_modes()}</span><span class="src-doc"> and finds the function pointer which is</span></li>
<li><a name="a430"></a><span class="src-doc">     * keyed from the mode name.  If found, the function is called and the data</span></li>
<li><a name="a431"></a><span class="src-doc">     * is returned to STDOUT (usually the browser).  If the specified mode is</span></li>
<li><a name="a432"></a><span class="src-doc">     * not found in the </span><span class="src-doc-inlinetag">{@link run_modes()}</span><span class="src-doc"> table, run() will </span><span class="src-doc-inlinetag">{@link croak()}</span><span class="src-doc">.</span></li>
<li><a name="a433"></a><span class="src-doc">     */</span></li>
<li><a name="a434"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodrun">run</a><span class="src-sym">(</span><span class="src-sym">) </span></li>
<li><a name="a435"></a>    <span class="src-sym">{</span></li>
<li><a name="a436"></a>        <span class="src-var">$rm_param </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodmode_param">mode_param</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a437"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$rm_param</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a438"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">&quot;No run mode param specified&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a439"></a>            <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a440"></a>        <span class="src-sym">}</span></li>
<li><a name="a441"></a>&nbsp;</li>
<li><a name="a442"></a>        <span class="src-var">$REQUEST </span>=<span class="src-sym">&amp; </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a443"></a>&nbsp;</li>
<li><a name="a444"></a>        <span class="src-comm">// Get run mode</span></li>
<li><a name="a445"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$rm_param</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a446"></a>            <span class="src-comm">// Run mode defined by PATH_INFO; grab from array</span></li>
<li><a name="a447"></a>            <span class="src-var">$rm </span>= <span class="src-var">$rm_param</span><span class="src-sym">[</span><span class="src-str">'run_mode'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a448"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/function_exists">function_exists</a><span class="src-sym">(</span><span class="src-var">$rm_param</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a449"></a>            <span class="src-comm">// $rm_param matches a function name.</span></li>
<li><a name="a450"></a>            <span class="src-comm">// Determine if run mode is a user-defined function</span></li>
<li><a name="a451"></a>            <span class="src-var">$functions </span>= <a href="http://www.php.net/get_defined_functions">get_defined_functions</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a452"></a>            <span class="src-var">$user_func </span>= <span class="src-var">$functions</span><span class="src-sym">[</span><span class="src-str">'user'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a453"></a>            <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/in_array">in_array</a><span class="src-sym">(</span><span class="src-var">$rm_param</span><span class="src-sym">, </span><span class="src-var">$user_func</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a454"></a>                <span class="src-comm">// Get run mode from user-defined function</span></li>
<li><a name="a455"></a>                <span class="src-var">$rm </span>= <span class="src-var">$rm_param</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a456"></a>            <span class="src-sym">}</span></li>
<li><a name="a457"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/method_exists">method_exists</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-var">$rm_param</span><span class="src-sym">) </span>&amp;&amp;</li>
<li><a name="a458"></a>            <span class="src-sym">!</span><a href="http://www.php.net/in_array">in_array</a><span class="src-sym">(</span><span class="src-var">$rm_param</span><span class="src-sym">, </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CGIAPP_METHODS</span><span class="src-sym">)) </span></li>
<li><a name="a459"></a>        <span class="src-sym">{</span></li>
<li><a name="a460"></a>            <span class="src-comm">// Get run-mode from method</span></li>
<li><a name="a461"></a>            <span class="src-var">$rm </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$rm_param</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a462"></a>        <span class="src-sym">}</span></li>
<li><a name="a463"></a>        </li>
<li><a name="a464"></a>        <span class="src-comm">// Get run-mode from CGI param</span></li>
<li><a name="a465"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$rm</span><span class="src-sym">))</span><span class="src-sym">{</span></li>
<li><a name="a466"></a>            <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$REQUEST</span><span class="src-sym">[</span><span class="src-var">$rm_param</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a467"></a>                <span class="src-var">$rm </span>= <span class="src-var">$REQUEST</span><span class="src-sym">[</span><span class="src-var">$rm_param</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a468"></a>            <span class="src-sym">}</span></li>
<li><a name="a469"></a>        <span class="src-sym">}</span></li>
<li><a name="a470"></a>        <span class="src-comm">// If run mode not passed, or unknown runmode passed, use the start_mode</span></li>
<li><a name="a471"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$rm</span><span class="src-sym">) </span>|| <span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_RUN_MODES</span><span class="src-sym">[</span><span class="src-var">$rm</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a472"></a>            <span class="src-var">$rm </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodstart_mode">start_mode</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a473"></a>        <span class="src-sym">}</span></li>
<li><a name="a474"></a>&nbsp;</li>
<li><a name="a475"></a>        <span class="src-comm">// Set get_current_runmode() for access by user later</span></li>
<li><a name="a476"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CURRENT_RUNMODE </span>= <span class="src-var">$rm</span><span class="src-sym">;</span></li>
<li><a name="a477"></a>&nbsp;</li>
<li><a name="a478"></a>        <span class="src-comm">// Allow prerun_mode to be changed</span></li>
<li><a name="a479"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE_LOCKED </span>= <span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a480"></a>&nbsp;</li>
<li><a name="a481"></a>        <span class="src-comm">// Call PRE-RUN hook, now that we know the run-mode</span></li>
<li><a name="a482"></a>        <span class="src-comm">// This hook can be used to provide run-mode specific behaviors</span></li>
<li><a name="a483"></a>        <span class="src-comm">// before the run-mode actually runs.</span></li>
<li><a name="a484"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-str">'prerun'</span><span class="src-sym">, </span><span class="src-var">$rm</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a485"></a>&nbsp;</li>
<li><a name="a486"></a>        <span class="src-comm">// Lock prerun_mode from being changed after cgiapp_prerun()</span></li>
<li><a name="a487"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE_LOCKED </span>= <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a488"></a>&nbsp;</li>
<li><a name="a489"></a>        <span class="src-comm">// If prerun_mode has been set, use it!</span></li>
<li><a name="a490"></a>        <span class="src-var">$prerun_mode </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodprerun_mode">prerun_mode</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a491"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$prerun_mode</span><span class="src-sym">) </span></li>
<li><a name="a492"></a>            &amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$prerun_mode</span><span class="src-sym">)) </span></li>
<li><a name="a493"></a>        <span class="src-sym">{</span></li>
<li><a name="a494"></a>            <span class="src-var">$rm </span>= <span class="src-var">$prerun_mode</span><span class="src-sym">;</span></li>
<li><a name="a495"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CURRENT_RUNMODE </span>= <span class="src-var">$rm</span><span class="src-sym">;</span></li>
<li><a name="a496"></a>        <span class="src-sym">}</span></li>
<li><a name="a497"></a>&nbsp;</li>
<li><a name="a498"></a>        <span class="src-var">$rmodes </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodrun_modes">run_modes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a499"></a>&nbsp;</li>
<li><a name="a500"></a>        <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$rmodes</span><span class="src-sym">[</span><span class="src-var">$rm</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a501"></a>            <span class="src-var">$rmeth </span>= <span class="src-var">$rmodes</span><span class="src-sym">[</span><span class="src-var">$rm</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a502"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a503"></a>            <span class="src-var">$msg  </span>= <span class="src-str">&quot;</span><span class="src-str"><span class="src-id">No</span> <span class="src-id">such</span> <span class="src-id">run</span>-<span class="src-id">mode</span> '<span class="src-var">$rm</span>'\n</span><span class="src-str">&quot;</span><span class="src-sym">;</span></li>
<li><a name="a504"></a>            <span class="src-var">$msg </span>.= <span class="src-str">&quot;Available run-modes: &quot; </span>. <a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">', '</span><span class="src-sym">, </span><span class="src-var">$rmodes</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a505"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-var">$msg</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a506"></a>            <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a507"></a>        <span class="src-sym">}</span></li>
<li><a name="a508"></a>&nbsp;</li>
<li><a name="a509"></a>        <span class="src-comm">// Process run mode!</span></li>
<li><a name="a510"></a>        <span class="src-comm">// However, we need to check for errors. Check for exceptions; if any</span></li>
<li><a name="a511"></a>        <span class="src-comm">// are caught, run the error_mode() with the exception as its argument</span></li>
<li><a name="a512"></a>        <span class="src-comm">// and use its return value for the body.</span></li>
<li><a name="a513"></a>        <span class="src-var">$error_mode </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methoderror_mode">error_mode</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a514"></a>        <a href="http://www.php.net/set_error_handler">set_error_handler</a><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">'Cgiapp2_Exception_Error'</span><span class="src-sym">, </span><span class="src-str">'handler'</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-id">E_USER_ERROR</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a515"></a>        try <span class="src-sym">{</span></li>
<li><a name="a516"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">__body </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$rmeth</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a517"></a>        <span class="src-sym">} </span>catch <span class="src-sym">(</span><span class="src-id"><a href="../Cgiapp2/Cgiapp2_Exception.html">Cgiapp2_Exception</a> </span><span class="src-var">$e</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a518"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-str">'error'</span><span class="src-sym">, </span><span class="src-var">$e</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a519"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$error_mode</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a520"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">__body </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$error_mode</span><span class="src-sym">(</span><span class="src-var">$e</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a521"></a>            <span class="src-sym">}</span></li>
<li><a name="a522"></a>        <span class="src-sym">}</span></li>
<li><a name="a523"></a>        <a href="http://www.php.net/restore_error_handler">restore_error_handler</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a524"></a>&nbsp;</li>
<li><a name="a525"></a>        <span class="src-comm">// Call cgiapp_postrun() hook, first unlocking _POSTRUN_MODE_LOCKED</span></li>
<li><a name="a526"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_POSTRUN_MODE_LOCKED </span>= <span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a527"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-str">'postrun'</span><span class="src-sym">, </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">__body</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a528"></a>&nbsp;</li>
<li><a name="a529"></a>        <span class="src-comm">// Re-Lock _POSTRUN_MODE_LOCKED, now that postrun is done</span></li>
<li><a name="a530"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_POSTRUN_MODE_LOCKED </span>= <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a531"></a>&nbsp;</li>
<li><a name="a532"></a>        <span class="src-comm">// Send HTTP headers, if necessary</span></li>
<li><a name="a533"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#method_send_headers">_send_headers</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a534"></a>&nbsp;</li>
<li><a name="a535"></a>        <span class="src-comm">// Send output to browser (unless we're in serious debug mode!)</span></li>
<li><a name="a536"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CGIAPP_RETURN_ONLY</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a537"></a>            echo <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">__body</span><span class="src-sym">;</span></li>
<li><a name="a538"></a>        <span class="src-sym">}</span></li>
<li><a name="a539"></a>&nbsp;</li>
<li><a name="a540"></a>        <span class="src-comm">// clean up operations</span></li>
<li><a name="a541"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-str">'teardown'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a542"></a>&nbsp;</li>
<li><a name="a543"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">__body</span><span class="src-sym">;</span></li>
<li><a name="a544"></a>    <span class="src-sym">}</span></li>
<li><a name="a545"></a>&nbsp;</li>
<li><a name="a546"></a>&nbsp;</li>
<li><a name="a547"></a>    <span class="src-comm">// SUBCLASSABLE METHODS</span></li>
<li><a name="a548"></a>    <span class="src-comm">// These methods do nothing unless subclassed!</span></li>
<li><a name="a549"></a>&nbsp;</li>
<li><a name="a549"></a>    </li>
<li><a name="a550"></a>    <span class="src-doc">/**</span></li>
<li><a name="a551"></a><span class="src-doc">     * Perform application specific initialization behaviour</span></li>
<li><a name="a552"></a><span class="src-doc">     *</span></li>
<li><a name="a553"></a><span class="src-doc">     * cgiapp_init() is called during the</span></li>
<li><a name="a554"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link $_INSTALLED_CALLBACKS init hook}</span><span class="src-doc">, which is during object</span></li>
<li><a name="a555"></a><span class="src-doc">     * instantiation, and prior to calling of the </span><span class="src-doc-inlinetag">{@link setup()}</span><span class="src-doc"> method.</span></li>
<li><a name="a556"></a><span class="src-doc">     * </span></li>
<li><a name="a557"></a><span class="src-doc">     * When used, this method provides an optional initialization hook, which</span></li>
<li><a name="a558"></a><span class="src-doc">     * allows for customization of the class and all descendents.</span></li>
<li><a name="a559"></a><span class="src-doc">     *</span></li>
<li><a name="a560"></a><span class="src-doc">     * The first argument received is the array of arguments sent to the</span></li>
<li><a name="a561"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link __construct() constructor method}</span><span class="src-doc">.</span></li>
<li><a name="a562"></a><span class="src-doc">     *</span></li>
<li><a name="a563"></a><span class="src-doc">     * As a </span><span class="src-doc-inlinetag">{@link add_callback() callback hook}</span><span class="src-doc">, the second argument expected</span></li>
<li><a name="a564"></a><span class="src-doc">     * is an object instance; this may be safely ignored if implementing in a</span></li>
<li><a name="a565"></a><span class="src-doc">     * Cgiapp2-based class.</span></li>
<li><a name="a566"></a><span class="src-doc">     * </span></li>
<li><a name="a567"></a><span class="src-doc">     * An example of the benefits provided by utilizing this hook is creating a</span></li>
<li><a name="a568"></a><span class="src-doc">     * custom &quot;application super-class&quot; from which which all your applications</span></li>
<li><a name="a569"></a><span class="src-doc">     * would inherit, instead of Cgiapp2.</span></li>
<li><a name="a570"></a><span class="src-doc">     * </span></li>
<li><a name="a571"></a><span class="src-doc">     * Consider the following:</span></li>
<li><a name="a572"></a><span class="src-doc">     * </span></li>
<li><a name="a573"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a574"></a><span class="src-doc">     *   // In MySuperclass.php:</span></li>
<li><a name="a575"></a><span class="src-doc">     *   require_once 'Cgiapp2.class.php';</span></li>
<li><a name="a576"></a><span class="src-doc">     *   class MySuperclass extends Cgiapp2</span></li>
<li><a name="a577"></a><span class="src-doc">     *   {</span></li>
<li><a name="a578"></a><span class="src-doc">     *       function cgiapp_init($args, $cgiapp)</span></li>
<li><a name="a579"></a><span class="src-doc">     *       {</span></li>
<li><a name="a580"></a><span class="src-doc">     *         // Perform some project-specific init behavior</span></li>
<li><a name="a581"></a><span class="src-doc">     *         // such as to load settings from a database or file.</span></li>
<li><a name="a582"></a><span class="src-doc">     *       }</span></li>
<li><a name="a583"></a><span class="src-doc">     *   }</span></li>
<li><a name="a584"></a><span class="src-doc">     * </span></li>
<li><a name="a585"></a><span class="src-doc">     * </span></li>
<li><a name="a586"></a><span class="src-doc">     *   // In MyApplication.php:</span></li>
<li><a name="a587"></a><span class="src-doc">     *   class MyApplication extends MySuperclass</span></li>
<li><a name="a588"></a><span class="src-doc">     *   {</span></li>
<li><a name="a589"></a><span class="src-doc">     *       function setup { ... }</span></li>
<li><a name="a590"></a><span class="src-doc">     *       function teardown { ... }</span></li>
<li><a name="a591"></a><span class="src-doc">     *       // The rest of your Cgiapp2-based class follows...</span></li>
<li><a name="a592"></a><span class="src-doc">     *   }</span></li>
<li><a name="a593"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a594"></a><span class="src-doc">     * </span></li>
<li><a name="a595"></a><span class="src-doc">     * By using Cgiapp2 and the cgiapp_init() method as illustrated, a suite of</span></li>
<li><a name="a596"></a><span class="src-doc">     * applications could be designed to share certain characteristics, such as</span></li>
<li><a name="a597"></a><span class="src-doc">     * a database connection, template engine, etc.  This has the potential for</span></li>
<li><a name="a598"></a><span class="src-doc">     * much cleaner code built on object-oriented inheritance.</span></li>
<li><a name="a599"></a><span class="src-doc">     *</span></li>
<li><a name="a600"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a601"></a><span class="src-doc">     * For those upgrading from a pre-2.0.0 version of Cgiapp2, please note that</span></li>
<li><a name="a602"></a><span class="src-doc">     * this method now accepts a second argument, an object instance.</span></li>
<li><a name="a603"></a><span class="src-doc">     *</span></li>
<li><a name="a604"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$args </span><span class="src-doc">Uses $args sent to constructor</span></li>
<li><a name="a605"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">object </span><span class="src-doc-var">$cgiapp </span><span class="src-doc">Observed Cgiapp2-based object</span></li>
<li><a name="a606"></a><span class="src-doc">     */</span></li>
<li><a name="a607"></a>    <span class="src-key">protected </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodcgiapp_init">cgiapp_init</a><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">, </span><span class="src-var">$cgiapp</span><span class="src-sym">)</span></li>
<li><a name="a608"></a>    <span class="src-sym">{</span></li>
<li><a name="a609"></a>        <span class="src-comm">// Must be overridden</span></li>
<li><a name="a610"></a>    <span class="src-sym">}</span></li>
<li><a name="a611"></a>&nbsp;</li>
<li><a name="a612"></a>    <span class="src-doc">/**</span></li>
<li><a name="a613"></a><span class="src-doc">     * Perform operations before selected run mode is executed</span></li>
<li><a name="a614"></a><span class="src-doc">     * </span></li>
<li><a name="a615"></a><span class="src-doc">     * cgiapp_prerun() implements the </span><span class="src-doc-inlinetag">{@link $_INSTALLED_CALLBACKS prerun hook}</span></li>
<li><a name="a616"></a><span class="src-doc">     * of the callback system. If utilized, the hook is called automatically</span></li>
<li><a name="a617"></a><span class="src-doc">     * right before the selected run mode method is called.</span></li>
<li><a name="a618"></a><span class="src-doc">     *</span></li>
<li><a name="a619"></a><span class="src-doc">     * The first argument passed is the name of the requested run mode.</span></li>
<li><a name="a620"></a><span class="src-doc">     *   </span></li>
<li><a name="a621"></a><span class="src-doc">     * Since this is a </span><span class="src-doc-inlinetag">{@link add_callback()}</span><span class="src-doc"> callback hook, the second argument</span></li>
<li><a name="a622"></a><span class="src-doc">     * is an object instance; if implementing in a Cgiapp2-based class, you can</span></li>
<li><a name="a623"></a><span class="src-doc">     * typically ignore this value.</span></li>
<li><a name="a624"></a><span class="src-doc">     *</span></li>
<li><a name="a625"></a><span class="src-doc">     * Use this hook and the run mode argument to provide functionality prior to</span></li>
<li><a name="a626"></a><span class="src-doc">     * the requested run mode method being called.  Uses include checking ACLs</span></li>
<li><a name="a627"></a><span class="src-doc">     * for permissions to the requested run mode. You may call</span></li>
<li><a name="a628"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link prerun_mode()}</span><span class="src-doc"> from this method to then change the requested run</span></li>
<li><a name="a629"></a><span class="src-doc">     * mode.</span></li>
<li><a name="a630"></a><span class="src-doc">     *</span></li>
<li><a name="a631"></a><span class="src-doc">     * Another benefit provided by utilizing this hook is creating a custom</span></li>
<li><a name="a632"></a><span class="src-doc">     * &quot;application super-class&quot; from which all your CGI applications would</span></li>
<li><a name="a633"></a><span class="src-doc">     * inherit, instead of Cgiapp2.</span></li>
<li><a name="a634"></a><span class="src-doc">     * </span></li>
<li><a name="a635"></a><span class="src-doc">     * Consider the following:</span></li>
<li><a name="a636"></a><span class="src-doc">     * </span></li>
<li><a name="a637"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a638"></a><span class="src-doc">     *   // In MySuperclass.php:</span></li>
<li><a name="a639"></a><span class="src-doc">     *   class MySuperclass extends Cgiapp2 {</span></li>
<li><a name="a640"></a><span class="src-doc">     *       function cgiapp_prerun($rm, $cgiapp) {</span></li>
<li><a name="a641"></a><span class="src-doc">     *         // Perform some project-specific init behavior</span></li>
<li><a name="a642"></a><span class="src-doc">     *         // such as to implement run mode specific</span></li>
<li><a name="a643"></a><span class="src-doc">     *         // authorization functions.</span></li>
<li><a name="a644"></a><span class="src-doc">     *       }</span></li>
<li><a name="a645"></a><span class="src-doc">     *   }</span></li>
<li><a name="a646"></a><span class="src-doc">     * </span></li>
<li><a name="a647"></a><span class="src-doc">     * </span></li>
<li><a name="a648"></a><span class="src-doc">     *   // In MyApplication.php:</span></li>
<li><a name="a649"></a><span class="src-doc">     *   class MyApplication extends MySuperclass {</span></li>
<li><a name="a650"></a><span class="src-doc">     *       function setup()</span></li>
<li><a name="a651"></a><span class="src-doc">     *       {</span></li>
<li><a name="a652"></a><span class="src-doc">     *           ...</span></li>
<li><a name="a653"></a><span class="src-doc">     *       }</span></li>
<li><a name="a654"></a><span class="src-doc">     *       function teardown()</span></li>
<li><a name="a655"></a><span class="src-doc">     *       {</span></li>
<li><a name="a656"></a><span class="src-doc">     *           ...</span></li>
<li><a name="a657"></a><span class="src-doc">     *       }</span></li>
<li><a name="a658"></a><span class="src-doc">     *       // The rest of your Cgiapp2-based class follows...</span></li>
<li><a name="a659"></a><span class="src-doc">     *   }</span></li>
<li><a name="a660"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a661"></a><span class="src-doc">     * </span></li>
<li><a name="a662"></a><span class="src-doc">     * By using Cgiapp2 and the cgiapp_prerun() method as illustrated,</span></li>
<li><a name="a663"></a><span class="src-doc">     * a suite of applications could be designed to share certain</span></li>
<li><a name="a664"></a><span class="src-doc">     * characteristics, such as a common authorization scheme.</span></li>
<li><a name="a665"></a><span class="src-doc">     * </span></li>
<li><a name="a666"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a667"></a><span class="src-doc">     * For those upgrading from a pre-2.0.0 version of Cgiapp2, please note that</span></li>
<li><a name="a668"></a><span class="src-doc">     * this method now accepts a second argument, an object instance.</span></li>
<li><a name="a669"></a><span class="src-doc">     *</span></li>
<li><a name="a670"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$rm </span><span class="src-doc">Current selected run mode</span></li>
<li><a name="a671"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">object </span><span class="src-doc-var">$cgiapp </span><span class="src-doc">Observed Cgiapp2-based object</span></li>
<li><a name="a672"></a><span class="src-doc">     */</span></li>
<li><a name="a673"></a>    <span class="src-key">protected </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodcgiapp_prerun">cgiapp_prerun</a><span class="src-sym">(</span><span class="src-var">$rm</span><span class="src-sym">, </span><span class="src-var">$cgiapp</span><span class="src-sym">)</span></li>
<li><a name="a674"></a>    <span class="src-sym">{</span></li>
<li><a name="a675"></a>        <span class="src-comm">// Must be overridden</span></li>
<li><a name="a676"></a>    <span class="src-sym">}</span></li>
<li><a name="a677"></a>&nbsp;</li>
<li><a name="a678"></a>&nbsp;</li>
<li><a name="a679"></a>    <span class="src-doc">/**</span></li>
<li><a name="a680"></a><span class="src-doc">     * Execute code following execution of the current run mode method</span></li>
<li><a name="a681"></a><span class="src-doc">     * </span></li>
<li><a name="a682"></a><span class="src-doc">     * cgiapp_postrun() implements the</span></li>
<li><a name="a683"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link $_INSTALLED_CALLBACKS postrun hook}</span><span class="src-doc"> of the callback system.</span></li>
<li><a name="a684"></a><span class="src-doc">     * If implemented, the hook is called after the run mode method has returned</span></li>
<li><a name="a685"></a><span class="src-doc">     * its output, but before HTTP headers are generated or content presented.</span></li>
<li><a name="a686"></a><span class="src-doc">     * This will give you an opportunity to modify the content and headers</span></li>
<li><a name="a687"></a><span class="src-doc">     * before they are returned to the web browser.</span></li>
<li><a name="a688"></a><span class="src-doc">     * </span></li>
<li><a name="a689"></a><span class="src-doc">     * A typical use for this hook is piping the output of a run mode through a</span></li>
<li><a name="a690"></a><span class="src-doc">     * series of &quot;filter&quot; processors.  For example:</span></li>
<li><a name="a691"></a><span class="src-doc">     *</span></li>
<li><a name="a692"></a><span class="src-doc">     * &lt;ul&gt;</span></li>
<li><a name="a693"></a><span class="src-doc">     *     &lt;li&gt;You want to enclose the output of all your run modes within a</span></li>
<li><a name="a694"></a><span class="src-doc">     *         larger, site-wide template.&lt;/li&gt;</span></li>
<li><a name="a695"></a><span class="src-doc">     *     &lt;li&gt;Your run modes return structured data (such as XML), which you</span></li>
<li><a name="a696"></a><span class="src-doc">     *         want to transform using a standard mechanism (such as XSLT).&lt;/li&gt;</span></li>
<li><a name="a697"></a><span class="src-doc">     *     &lt;li&gt;You want to modify HTTP headers in a particular way across all</span></li>
<li><a name="a698"></a><span class="src-doc">     *         run modes, based on particular criteria.&lt;/li&gt;</span></li>
<li><a name="a699"></a><span class="src-doc">     * &lt;/ul&gt;</span></li>
<li><a name="a700"></a><span class="src-doc">     *</span></li>
<li><a name="a701"></a><span class="src-doc">     * The first argument received is the current generated body content.</span></li>
<li><a name="a702"></a><span class="src-doc">     *</span></li>
<li><a name="a703"></a><span class="src-doc">     * Since this is a </span><span class="src-doc-inlinetag">{@link add_callback()}</span><span class="src-doc"> callback hook, the second argument</span></li>
<li><a name="a704"></a><span class="src-doc">     * is an object instance; if implementing in a Cgiapp2-based class, you can</span></li>
<li><a name="a705"></a><span class="src-doc">     * typically ignore this value.</span></li>
<li><a name="a706"></a><span class="src-doc">     *</span></li>
<li><a name="a707"></a><span class="src-doc">     * A potential cgiapp_postrun() method might be implemented as follows:</span></li>
<li><a name="a708"></a><span class="src-doc">     * </span></li>
<li><a name="a709"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a710"></a><span class="src-doc">     *     function cgiapp_postrun($body, $cgiapp)</span></li>
<li><a name="a711"></a><span class="src-doc">     *     {</span></li>
<li><a name="a712"></a><span class="src-doc">     *         // Enclose output HTML table</span></li>
<li><a name="a713"></a><span class="src-doc">     *         $new_output  = &quot;&lt;table border=1&gt;&quot;;</span></li>
<li><a name="a714"></a><span class="src-doc">     *         $new_output .= &quot;&lt;tr&gt;&lt;td&gt; Hello, World! &lt;/td&gt;&lt;/tr&gt;&quot;;</span></li>
<li><a name="a715"></a><span class="src-doc">     *         $new_output .= &quot;&lt;tr&gt;&lt;td&gt;&quot;. $body .&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;</span></li>
<li><a name="a716"></a><span class="src-doc">     *         $new_output .= &quot;&lt;/table&gt;&quot;;</span></li>
<li><a name="a717"></a><span class="src-doc">     *   </span></li>
<li><a name="a718"></a><span class="src-doc">     *         # Replace old output with new output</span></li>
<li><a name="a719"></a><span class="src-doc">     *         $cgiapp-&gt;postrun_body($body);</span></li>
<li><a name="a720"></a><span class="src-doc">     *     }</span></li>
<li><a name="a721"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a722"></a><span class="src-doc">     *</span></li>
<li><a name="a723"></a><span class="src-doc">     * &lt;b&gt;NOTE:&lt;/b&gt; </span><span class="src-doc-inlinetag">{@link run()}</span><span class="src-doc"> passes the output from your run mode to</span></li>
<li><a name="a724"></a><span class="src-doc">     * cgiapp_postrun(), but does not expect anything to return from the method</span></li>
<li><a name="a725"></a><span class="src-doc">     * (in point of fact, it does nothing with the method's return value).</span></li>
<li><a name="a726"></a><span class="src-doc">     * If you plan on modifying that content or replacing it, call</span></li>
<li><a name="a727"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link postrun_body()}</span><span class="src-doc"> with the new or modified content, as shown in the</span></li>
<li><a name="a728"></a><span class="src-doc">     * example above.</span></li>
<li><a name="a729"></a><span class="src-doc">     * </span></li>
<li><a name="a730"></a><span class="src-doc">     * Obviously, with access to the Cgiapp2 object you have full access to use</span></li>
<li><a name="a731"></a><span class="src-doc">     * all the methods normally available in a run mode.  You could, for</span></li>
<li><a name="a732"></a><span class="src-doc">     * example, use </span><span class="src-doc-inlinetag">{@link load_tmpl()}</span><span class="src-doc"> to replace the static HTML in this</span></li>
<li><a name="a733"></a><span class="src-doc">     * example with content from a template (assigning $body to the template).</span></li>
<li><a name="a734"></a><span class="src-doc">     * You could change the HTTP headers (via </span><span class="src-doc-inlinetag">{@link header_type()}</span><span class="src-doc"> and</span></li>
<li><a name="a735"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link header_props()}</span><span class="src-doc"> methods) to set up a redirect.  You could also</span></li>
<li><a name="a736"></a><span class="src-doc">     * use the objects properties to apply changes only under certain</span></li>
<li><a name="a737"></a><span class="src-doc">     * circumstance, such as a in only certain run modes, and when a</span></li>
<li><a name="a738"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link param()}</span><span class="src-doc"> is a particular value.</span></li>
<li><a name="a739"></a><span class="src-doc">     *</span></li>
<li><a name="a740"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a741"></a><span class="src-doc">     * For those upgrading from a pre-2.0.0 version of Cgiapp2, please note that</span></li>
<li><a name="a742"></a><span class="src-doc">     * this method now accepts a second argument, an object instance. Also note</span></li>
<li><a name="a743"></a><span class="src-doc">     * that $body is no longer passed by reference, and that to update or change</span></li>
<li><a name="a744"></a><span class="src-doc">     * the generated $body, you must use </span><span class="src-doc-inlinetag">{@link postrun_body()}</span><span class="src-doc">.</span></li>
<li><a name="a745"></a><span class="src-doc">     *</span></li>
<li><a name="a746"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$body </span><span class="src-doc">Content returned by the run mode</span></li>
<li><a name="a747"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">object </span><span class="src-doc-var">$cgiapp </span><span class="src-doc">Observed Cgiapp2-based object</span></li>
<li><a name="a748"></a><span class="src-doc">     */</span></li>
<li><a name="a749"></a>    <span class="src-key">protected </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodcgiapp_postrun">cgiapp_postrun</a><span class="src-sym">(</span><span class="src-var">$body</span><span class="src-sym">, </span><span class="src-var">$cgiapp</span><span class="src-sym">)</span></li>
<li><a name="a750"></a>    <span class="src-sym">{</span></li>
<li><a name="a751"></a>        <span class="src-comm">// Must override</span></li>
<li><a name="a752"></a>    <span class="src-sym">}</span></li>
<li><a name="a753"></a>&nbsp;</li>
<li><a name="a754"></a>&nbsp;</li>
<li><a name="a755"></a>    <span class="src-doc">/**</span></li>
<li><a name="a756"></a><span class="src-doc">     * Setup the application's environment</span></li>
<li><a name="a757"></a><span class="src-doc">     * </span></li>
<li><a name="a758"></a><span class="src-doc">     * This method is called by the inherited constructor method.  The setup()</span></li>
<li><a name="a759"></a><span class="src-doc">     * method should be used to define the following property/methods:</span></li>
<li><a name="a760"></a><span class="src-doc">     * &lt;ul&gt;</span></li>
<li><a name="a761"></a><span class="src-doc">     *     &lt;li&gt;</span><span class="src-doc-inlinetag">{@link mode_param()}</span><span class="src-doc"> - set the name of the run mode CGI</span></li>
<li><a name="a762"></a><span class="src-doc">     *         param.&lt;/li&gt;</span></li>
<li><a name="a763"></a><span class="src-doc">     *     &lt;li&gt;</span><span class="src-doc-inlinetag">{@link start_mode()}</span><span class="src-doc"> - text scalar containing the default run</span></li>
<li><a name="a764"></a><span class="src-doc">     *         mode.&lt;/li&gt;</span></li>
<li><a name="a765"></a><span class="src-doc">     *     &lt;li&gt;</span><span class="src-doc-inlinetag">{@link run_modes()}</span><span class="src-doc"> - hash table containing mode =&gt; function</span></li>
<li><a name="a766"></a><span class="src-doc">     *         mappings.&lt;/li&gt;</span></li>
<li><a name="a767"></a><span class="src-doc">     *     &lt;li&gt;</span><span class="src-doc-inlinetag">{@link tmpl_path()}</span><span class="src-doc"> - text scalar containing path to template</span></li>
<li><a name="a768"></a><span class="src-doc">     *         files.&lt;/li&gt;</span></li>
<li><a name="a769"></a><span class="src-doc">     * &lt;/ul&gt;</span></li>
<li><a name="a770"></a><span class="src-doc">     * Your setup() method may call any of the instance methods of your</span></li>
<li><a name="a771"></a><span class="src-doc">     * application.  This function is a good place to define properties specific</span></li>
<li><a name="a772"></a><span class="src-doc">     * to your application via the </span><span class="src-doc-inlinetag">{@link param()}</span><span class="src-doc"> method.</span></li>
<li><a name="a773"></a><span class="src-doc">     * </span></li>
<li><a name="a774"></a><span class="src-doc">     * Your setup() method might be implemented something like this:</span></li>
<li><a name="a775"></a><span class="src-doc">     * </span></li>
<li><a name="a776"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a777"></a><span class="src-doc">     *     function setup()</span></li>
<li><a name="a778"></a><span class="src-doc">     *     {</span></li>
<li><a name="a779"></a><span class="src-doc">     *         $this-&gt;tmpl_path('/path/to/my/templates/');</span></li>
<li><a name="a780"></a><span class="src-doc">     *         $this-&gt;start_mode('putform');</span></li>
<li><a name="a781"></a><span class="src-doc">     *         $this-&gt;run_modes(array(</span></li>
<li><a name="a782"></a><span class="src-doc">     *             'putform'  =&gt; 'my_putform_func',</span></li>
<li><a name="a783"></a><span class="src-doc">     *             'postdata' =&gt; 'my_data_func'</span></li>
<li><a name="a784"></a><span class="src-doc">     *         ));</span></li>
<li><a name="a785"></a><span class="src-doc">     *         $this-&gt;param('myprop1');</span></li>
<li><a name="a786"></a><span class="src-doc">     *         $this-&gt;param('myprop2', 'prop2value');</span></li>
<li><a name="a787"></a><span class="src-doc">     *         $this-&gt;param('myprop3', array('p3v1', 'p3v2', 'p3v3'));</span></li>
<li><a name="a788"></a><span class="src-doc">     *     }</span></li>
<li><a name="a789"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a790"></a><span class="src-doc">     *</span></li>
<li><a name="a791"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@abstract</span></li>
<li><a name="a792"></a><span class="src-doc">     */</span></li>
<li><a name="a793"></a>    <span class="src-key">abstract </span><span class="src-key">protected </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodsetup">setup</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a794"></a>&nbsp;</li>
<li><a name="a795"></a>&nbsp;</li>
<li><a name="a796"></a>    <span class="src-doc">/**</span></li>
<li><a name="a797"></a><span class="src-doc">     * Perform cleanup after running the application</span></li>
<li><a name="a798"></a><span class="src-doc">     * </span></li>
<li><a name="a799"></a><span class="src-doc">     * teardown() implements the </span><span class="src-doc-inlinetag">{@link $_INSTALLED_CALLBACKS teardown hook}</span><span class="src-doc"> of</span></li>
<li><a name="a800"></a><span class="src-doc">     * the callback system, which is called automatically after your application</span></li>
<li><a name="a801"></a><span class="src-doc">     * runs; it can be used to clean up after your operations.</span></li>
<li><a name="a802"></a><span class="src-doc">     *</span></li>
<li><a name="a803"></a><span class="src-doc">     * A typical use of the teardown() method is to disconnect a database</span></li>
<li><a name="a804"></a><span class="src-doc">     * connection which was established in the </span><span class="src-doc-inlinetag">{@link setup()}</span><span class="src-doc"> function (or init</span></li>
<li><a name="a805"></a><span class="src-doc">     * hook).  You could also use the teardown() method to store state</span></li>
<li><a name="a806"></a><span class="src-doc">     * information about the application to the server.</span></li>
<li><a name="a807"></a><span class="src-doc">     *</span></li>
<li><a name="a808"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a809"></a><span class="src-doc">     * For those upgrading from a pre-2.0.0 version of Cgiapp2, please note that</span></li>
<li><a name="a810"></a><span class="src-doc">     * this method now accepts an argument, an object instance.</span></li>
<li><a name="a811"></a><span class="src-doc">     *</span></li>
<li><a name="a812"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">object </span><span class="src-doc-var">$cgiapp </span><span class="src-doc">Observed Cgiapp2-based object</span></li>
<li><a name="a813"></a><span class="src-doc">     */</span></li>
<li><a name="a814"></a>    <span class="src-key">protected </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodteardown">teardown</a><span class="src-sym">(</span><span class="src-var">$cgiapp</span><span class="src-sym">) </span></li>
<li><a name="a815"></a>    <span class="src-sym">{</span></li>
<li><a name="a816"></a>        <span class="src-comm">// Must be overridden</span></li>
<li><a name="a817"></a>    <span class="src-sym">}</span></li>
<li><a name="a818"></a>&nbsp;</li>
<li><a name="a819"></a>    <span class="src-comm">// CALLBACK METHODS</span></li>
<li><a name="a820"></a>&nbsp;</li>
<li><a name="a820"></a>    </li>
<li><a name="a821"></a>    <span class="src-doc">/**</span></li>
<li><a name="a822"></a><span class="src-doc">     * Register a callback for a class instance</span></li>
<li><a name="a823"></a><span class="src-doc">     *</span></li>
<li><a name="a824"></a><span class="src-doc">     * The add_callback() method allows you to register a callback function that</span></li>
<li><a name="a825"></a><span class="src-doc">     * is to be called at the given stage of execution.  Valid hooks include</span></li>
<li><a name="a826"></a><span class="src-doc">     * 'init', 'prerun', 'postrun' and 'teardown', 'tmpl_path', 'tmpl_fetch',</span></li>
<li><a name="a827"></a><span class="src-doc">     * and any other hooks defined using the </span><span class="src-doc-inlinetag">{@link new_hook()}</span><span class="src-doc"> method.</span></li>
<li><a name="a828"></a><span class="src-doc">     * </span></li>
<li><a name="a829"></a><span class="src-doc">     * The callback should be a valid PHP callback; see</span></li>
<li><a name="a830"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link http://php.net/callback PHP callback documentation}</span><span class="src-doc"> for more</span></li>
<li><a name="a831"></a><span class="src-doc">     * information.</span></li>
<li><a name="a832"></a><span class="src-doc">     * </span></li>
<li><a name="a833"></a><span class="src-doc">     * If multiple callbacks are added to the same hook, they will all be</span></li>
<li><a name="a834"></a><span class="src-doc">     * executed one after the other.  The exact order depends on which class</span></li>
<li><a name="a835"></a><span class="src-doc">     * installed each callback, and the order in which they were registered.</span></li>
<li><a name="a836"></a><span class="src-doc">     *</span></li>
<li><a name="a837"></a><span class="src-doc">     * If no $class is specified, and an object callback is specified, and the</span></li>
<li><a name="a838"></a><span class="src-doc">     * object is a Cgiapp2-derived class, that object's class will be used.</span></li>
<li><a name="a839"></a><span class="src-doc">     *</span></li>
<li><a name="a840"></a><span class="src-doc">     * Callbacks are executed first for the current class, then the parent</span></li>
<li><a name="a841"></a><span class="src-doc">     * class, and on up the class hierarchy. Additionally, if multiple callbacks</span></li>
<li><a name="a842"></a><span class="src-doc">     * are registered for a given class, then they are executed in the order in</span></li>
<li><a name="a843"></a><span class="src-doc">     * which they are registered.</span></li>
<li><a name="a844"></a><span class="src-doc">     * </span></li>
<li><a name="a845"></a><span class="src-doc">     * Callbacks are stored in the </span><span class="src-doc-inlinetag">{@link $_INSTALLED_CALLBACKS}</span><span class="src-doc"> static</span></li>
<li><a name="a846"></a><span class="src-doc">     * property.  $_INSTALLED_CALLBACKS is a multi-dimensional array with the</span></li>
<li><a name="a847"></a><span class="src-doc">     * first key being the hook, and the second the classname; callbacks are</span></li>
<li><a name="a848"></a><span class="src-doc">     * stored under $_INSTALLED_CALLBACKS[$hook][$classname].</span></li>
<li><a name="a849"></a><span class="src-doc">     *</span></li>
<li><a name="a850"></a><span class="src-doc">     * Class-based callbacks are useful for plugins to add features to all web</span></li>
<li><a name="a851"></a><span class="src-doc">     * applications.</span></li>
<li><a name="a852"></a><span class="src-doc">     * </span></li>
<li><a name="a853"></a><span class="src-doc">     * Another feature of class-based callbacks is that your plugin can create</span></li>
<li><a name="a854"></a><span class="src-doc">     * hooks and add callbacks at any time - even before the web application's</span></li>
<li><a name="a855"></a><span class="src-doc">     * object has been initialized. You could do this in your class definition</span></li>
<li><a name="a856"></a><span class="src-doc">     * file:</span></li>
<li><a name="a857"></a><span class="src-doc">     * </span></li>
<li><a name="a858"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a859"></a><span class="src-doc">     * class Cgiapp2_Plugin_MyPlugin</span></li>
<li><a name="a860"></a><span class="src-doc">     * {</span></li>
<li><a name="a861"></a><span class="src-doc">     *     function my_setup($cgiapp)</span></li>
<li><a name="a862"></a><span class="src-doc">     *     {</span></li>
<li><a name="a863"></a><span class="src-doc">     *         // do some stuff...</span></li>
<li><a name="a864"></a><span class="src-doc">     *     }</span></li>
<li><a name="a865"></a><span class="src-doc">     * }</span></li>
<li><a name="a866"></a><span class="src-doc">     * Cgiapp2::add_callback('init', array('Cgiapp2_Plugin_MyPlugin', 'my_setup'));</span></li>
<li><a name="a867"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a868"></a><span class="src-doc">     *</span></li>
<li><a name="a869"></a><span class="src-doc">     * The above code would register a global plugin that would execute in the</span></li>
<li><a name="a870"></a><span class="src-doc">     * cgiapp_init() method.</span></li>
<li><a name="a871"></a><span class="src-doc">     *</span></li>
<li><a name="a872"></a><span class="src-doc">     * NOTE: Due to the nature of templating, the various tmpl_* hooks are setup</span></li>
<li><a name="a873"></a><span class="src-doc">     * so that they &lt;b&gt;always&lt;/b&gt; register with the Cgiapp2 class, and such that</span></li>
<li><a name="a874"></a><span class="src-doc">     * only one callback is allowed per template hook; the last callback to</span></li>
<li><a name="a875"></a><span class="src-doc">     * register will be the callback used.</span></li>
<li><a name="a876"></a><span class="src-doc">     *</span></li>
<li><a name="a877"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a878"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a879"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$hook </span></li>
<li><a name="a880"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string</span><span class="src-doc">|</span><span class="src-doc-type">array</span><span class="src-doc-var">$callback </span></li>
<li><a name="a881"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string</span><span class="src-doc">|</span><span class="src-doc-type">object</span><span class="src-doc">|</span><span class="src-doc-type">null</span><span class="src-doc-var">$class </span></li>
<li><a name="a882"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">boolean </span></li>
<li><a name="a883"></a><span class="src-doc">     */</span></li>
<li><a name="a884"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodadd_callback">add_callback</a><span class="src-sym">(</span><span class="src-var">$hook</span><span class="src-sym">, </span><span class="src-var">$callback</span><span class="src-sym">, </span><span class="src-var">$class </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a885"></a>    <span class="src-sym">{</span></li>
<li><a name="a886"></a>        <span class="src-var">$hook </span>= <a href="http://www.php.net/strtolower">strtolower</a><span class="src-sym">(</span><span class="src-var">$hook</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a887"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a888"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-id">Unknown</span> <span class="src-id">hook</span> (<span class="src-var">$hook</span>)</span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a889"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a890"></a>        <span class="src-sym">}</span></li>
<li><a name="a891"></a>&nbsp;</li>
<li><a name="a892"></a>        <span class="src-comm">// Check for valid callback</span></li>
<li><a name="a893"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_callable">is_callable</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a894"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">&quot;Invalid callback&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a895"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a896"></a>        <span class="src-sym">}</span></li>
<li><a name="a897"></a>&nbsp;</li>
<li><a name="a898"></a>        <span class="src-comm">// If callback is object callback and a Cgiapp2-based class, use that for</span></li>
<li><a name="a899"></a>        <span class="src-comm">// the class</span></li>
<li><a name="a900"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">) </span></li>
<li><a name="a901"></a>            &amp;&amp; <a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">) </span></li>
<li><a name="a902"></a>            &amp;&amp; <a href="http://www.php.net/is_object">is_object</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span></li>
<li><a name="a903"></a>            &amp;&amp; <a href="http://www.php.net/is_subclass_of">is_subclass_of</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">, </span><span class="src-str">'Cgiapp2'</span><span class="src-sym">)) </span></li>
<li><a name="a904"></a>        <span class="src-sym">{</span></li>
<li><a name="a905"></a>            <span class="src-var">$class </span>= <a href="http://www.php.net/get_class">get_class</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a906"></a>        <span class="src-sym">}</span></li>
<li><a name="a907"></a>&nbsp;</li>
<li><a name="a908"></a>        <span class="src-comm">// Get class name for registering hook</span></li>
<li><a name="a909"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">) </span>&amp;&amp; <a href="http://www.php.net/is_object">is_object</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a910"></a>            <span class="src-var">$className </span>= <a href="http://www.php.net/get_class">get_class</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a911"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a912"></a>            <span class="src-var">$className </span>= <span class="src-var">$class</span><span class="src-sym">;</span></li>
<li><a name="a913"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">) </span>&amp;&amp; <a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a914"></a>            <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a915"></a>                <span class="src-var">$className </span>= <span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a916"></a>            <span class="src-sym">}</span></li>
<li><a name="a917"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a918"></a>            <span class="src-var">$className </span>= <span class="src-str">'Cgiapp2'</span><span class="src-sym">;</span></li>
<li><a name="a919"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a920"></a>            <span class="src-comm">// Bad class name provided; return false</span></li>
<li><a name="a921"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a922"></a>        <span class="src-sym">}</span></li>
<li><a name="a923"></a>&nbsp;</li>
<li><a name="a924"></a>        <span class="src-comm">// Initialize hook/class callback array</span></li>
<li><a name="a925"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$className</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a926"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$className</span><span class="src-sym">] </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a927"></a>        <span class="src-sym">}</span></li>
<li><a name="a928"></a>&nbsp;</li>
<li><a name="a929"></a>        <span class="src-comm">// Register callback</span></li>
<li><a name="a930"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">in_array</span><span class="src-sym">(</span><span class="src-var">$hook</span><span class="src-sym">, </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_TMPL_HOOKS</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a931"></a>            <span class="src-comm">// Template hooks are always registered at the Cgiapp2 level, and</span></li>
<li><a name="a932"></a>            <span class="src-comm">// only one callback for a hook type can be registered at a time.</span></li>
<li><a name="a933"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'Cgiapp2'</span><span class="src-sym">] </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a934"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a935"></a>            <span class="src-comm">// All other hooks can be registered anywhere along the class</span></li>
<li><a name="a936"></a>            <span class="src-comm">// inheritance chain</span></li>
<li><a name="a937"></a>            <span class="src-id">array_push</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$className</span><span class="src-sym">]</span><span class="src-sym">, </span><span class="src-var">$callback</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a938"></a>        <span class="src-sym">}</span></li>
<li><a name="a939"></a>&nbsp;</li>
<li><a name="a940"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a941"></a>    <span class="src-sym">}</span></li>
<li><a name="a942"></a>&nbsp;</li>
<li><a name="a943"></a>    <span class="src-doc">/**</span></li>
<li><a name="a944"></a><span class="src-doc">     * Create a new hook location in which to register callbacks</span></li>
<li><a name="a945"></a><span class="src-doc">     *</span></li>
<li><a name="a946"></a><span class="src-doc">     * Allows developers to create a new location to register callbacks. Takes</span></li>
<li><a name="a947"></a><span class="src-doc">     * up to two arguments, a hook name, and a class name or object. If no class</span></li>
<li><a name="a948"></a><span class="src-doc">     * name or object is specified, the hook is registered with the global</span></li>
<li><a name="a949"></a><span class="src-doc">     * Cgiapp2 class.</span></li>
<li><a name="a950"></a><span class="src-doc">     *</span></li>
<li><a name="a951"></a><span class="src-doc">     * See </span><span class="src-doc-inlinetag">{@link call_hook()}</span><span class="src-doc"> for information on how hooks are called.</span></li>
<li><a name="a952"></a><span class="src-doc">     *</span></li>
<li><a name="a953"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a954"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$hook </span></li>
<li><a name="a955"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string</span><span class="src-doc">|</span><span class="src-doc-type">object</span><span class="src-doc">|</span><span class="src-doc-type">null</span><span class="src-doc-var">$class </span></li>
<li><a name="a956"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">boolean </span></li>
<li><a name="a957"></a><span class="src-doc">     */</span></li>
<li><a name="a958"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodnew_hook">new_hook</a><span class="src-sym">(</span><span class="src-var">$hook</span><span class="src-sym">, </span><span class="src-var">$class </span>= <span class="src-id">null</span><span class="src-sym">)</span></li>
<li><a name="a959"></a>    <span class="src-sym">{</span></li>
<li><a name="a960"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$hook</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a961"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a962"></a>        <span class="src-sym">}</span></li>
<li><a name="a963"></a>&nbsp;</li>
<li><a name="a964"></a>        <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a965"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$class</span><span class="src-sym">] </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a966"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a967"></a>            <span class="src-var">$className </span>= <a href="http://www.php.net/get_class">get_class</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a968"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$className</span><span class="src-sym">] </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a969"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a970"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'Cgiapp2'</span><span class="src-sym">] </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a971"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a972"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a973"></a>        <span class="src-sym">}</span></li>
<li><a name="a974"></a>&nbsp;</li>
<li><a name="a975"></a>        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_HOOK_ARG_PLACEMENT</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">] </span>= <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a976"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a977"></a>    <span class="src-sym">}</span></li>
<li><a name="a978"></a>&nbsp;</li>
<li><a name="a979"></a>    <span class="src-doc">/**</span></li>
<li><a name="a980"></a><span class="src-doc">     * Call (execute) a hook</span></li>
<li><a name="a981"></a><span class="src-doc">     *</span></li>
<li><a name="a982"></a><span class="src-doc">     * Executes a callback registered at the given hook. The first argument is</span></li>
<li><a name="a983"></a><span class="src-doc">     * the hook name. All remaining arguments are passed to the callback at that</span></li>
<li><a name="a984"></a><span class="src-doc">     * hook location.</span></li>
<li><a name="a985"></a><span class="src-doc">     *</span></li>
<li><a name="a986"></a><span class="src-doc">     * The first argument passed to the hook will always be the current object.</span></li>
<li><a name="a987"></a><span class="src-doc">     * Thus, your callback should, at the very least, accept a single argument:</span></li>
<li><a name="a988"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a989"></a><span class="src-doc">     *     function myHookCallback($cgiapp)</span></li>
<li><a name="a990"></a><span class="src-doc">     *     {</span></li>
<li><a name="a991"></a><span class="src-doc">     *     }</span></li>
<li><a name="a992"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a993"></a><span class="src-doc">     *</span></li>
<li><a name="a994"></a><span class="src-doc">     * Some hooks may accept additional arguments (e.g., </span><span class="src-doc-inlinetag">{@link cgiapp_init()}</span><span class="src-doc">,</span></li>
<li><a name="a995"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link cgiapp_prerun()}</span><span class="src-doc">, and </span><span class="src-doc-inlinetag">{@link cgiapp_postrun()}</span><span class="src-doc">); this will be</span></li>
<li><a name="a996"></a><span class="src-doc">     * determined by how the hook is called.</span></li>
<li><a name="a997"></a><span class="src-doc">     *</span></li>
<li><a name="a998"></a><span class="src-doc">     * Make sure that the callback is executable (i.e., the visibility allows</span></li>
<li><a name="a999"></a><span class="src-doc">     * call_hook() to call it).</span></li>
<li><a name="a1000"></a><span class="src-doc">     *</span></li>
<li><a name="a1001"></a><span class="src-doc">     * Looks in the current class, and then up the class hierarchy for any hooks</span></li>
<li><a name="a1002"></a><span class="src-doc">     * registered, giving those further up the last call.</span></li>
<li><a name="a1003"></a><span class="src-doc">     *</span></li>
<li><a name="a1004"></a><span class="src-doc">     * If more than one hook is executed or has a return value, than all return</span></li>
<li><a name="a1005"></a><span class="src-doc">     * values will be returned as an array. Otherwise, call_hook() returns a</span></li>
<li><a name="a1006"></a><span class="src-doc">     * single value as designated by the callback. You may want to pass</span></li>
<li><a name="a1007"></a><span class="src-doc">     * references as arguments to your callbacks if you want them to cascade</span></li>
<li><a name="a1008"></a><span class="src-doc">     * values.</span></li>
<li><a name="a1009"></a><span class="src-doc">     *</span></li>
<li><a name="a1010"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a1011"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$hook </span></li>
<li><a name="a1012"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">mixed </span></li>
<li><a name="a1013"></a><span class="src-doc">     */</span></li>
<li><a name="a1014"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-sym">)</span></li>
<li><a name="a1015"></a>    <span class="src-sym">{</span></li>
<li><a name="a1016"></a>        <span class="src-var">$args </span>= <a href="http://www.php.net/func_get_args">func_get_args</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1017"></a>        <span class="src-var">$hook </span>= <a href="http://www.php.net/array_shift">array_shift</a><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1018"></a>&nbsp;</li>
<li><a name="a1019"></a>        <span class="src-comm">// Valid hook?</span></li>
<li><a name="a1020"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$hook</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1021"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Invalid hook type&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1022"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a1023"></a>        <span class="src-sym">}</span></li>
<li><a name="a1024"></a>&nbsp;</li>
<li><a name="a1025"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1026"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-id">Unknown</span> <span class="src-id">hook</span> (<span class="src-var">$hook</span>)</span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1027"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a1028"></a>        <span class="src-sym">}</span></li>
<li><a name="a1029"></a>&nbsp;</li>
<li><a name="a1030"></a>        <span class="src-comm">// Determine what classes to check for</span></li>
<li><a name="a1031"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CALLBACK_CLASSES</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1032"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#method_class_hierarchy">_class_hierarchy</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1033"></a>        <span class="src-sym">}</span></li>
<li><a name="a1034"></a>&nbsp;</li>
<li><a name="a1035"></a>        <span class="src-comm">// Add this object to the argument list</span></li>
<li><a name="a1036"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_HOOK_ARG_PLACEMENT</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1037"></a>            <span class="src-id">array_unshift</span><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">, </span><span class="src-var">$this</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1038"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a1039"></a>            <a href="http://www.php.net/array_push">array_push</a><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">, </span><span class="src-var">$this</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1040"></a>        <span class="src-sym">}</span></li>
<li><a name="a1041"></a>&nbsp;</li>
<li><a name="a1042"></a>        <span class="src-comm">// Loop through the callback class hierarchy...</span></li>
<li><a name="a1043"></a>        <span class="src-var">$return </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1044"></a>        <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CALLBACK_CLASSES </span><span class="src-key">as </span><span class="src-var">$class</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1045"></a>            <span class="src-comm">// Is there a hook for this class?</span></li>
<li><a name="a1046"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$class</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1047"></a>                <span class="src-key">continue</span><span class="src-sym">;</span></li>
<li><a name="a1048"></a>            <span class="src-sym">}</span></li>
<li><a name="a1049"></a>&nbsp;</li>
<li><a name="a1050"></a>            <span class="src-var">$executed_callback </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1051"></a>&nbsp;</li>
<li><a name="a1052"></a>            <span class="src-comm">// Loop through callback array</span></li>
<li><a name="a1053"></a>            <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$_INSTALLED_CALLBACKS</span><span class="src-sym">[</span><span class="src-var">$hook</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$class</span><span class="src-sym">] </span><span class="src-key">as </span><span class="src-var">$callback</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1054"></a>                <span class="src-comm">// Check to see if this callback has already been executed</span></li>
<li><a name="a1055"></a>                <span class="src-var">$key </span>= <span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a1056"></a>                <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">)</span></li>
<li><a name="a1057"></a>                    &amp;&amp; <span class="src-sym">(</span><span class="src-num">2 </span>== <a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">))) </span></li>
<li><a name="a1058"></a>                <span class="src-sym">{</span></li>
<li><a name="a1059"></a>                    <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_object">is_object</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span></li>
<li><a name="a1060"></a>                        &amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">)) </span></li>
<li><a name="a1061"></a>                    <span class="src-sym">{</span></li>
<li><a name="a1062"></a>                        <span class="src-comm">// if it's an object method, get the class name so we</span></li>
<li><a name="a1063"></a>                        <span class="src-comm">// can serialize it</span></li>
<li><a name="a1064"></a>                        <span class="src-var">$array </span>= <span class="src-key">array</span><span class="src-sym">(</span><a href="http://www.php.net/get_class">get_class</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1065"></a>                        <span class="src-var">$key </span>= <a href="http://www.php.net/serialize">serialize</a><span class="src-sym">(</span><span class="src-var">$array</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1066"></a>                    <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span></li>
<li><a name="a1067"></a>                        &amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">)) </span></li>
<li><a name="a1068"></a>                    <span class="src-sym">{</span></li>
<li><a name="a1069"></a>                        <span class="src-comm">// class methods can be simply serialized</span></li>
<li><a name="a1070"></a>                        <span class="src-var">$key </span>= <a href="http://www.php.net/serialize">serialize</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1071"></a>                    <span class="src-sym">}</span></li>
<li><a name="a1072"></a>                <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1073"></a>                    <span class="src-comm">// function callbacks are simple</span></li>
<li><a name="a1074"></a>                    <span class="src-var">$key </span>= <span class="src-var">$callback</span><span class="src-sym">;</span></li>
<li><a name="a1075"></a>                <span class="src-sym">}</span></li>
<li><a name="a1076"></a>&nbsp;</li>
<li><a name="a1077"></a>                <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-var">$key</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1078"></a>                    <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">'Invalid call hook (bad callback)'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1079"></a>                    <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a1080"></a>                <span class="src-sym">}</span></li>
<li><a name="a1081"></a>&nbsp;</li>
<li><a name="a1082"></a>                <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$executed_callback</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1083"></a>                    <span class="src-comm">// Callback has been executed already... </span></li>
<li><a name="a1084"></a>                    <span class="src-key">continue</span><span class="src-sym">;</span></li>
<li><a name="a1085"></a>                <span class="src-sym">}</span></li>
<li><a name="a1086"></a>&nbsp;</li>
<li><a name="a1087"></a>                <span class="src-comm">// Execute callback</span></li>
<li><a name="a1088"></a>                try <span class="src-sym">{</span></li>
<li><a name="a1089"></a>                    <span class="src-var">$return</span><span class="src-sym">[</span><span class="src-sym">] </span>= <a href="http://www.php.net/call_user_func_array">call_user_func_array</a><span class="src-sym">(</span><span class="src-var">$callback</span><span class="src-sym">, </span><span class="src-var">$args</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1090"></a>                <span class="src-sym">} </span>catch <span class="src-sym">(</span><span class="src-id">Exception </span><span class="src-var">$e</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1091"></a>                    <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-id">Error</span> <span class="src-id">executing</span> <span class="src-var">$class</span> <span class="src-id">callback</span> <span class="src-id">in</span> <span class="src-var">$hook</span> <span class="src-id">stage</span>: </span><span class="src-str">&quot; </span>. <span class="src-var">$e</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1092"></a>                    <span class="src-key">die</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1093"></a>                <span class="src-sym">}</span></li>
<li><a name="a1094"></a>                <span class="src-var">$executed_callback</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>= <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a1095"></a>            <span class="src-sym">}</span></li>
<li><a name="a1096"></a>        <span class="src-sym">}</span></li>
<li><a name="a1097"></a>&nbsp;</li>
<li><a name="a1098"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-num">1 </span>== <a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$return</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1099"></a>            <span class="src-var">$return </span>= <span class="src-var">$return</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a1100"></a>        <span class="src-sym">}</span></li>
<li><a name="a1101"></a>&nbsp;</li>
<li><a name="a1102"></a>        <span class="src-key">return </span><span class="src-var">$return</span><span class="src-sym">;</span></li>
<li><a name="a1103"></a>    <span class="src-sym">}</span></li>
<li><a name="a1104"></a>&nbsp;</li>
<li><a name="a1105"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1106"></a><span class="src-doc">     * Get class hierarchy for a class name or object</span></li>
<li><a name="a1107"></a><span class="src-doc">     *</span></li>
<li><a name="a1108"></a><span class="src-doc">     * Determines the class hierarchy for a class, as an ordered array (current</span></li>
<li><a name="a1109"></a><span class="src-doc">     * class to eldest grandparent). Sets </span><span class="src-doc-inlinetag">{@link $_CALLBACK_CLASSES}</span><span class="src-doc">.</span></li>
<li><a name="a1110"></a><span class="src-doc">     *</span></li>
<li><a name="a1111"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> protected</span></li>
<li><a name="a1112"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string</span><span class="src-doc">|</span><span class="src-doc-type">object </span></li>
<li><a name="a1113"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a1114"></a><span class="src-doc">     */</span></li>
<li><a name="a1115"></a>    <span class="src-key">protected </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#method_class_hierarchy">_class_hierarchy</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)</span></li>
<li><a name="a1116"></a>    <span class="src-sym">{</span></li>
<li><a name="a1117"></a>        <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_object">is_object</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1118"></a>            <span class="src-var">$class </span>= <a href="http://www.php.net/get_class">get_class</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1119"></a>        <span class="src-sym">}</span></li>
<li><a name="a1120"></a>&nbsp;</li>
<li><a name="a1121"></a>        <span class="src-var">$classes </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1122"></a>        <span class="src-key">while </span><span class="src-sym">(</span><span class="src-var">$class </span>= <a href="http://www.php.net/get_parent_class">get_parent_class</a><span class="src-sym">(</span><span class="src-var">$class</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1123"></a>            <a href="http://www.php.net/array_push">array_push</a><span class="src-sym">(</span><span class="src-var">$classes</span><span class="src-sym">, </span><span class="src-var">$class</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1124"></a>        <span class="src-sym">}</span></li>
<li><a name="a1125"></a>&nbsp;</li>
<li><a name="a1126"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CALLBACK_CLASSES </span>= <span class="src-var">$classes</span><span class="src-sym">;</span></li>
<li><a name="a1127"></a>    <span class="src-sym">}</span></li>
<li><a name="a1128"></a>&nbsp;</li>
<li><a name="a1129"></a>&nbsp;</li>
<li><a name="a1130"></a>    <span class="src-comm">// UTILITY METHODS</span></li>
<li><a name="a1131"></a>&nbsp;</li>
<li><a name="a1131"></a>    </li>
<li><a name="a1132"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1133"></a><span class="src-doc">     * dump debugging information to the screen</span></li>
<li><a name="a1134"></a><span class="src-doc">     *</span></li>
<li><a name="a1135"></a><span class="src-doc">     * The dump() method is a debugging function which will return a</span></li>
<li><a name="a1136"></a><span class="src-doc">     * chunk of text which contains all the environment and CGI form</span></li>
<li><a name="a1137"></a><span class="src-doc">     * data of the request, formatted nicely for human readability.</span></li>
<li><a name="a1138"></a><span class="src-doc">     * Useful for debugging in a CLI environment.</span></li>
<li><a name="a1139"></a><span class="src-doc">     * </span></li>
<li><a name="a1140"></a><span class="src-doc">     * &lt;b&gt;Example:&lt;/b&gt;</span></li>
<li><a name="a1141"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1142"></a><span class="src-doc">     *     echo $webapp-&gt;dump();</span></li>
<li><a name="a1143"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1144"></a><span class="src-doc">     * </span></li>
<li><a name="a1145"></a><span class="src-doc">     */</span></li>
<li><a name="a1146"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methoddump">dump</a><span class="src-sym">(</span><span class="src-sym">) </span></li>
<li><a name="a1147"></a>    <span class="src-sym">{</span></li>
<li><a name="a1148"></a>        <span class="src-var">$output </span>= <span class="src-str">''</span><span class="src-sym">;</span></li>
<li><a name="a1149"></a>&nbsp;</li>
<li><a name="a1150"></a>        <span class="src-comm">// Dump run-mode</span></li>
<li><a name="a1151"></a>        <span class="src-var">$current_runmode </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodget_current_runmode">get_current_runmode</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1152"></a>&nbsp;</li>
<li><a name="a1153"></a>        <span class="src-var">$output </span>.= <span class="src-str">&quot;</span><span class="src-str"><span class="src-id">Current</span> <span class="src-id">Run</span>-<span class="src-id">mode</span>: '<span class="src-var">$current_runmode</span>'\n</span><span class="src-str">&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1154"></a>&nbsp;</li>
<li><a name="a1155"></a>        <span class="src-comm">// Dump Params</span></li>
<li><a name="a1156"></a>        <span class="src-var">$output </span>.=  <span class="src-str">&quot;\nQuery Parameters:\n&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1157"></a>        <span class="src-var">$params  </span>=<span class="src-sym">&amp; </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1158"></a>        <span class="src-var">$output </span>.=  <a href="http://www.php.net/print_r">print_r</a><span class="src-sym">(</span><span class="src-var">$params</span><span class="src-sym">, </span><span class="src-id">true</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1159"></a>&nbsp;</li>
<li><a name="a1160"></a>        <span class="src-key">return </span><span class="src-var">$output</span><span class="src-sym">;</span></li>
<li><a name="a1161"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1162"></a>&nbsp;</li>
<li><a name="a1163"></a>&nbsp;</li>
<li><a name="a1164"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1165"></a><span class="src-doc">     * Dump debugging information as HTML to the screen</span></li>
<li><a name="a1166"></a><span class="src-doc">     * </span></li>
<li><a name="a1167"></a><span class="src-doc">     * The dump_html() method is a debugging function which will return</span></li>
<li><a name="a1168"></a><span class="src-doc">     * a chunk of text which contains all the environment and CGI form</span></li>
<li><a name="a1169"></a><span class="src-doc">     * data of the request, formatted nicely for human readability via</span></li>
<li><a name="a1170"></a><span class="src-doc">     * a web browser.  Useful for outputting to a browser.</span></li>
<li><a name="a1171"></a><span class="src-doc">     * </span></li>
<li><a name="a1172"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1173"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1174"></a><span class="src-doc">     *     $output = $webapp-&gt;dump_html();</span></li>
<li><a name="a1175"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1176"></a><span class="src-doc">     */</span></li>
<li><a name="a1177"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methoddump_html">dump_html</a><span class="src-sym">(</span><span class="src-sym">) </span></li>
<li><a name="a1178"></a>    <span class="src-sym">{</span></li>
<li><a name="a1179"></a>        <span class="src-var">$output </span>= <span class="src-str">''</span><span class="src-sym">;</span></li>
<li><a name="a1180"></a>&nbsp;</li>
<li><a name="a1181"></a>        <span class="src-comm">// Dump run-mode</span></li>
<li><a name="a1182"></a>        <span class="src-var">$current_runmode </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodget_current_runmode">get_current_runmode</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1183"></a>&nbsp;</li>
<li><a name="a1184"></a>        <span class="src-var">$output </span>.= <span class="src-str">&quot;</span><span class="src-str">&lt;<span class="src-id">p</span>&gt;\n<span class="src-id">Current</span> <span class="src-id">Run</span>-<span class="src-id">mode</span>: '&lt;<span class="src-id">b</span>&gt;<span class="src-var">$current_runmode</span>&lt;/<span class="src-id">b</span>&gt;'&lt;<span class="src-id">br</span> /&gt;\n</span><span class="src-str">&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1185"></a>&nbsp;</li>
<li><a name="a1186"></a>        <span class="src-comm">// Dump Params</span></li>
<li><a name="a1187"></a>        <span class="src-var">$output </span>.= <span class="src-str">&quot;Query Parameters:&lt;/p&gt;\n&lt;ul&gt;\n&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1188"></a>&nbsp;</li>
<li><a name="a1189"></a>        <span class="src-var">$params </span>=<span class="src-sym">&amp; </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1190"></a>        <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$params </span><span class="src-key">as </span><span class="src-var">$q </span>=&gt; <span class="src-var">$v</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1191"></a>            <span class="src-var">$output </span>.= <span class="src-str">&quot;</span><span class="src-str">&lt;<span class="src-id">li</span>&gt;&lt;<span class="src-id">b</span>&gt;<span class="src-var">$q</span> :&lt;/<span class="src-id">b</span>&gt;&lt;<span class="src-id">pre</span>&gt;\n</span><span class="src-str">&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1192"></a>            <span class="src-var">$output </span>.= <a href="http://www.php.net/print_r">print_r</a><span class="src-sym">(</span><span class="src-var">$v</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1193"></a>            <span class="src-var">$output </span>.= <span class="src-str">&quot;&lt;/pre&gt;\n&lt;/li&gt;\n&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1194"></a>        <span class="src-sym">}</span></li>
<li><a name="a1195"></a>        <span class="src-var">$output </span>.= <span class="src-str">&quot;&lt;/ul&gt;\n&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1196"></a>&nbsp;</li>
<li><a name="a1197"></a>        <span class="src-key">return </span><span class="src-var">$output</span><span class="src-sym">;</span></li>
<li><a name="a1198"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1199"></a>&nbsp;</li>
<li><a name="a1200"></a>&nbsp;</li>
<li><a name="a1201"></a>    <span class="src-comm">// HTTP HEADER METHODS</span></li>
<li><a name="a1202"></a>&nbsp;</li>
<li><a name="a1202"></a>    </li>
<li><a name="a1203"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1204"></a><span class="src-doc">     * Set or return a list of header properties</span></li>
<li><a name="a1205"></a><span class="src-doc">     * </span></li>
<li><a name="a1206"></a><span class="src-doc">     * The header_props() method expects an associative array of valid  HTTP</span></li>
<li><a name="a1207"></a><span class="src-doc">     * header properties.  These properties will be passed directly to PHP's</span></li>
<li><a name="a1208"></a><span class="src-doc">     * header() method.  Refer to the PHP header function documentation for</span></li>
<li><a name="a1209"></a><span class="src-doc">     * exact usage details.</span></li>
<li><a name="a1210"></a><span class="src-doc">     * </span></li>
<li><a name="a1211"></a><span class="src-doc">     * If called multiple times, each set of headers is merged with the list</span></li>
<li><a name="a1212"></a><span class="src-doc">     * already contained; thus, later headers of the same type will overwrite</span></li>
<li><a name="a1213"></a><span class="src-doc">     * previous headers.</span></li>
<li><a name="a1214"></a><span class="src-doc">     * </span></li>
<li><a name="a1215"></a><span class="src-doc">     * Headers are not sent until the entire document is ready to be returned.</span></li>
<li><a name="a1216"></a><span class="src-doc">     *</span></li>
<li><a name="a1217"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1218"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1219"></a><span class="src-doc">     *     $webapp-&gt;header_props(array(</span></li>
<li><a name="a1220"></a><span class="src-doc">     *         'type'    =&gt; 'image/gif',</span></li>
<li><a name="a1221"></a><span class="src-doc">     *         'expires' =&gt; '+3d'</span></li>
<li><a name="a1222"></a><span class="src-doc">     *     ));</span></li>
<li><a name="a1223"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1224"></a><span class="src-doc">     * </span></li>
<li><a name="a1225"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a1226"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$data </span><span class="src-doc">Optional; associative array of header types and values</span></li>
<li><a name="a1227"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">array </span><span class="src-doc">Array of header properties</span></li>
<li><a name="a1228"></a><span class="src-doc">     */</span></li>
<li><a name="a1229"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodheader_props">header_props</a><span class="src-sym">(</span><span class="src-var">$data </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a1230"></a>    <span class="src-sym">{</span></li>
<li><a name="a1231"></a>        <span class="src-comm">// First use?  Create new _HEADER_PROPS!</span></li>
<li><a name="a1232"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_PROPS</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1233"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_PROPS </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1234"></a>        <span class="src-sym">}</span></li>
<li><a name="a1235"></a>&nbsp;</li>
<li><a name="a1236"></a>        <span class="src-var">$rh_p </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_PROPS</span><span class="src-sym">;</span></li>
<li><a name="a1237"></a>&nbsp;</li>
<li><a name="a1238"></a>        <span class="src-comm">// If data is provided, set it!</span></li>
<li><a name="a1239"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1240"></a>            <span class="src-comm">// This is an associative array; make a copy</span></li>
<li><a name="a1241"></a>            <span class="src-var">$rh_p </span>= <a href="http://www.php.net/array_merge">array_merge</a><span class="src-sym">(</span><span class="src-var">$rh_p</span><span class="src-sym">, </span><span class="src-var">$data</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1242"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">((</span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>% <span class="src-num">2</span><span class="src-sym">) </span>== <span class="src-num">0</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1243"></a>            <span class="src-var">$rh_p </span>= <a href="http://www.php.net/array_merge">array_merge</a><span class="src-sym">(</span><span class="src-var">$rh_p</span><span class="src-sym">, </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">array_to_hash</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1244"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>|| <span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">!</span><a href="http://www.php.net/is_null">is_null</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">))) </span><span class="src-sym">{</span></li>
<li><a name="a1245"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Bad data passed to header_props()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1246"></a>        <span class="src-sym">}</span></li>
<li><a name="a1247"></a>&nbsp;</li>
<li><a name="a1248"></a>        <span class="src-comm">// If we've gotten this far, set and return the value!</span></li>
<li><a name="a1249"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_PROPS </span>= <span class="src-var">$rh_p</span><span class="src-sym">;</span></li>
<li><a name="a1250"></a>        <span class="src-key">return </span><span class="src-var">$rh_p</span><span class="src-sym">;</span></li>
<li><a name="a1251"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1252"></a>&nbsp;</li>
<li><a name="a1253"></a>&nbsp;</li>
<li><a name="a1254"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1255"></a><span class="src-doc">     * Set the header type for the current instance of the application</span></li>
<li><a name="a1256"></a><span class="src-doc">     *</span></li>
<li><a name="a1257"></a><span class="src-doc">     * The header_type() method expects to be passed either 'header',</span></li>
<li><a name="a1258"></a><span class="src-doc">     * 'redirect', or 'none'.  This method specifies the type of HTTP headers</span></li>
<li><a name="a1259"></a><span class="src-doc">     * which should be sent back to the browser.  If not specified, defaults is</span></li>
<li><a name="a1260"></a><span class="src-doc">     * 'header'.  You can use this method to specify additional or alternate</span></li>
<li><a name="a1261"></a><span class="src-doc">     * HTTP headers for your application or run mode; this could be useful for</span></li>
<li><a name="a1262"></a><span class="src-doc">     * returning alternate content (a PDF or image file, for instance).</span></li>
<li><a name="a1263"></a><span class="src-doc">     * </span></li>
<li><a name="a1264"></a><span class="src-doc">     * To perform a redirect using Cgiapp2, you would do the following:</span></li>
<li><a name="a1265"></a><span class="src-doc">     * </span></li>
<li><a name="a1266"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1267"></a><span class="src-doc">     *   function some_redirect_mode()</span></li>
<li><a name="a1268"></a><span class="src-doc">     *   {</span></li>
<li><a name="a1269"></a><span class="src-doc">     *       $new_url = &quot;http://site/path/doc.html&quot;;</span></li>
<li><a name="a1270"></a><span class="src-doc">     *       $this-&gt;header_type('redirect');</span></li>
<li><a name="a1271"></a><span class="src-doc">     *       $this-&gt;header_props(array('url' =&gt; $new_url));</span></li>
<li><a name="a1272"></a><span class="src-doc">     *       return &quot;Redirecting to $new_url&quot;;</span></li>
<li><a name="a1273"></a><span class="src-doc">     *   }</span></li>
<li><a name="a1274"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1275"></a><span class="src-doc">     * </span></li>
<li><a name="a1276"></a><span class="src-doc">     * If you wish to suppress HTTP headers entirely (as might be the case if</span></li>
<li><a name="a1277"></a><span class="src-doc">     * you're working in a slightly more exotic environment), you can set</span></li>
<li><a name="a1278"></a><span class="src-doc">     * header_type() to &quot;none&quot;.  This will send no headers. Be warned: since you</span></li>
<li><a name="a1279"></a><span class="src-doc">     * are programming in PHP, &lt;b&gt;some&lt;/b&gt; headers &lt;b&gt;will&lt;/b&gt; be passed if you</span></li>
<li><a name="a1280"></a><span class="src-doc">     * are running your script via a web server.</span></li>
<li><a name="a1281"></a><span class="src-doc">     * </span></li>
<li><a name="a1282"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1283"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1284"></a><span class="src-doc">     *     $webapp-&gt;header_type('redirect');</span></li>
<li><a name="a1285"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1286"></a><span class="src-doc">     * </span></li>
<li><a name="a1287"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$header_type </span><span class="src-doc">Type of header to set: 'none', 'redirect', or</span></li>
<li><a name="a1288"></a><span class="src-doc">     *  'header' are valid.</span></li>
<li><a name="a1289"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">$header_type</span></li>
<li><a name="a1290"></a><span class="src-doc">     */</span></li>
<li><a name="a1291"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodheader_type">header_type</a><span class="src-sym">(</span><span class="src-var">$header_type </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a1292"></a>    <span class="src-sym">{</span></li>
<li><a name="a1293"></a>        <span class="src-var">$allowed_header_types </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">'header'</span><span class="src-sym">, </span><span class="src-str">'redirect'</span><span class="src-sym">, </span><span class="src-str">'none'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1294"></a>&nbsp;</li>
<li><a name="a1295"></a>        <span class="src-comm">// First use?  Create new _HEADER_TYPE!</span></li>
<li><a name="a1296"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_TYPE</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1297"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_TYPE </span>= <span class="src-str">'header'</span><span class="src-sym">;</span></li>
<li><a name="a1298"></a>        <span class="src-sym">}</span></li>
<li><a name="a1299"></a>&nbsp;</li>
<li><a name="a1300"></a>        <span class="src-comm">// If data is provided, set it!</span></li>
<li><a name="a1301"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$header_type</span><span class="src-sym">) </span></li>
<li><a name="a1302"></a>            &amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$header_type</span><span class="src-sym">)) </span></li>
<li><a name="a1303"></a>        <span class="src-sym">{</span></li>
<li><a name="a1304"></a>            <span class="src-var">$header_type </span>= <a href="http://www.php.net/strtolower">strtolower</a><span class="src-sym">(</span><span class="src-var">$header_type</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1305"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/in_array">in_array</a><span class="src-sym">(</span><span class="src-var">$header_type</span><span class="src-sym">, </span><span class="src-var">$allowed_header_types</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1306"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-id">Invalid</span> <span class="src-id">header_type</span> '<span class="src-var">$header_type</span>'</span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1307"></a>            <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a1308"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_TYPE </span>= <span class="src-var">$header_type</span><span class="src-sym">;</span></li>
<li><a name="a1309"></a>            <span class="src-sym">}</span></li>
<li><a name="a1310"></a>        <span class="src-sym">}</span></li>
<li><a name="a1311"></a>&nbsp;</li>
<li><a name="a1312"></a>        <span class="src-comm">// If we've gotten this far, return the value!</span></li>
<li><a name="a1313"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_HEADER_TYPE</span><span class="src-sym">;</span></li>
<li><a name="a1314"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1315"></a>&nbsp;</li>
<li><a name="a1316"></a>    <span class="src-comm">// TEMPLATE METHODS</span></li>
<li><a name="a1317"></a>&nbsp;</li>
<li><a name="a1317"></a>    </li>
<li><a name="a1318"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1319"></a><span class="src-doc">     * load_tmpl() - fetch a compiled template</span></li>
<li><a name="a1320"></a><span class="src-doc">     *</span></li>
<li><a name="a1321"></a><span class="src-doc">     * load_tmpl() takes the name of a template file and returns the text</span></li>
<li><a name="a1322"></a><span class="src-doc">     * generated by filling that template file. It does so by calling the</span></li>
<li><a name="a1323"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link add_callback() tmpl_fetch hook}</span><span class="src-doc">.</span></li>
<li><a name="a1324"></a><span class="src-doc">     *</span></li>
<li><a name="a1325"></a><span class="src-doc">     * If more than one callback hook has been registered for the tmpl_fetch</span></li>
<li><a name="a1326"></a><span class="src-doc">     * hook, and each returns a value, than all values will be concatenated with</span></li>
<li><a name="a1327"></a><span class="src-doc">     * a newline.</span></li>
<li><a name="a1328"></a><span class="src-doc">     *</span></li>
<li><a name="a1329"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1330"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1331"></a><span class="src-doc">     *     // Fetching a template from an object instance:</span></li>
<li><a name="a1332"></a><span class="src-doc">     *     $text = $webapp-&gt;load_tmpl('some.tpl');</span></li>
<li><a name="a1333"></a><span class="src-doc">     *</span></li>
<li><a name="a1334"></a><span class="src-doc">     *     // Fetching a template from within a class method:</span></li>
<li><a name="a1335"></a><span class="src-doc">     *     // Common usage is to return the fetched and populated template as</span></li>
<li><a name="a1336"></a><span class="src-doc">     *     // the value of the run mode:</span></li>
<li><a name="a1337"></a><span class="src-doc">     *     function someRunMode() {</span></li>
<li><a name="a1338"></a><span class="src-doc">     *         // Do some processing...</span></li>
<li><a name="a1339"></a><span class="src-doc">     *         return $this-&gt;load_tmpl('some.tpl');</span></li>
<li><a name="a1340"></a><span class="src-doc">     *     }</span></li>
<li><a name="a1341"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1342"></a><span class="src-doc">     * </span></li>
<li><a name="a1343"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE&lt;/b&gt;</span></li>
<li><a name="a1344"></a><span class="src-doc">     * This class may no longer be overridden, as it implements the</span></li>
<li><a name="a1345"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link add_callback() callback hook}</span><span class="src-doc"> 'tmpl_fetch'.  Also, in order to use</span></li>
<li><a name="a1346"></a><span class="src-doc">     * it, you will need to include a template plugin in your application or</span></li>
<li><a name="a1347"></a><span class="src-doc">     * superclass:</span></li>
<li><a name="a1348"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1349"></a><span class="src-doc">     * require_once 'Cgiapp2.class.php';</span></li>
<li><a name="a1350"></a><span class="src-doc">     * require_once 'Cgiapp2/Plugin/Smarty.class.php';</span></li>
<li><a name="a1351"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1352"></a><span class="src-doc">     *</span></li>
<li><a name="a1353"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$tmpl_file </span><span class="src-doc">Name of a template to load</span></li>
<li><a name="a1354"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">$output Contents of the compiled template</span></li>
<li><a name="a1355"></a><span class="src-doc">     */</span></li>
<li><a name="a1356"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodload_tmpl">load_tmpl</a><span class="src-sym">(</span><span class="src-var">$tmpl_file</span><span class="src-sym">) </span></li>
<li><a name="a1357"></a>    <span class="src-sym">{</span></li>
<li><a name="a1358"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-str">'tmpl_fetch'</span><span class="src-sym">, </span><span class="src-var">$tmpl_file</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1359"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1360"></a>&nbsp;</li>
<li><a name="a1361"></a>&nbsp;</li>
<li><a name="a1362"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1363"></a><span class="src-doc">     * Assign content to a template</span></li>
<li><a name="a1364"></a><span class="src-doc">     *</span></li>
<li><a name="a1365"></a><span class="src-doc">     * Attempts to assign content to a template. If a tmpl_assign</span></li>
<li><a name="a1366"></a><span class="src-doc">     * callback hook is registered, it will use that callback (see</span></li>
<li><a name="a1367"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link $_INSTALLED_CALLBACKS}</span><span class="src-doc"> and </span><span class="src-doc-inlinetag">{@link add_callback()}</span><span class="src-doc"> for information</span></li>
<li><a name="a1368"></a><span class="src-doc">     * on plugin callbacks), passing it all arguments.</span></li>
<li><a name="a1369"></a><span class="src-doc">     * </span></li>
<li><a name="a1370"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1371"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1372"></a><span class="src-doc">     *     // Assigning values via an object instance</span></li>
<li><a name="a1373"></a><span class="src-doc">     *     $webapp-&gt;tmpl_assign('var_name', 'value');</span></li>
<li><a name="a1374"></a><span class="src-doc">     *</span></li>
<li><a name="a1375"></a><span class="src-doc">     *     // From within the class:</span></li>
<li><a name="a1376"></a><span class="src-doc">     *     function someRunMode()</span></li>
<li><a name="a1377"></a><span class="src-doc">     *     {</span></li>
<li><a name="a1378"></a><span class="src-doc">     *         // Assign a single value</span></li>
<li><a name="a1379"></a><span class="src-doc">     *         $this-&gt;tmpl-assign('var_name', $value);</span></li>
<li><a name="a1380"></a><span class="src-doc">     *</span></li>
<li><a name="a1381"></a><span class="src-doc">     *         // Assign several values</span></li>
<li><a name="a1382"></a><span class="src-doc">     *         $this-&gt;tmpl_assign(array(</span></li>
<li><a name="a1383"></a><span class="src-doc">     *             'var1' =&gt; $value1,</span></li>
<li><a name="a1384"></a><span class="src-doc">     *             'var2' =&gt; $value2</span></li>
<li><a name="a1385"></a><span class="src-doc">     *         ));</span></li>
<li><a name="a1386"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1387"></a><span class="src-doc">     * </span></li>
<li><a name="a1388"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE&lt;/b&gt;</span></li>
<li><a name="a1389"></a><span class="src-doc">     * This class may no longer be overridden, as it implements the</span></li>
<li><a name="a1390"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link add_callback() callback hook}</span><span class="src-doc"> 'tmpl_assign'.  Also, in order to</span></li>
<li><a name="a1391"></a><span class="src-doc">     * use it, you will need to include a template plugin in your application or</span></li>
<li><a name="a1392"></a><span class="src-doc">     * superclass:</span></li>
<li><a name="a1393"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1394"></a><span class="src-doc">     * require_once 'Cgiapp2.class.php';</span></li>
<li><a name="a1395"></a><span class="src-doc">     * require_once 'Cgiapp2/Plugin/Smarty.class.php';</span></li>
<li><a name="a1396"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1397"></a><span class="src-doc">     *</span></li>
<li><a name="a1398"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">mixed </span><span class="src-doc-var">$data </span><span class="src-doc">An associative array of var =&gt; val pairs to assign to</span></li>
<li><a name="a1399"></a><span class="src-doc">     *  the template</span></li>
<li><a name="a1400"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">mixed </span><span class="src-doc-var">$var,$val </span><span class="src-doc">Assign $val to $var in the template</span></li>
<li><a name="a1401"></a><span class="src-doc">     */</span></li>
<li><a name="a1402"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodtmpl_assign">tmpl_assign</a><span class="src-sym">(</span><span class="src-sym">)</span></li>
<li><a name="a1403"></a>    <span class="src-sym">{</span></li>
<li><a name="a1404"></a>        <span class="src-var">$args </span>= <a href="http://www.php.net/func_get_args">func_get_args</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1405"></a>        <a href="http://www.php.net/array_unshift">array_unshift</a><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">, </span><span class="src-str">'tmpl_assign'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1406"></a>        <span class="src-key">return </span><a href="http://www.php.net/call_user_func_array">call_user_func_array</a><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-str">'call_hook'</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-var">$args</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1407"></a>    <span class="src-sym">}</span></li>
<li><a name="a1408"></a>&nbsp;</li>
<li><a name="a1409"></a>&nbsp;</li>
<li><a name="a1410"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1411"></a><span class="src-doc">     * Set template path and initialize template object</span></li>
<li><a name="a1412"></a><span class="src-doc">     *</span></li>
<li><a name="a1413"></a><span class="src-doc">     * tmpl_path() sets the file path to the base directory where the templates</span></li>
<li><a name="a1414"></a><span class="src-doc">     * are stored.  It then calls the </span><span class="src-doc-inlinetag">{@link add_callback() tmpl_path hook}</span><span class="src-doc">.</span></li>
<li><a name="a1415"></a><span class="src-doc">     *</span></li>
<li><a name="a1416"></a><span class="src-doc">     * tmpl_path() also takes an optional argument of an associative array of</span></li>
<li><a name="a1417"></a><span class="src-doc">     * parameters to pass to the template engine constructor; this can be used</span></li>
<li><a name="a1418"></a><span class="src-doc">     * to customize the template engine's behaviour for your application. It is</span></li>
<li><a name="a1419"></a><span class="src-doc">     * passed to the tmpl_path hook.</span></li>
<li><a name="a1420"></a><span class="src-doc">     *</span></li>
<li><a name="a1421"></a><span class="src-doc">     * See </span><span class="src-doc-inlinetag">{@link Cgiapp2_Plugin_Smarty::init()}</span><span class="src-doc"> for an example of a tmpl_path</span></li>
<li><a name="a1422"></a><span class="src-doc">     * hook in practice.</span></li>
<li><a name="a1423"></a><span class="src-doc">     *</span></li>
<li><a name="a1424"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1425"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1426"></a><span class="src-doc">     *     $webapp-&gt;tmpl_path('/path/to/some/templates/');</span></li>
<li><a name="a1427"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1428"></a><span class="src-doc">     * </span></li>
<li><a name="a1429"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE&lt;/b&gt;</span></li>
<li><a name="a1430"></a><span class="src-doc">     * This class may no longer be overridden, as it implements the</span></li>
<li><a name="a1431"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link add_callback() callback hook}</span><span class="src-doc"> 'tmpl_path'.  Also, in order to use</span></li>
<li><a name="a1432"></a><span class="src-doc">     * it, you will need to include a template plugin in your application or</span></li>
<li><a name="a1433"></a><span class="src-doc">     * superclass:</span></li>
<li><a name="a1434"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1435"></a><span class="src-doc">     * require_once 'Cgiapp2.class.php';</span></li>
<li><a name="a1436"></a><span class="src-doc">     * require_once 'Cgiapp2/Plugin/Smarty.class.php';</span></li>
<li><a name="a1437"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1438"></a><span class="src-doc">     *</span></li>
<li><a name="a1439"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$tmpl_path </span><span class="src-doc">Optional; path to base template directory</span></li>
<li><a name="a1440"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$extra_params </span><span class="src-doc">Optional; associative array of arguments to</span></li>
<li><a name="a1441"></a><span class="src-doc">     *  pass to template engine constructor</span></li>
<li><a name="a1442"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">Template path</span></li>
<li><a name="a1443"></a><span class="src-doc">     */</span></li>
<li><a name="a1444"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodtmpl_path">tmpl_path</a><span class="src-sym">(</span><span class="src-var">$tmpl_path </span>= <span class="src-id">null</span><span class="src-sym">, </span><span class="src-var">$extra_params </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a1445"></a>    <span class="src-sym">{</span></li>
<li><a name="a1446"></a>        <span class="src-comm">// First use?  Create new _TMPL_PATH!</span></li>
<li><a name="a1447"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_TMPL_PATH</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1448"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_TMPL_PATH </span>= <span class="src-str">'.'</span><span class="src-sym">;</span></li>
<li><a name="a1449"></a>        <span class="src-sym">}</span></li>
<li><a name="a1450"></a>&nbsp;</li>
<li><a name="a1451"></a>        <span class="src-comm">// If data is provided, set it and initialize template object</span></li>
<li><a name="a1452"></a>        <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$tmpl_path</span><span class="src-sym">)     </span></li>
<li><a name="a1453"></a>            &amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$tmpl_path</span><span class="src-sym">)</span></li>
<li><a name="a1454"></a>            &amp;&amp; <a href="http://www.php.net/is_dir">is_dir</a><span class="src-sym">(</span><span class="src-var">$tmpl_path</span><span class="src-sym">)) </span></li>
<li><a name="a1455"></a>        <span class="src-sym">{</span></li>
<li><a name="a1456"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_TMPL_PATH </span>= <span class="src-var">$tmpl_path</span><span class="src-sym">;</span></li>
<li><a name="a1457"></a>&nbsp;</li>
<li><a name="a1458"></a>            <span class="src-comm">// Call hook to create template engine object</span></li>
<li><a name="a1459"></a>            <span class="src-var">$e </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodcall_hook">call_hook</a><span class="src-sym">(</span><span class="src-str">'tmpl_path'</span><span class="src-sym">, </span><span class="src-var">$tmpl_path</span><span class="src-sym">, </span><span class="src-var">$extra_params</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1460"></a>            </li>
<li><a name="a1461"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-var">$e</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1462"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">'No tmpl_path hook set'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1463"></a>            <span class="src-sym">}</span></li>
<li><a name="a1464"></a>        <span class="src-sym">}</span></li>
<li><a name="a1465"></a>&nbsp;</li>
<li><a name="a1466"></a>        <span class="src-comm">// If we've gotten this far, return the value!</span></li>
<li><a name="a1467"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_TMPL_PATH</span><span class="src-sym">;</span></li>
<li><a name="a1468"></a>    <span class="src-sym">}</span></li>
<li><a name="a1469"></a>&nbsp;</li>
<li><a name="a1470"></a>    <span class="src-comm">// APPLICATION METHODS</span></li>
<li><a name="a1471"></a>    <span class="src-comm">// These methods are Cgiapp2 methods that are critical for standard usage of</span></li>
<li><a name="a1472"></a>    <span class="src-comm">// the class and should, in most events, never be overridden.</span></li>
<li><a name="a1473"></a>&nbsp;</li>
<li><a name="a1473"></a>    </li>
<li><a name="a1474"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1475"></a><span class="src-doc">     * Set the CGI parameter used to indicate the run mode</span></li>
<li><a name="a1476"></a><span class="src-doc">     * </span></li>
<li><a name="a1477"></a><span class="src-doc">     * mode_param() is generally called in the </span><span class="src-doc-inlinetag">{@link setup()}</span><span class="src-doc"> method.  The</span></li>
<li><a name="a1478"></a><span class="src-doc">     * mode_param() method is used to tell the </span><span class="src-doc-inlinetag">{@link run()}</span><span class="src-doc"> method how to</span></li>
<li><a name="a1479"></a><span class="src-doc">     * determine the requested run mode. Three possibilities exist:</span></li>
<li><a name="a1480"></a><span class="src-doc">     * &lt;ol&gt;</span></li>
<li><a name="a1481"></a><span class="src-doc">     *     &lt;li&gt;Use a </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span><span class="src-doc"> parameter (this is the default,</span></li>
<li><a name="a1482"></a><span class="src-doc">     *     and 'rm' is the</span></li>
<li><a name="a1483"></a><span class="src-doc">     *     default value)&lt;/li&gt;</span></li>
<li><a name="a1484"></a><span class="src-doc">     *     &lt;li&gt;Provide a function or a method name to use as a callback&lt;/li&gt;</span></li>
<li><a name="a1485"></a><span class="src-doc">     *     &lt;li&gt;Provide the index in PATH_INFO to use&lt;/li&gt;</span></li>
<li><a name="a1486"></a><span class="src-doc">     * &lt;/ol&gt;</span></li>
<li><a name="a1487"></a><span class="src-doc">     * As noted in (1), above, if mode_param() is not specified by the</span></li>
<li><a name="a1488"></a><span class="src-doc">     * developer, the method defaults to using the </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span></li>
<li><a name="a1489"></a><span class="src-doc">     * parameter 'rm'.</span></li>
<li><a name="a1490"></a><span class="src-doc">     *</span></li>
<li><a name="a1491"></a><span class="src-doc">     * In the first case, you would call mode_param() simply as:</span></li>
<li><a name="a1492"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1493"></a><span class="src-doc">     *     $webapp-&gt;mode_param('mode');</span></li>
<li><a name="a1494"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1495"></a><span class="src-doc">     * &lt;b&gt;Note:&lt;/b&gt; if the parameter name you specify matches a method or</span></li>
<li><a name="a1496"></a><span class="src-doc">     * function you've defined, Cgiapp2 will use that function or method instead.</span></li>
<li><a name="a1497"></a><span class="src-doc">     * This is probably a bug.</span></li>
<li><a name="a1498"></a><span class="src-doc">     * </span></li>
<li><a name="a1499"></a><span class="src-doc">     * Alternatively you can set mode_param() to use a method or function name,</span></li>
<li><a name="a1500"></a><span class="src-doc">     * as described in (2), above:</span></li>
<li><a name="a1501"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1502"></a><span class="src-doc">     *     $webapp-&gt;mode_param('some_method');</span></li>
<li><a name="a1503"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1504"></a><span class="src-doc">     * This would allow you to create an instance method whose output would be</span></li>
<li><a name="a1505"></a><span class="src-doc">     * used as the value of the current run mode.  E.g., a &quot;mode param method&quot;:</span></li>
<li><a name="a1506"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1507"></a><span class="src-doc">     *     function some_method()</span></li>
<li><a name="a1508"></a><span class="src-doc">     *     {</span></li>
<li><a name="a1509"></a><span class="src-doc">     *         // Do some stuff here, such as looking at SERVER_NAME or</span></li>
<li><a name="a1510"></a><span class="src-doc">     *         // PATH_INFO, and return a mode parameter accordingly</span></li>
<li><a name="a1511"></a><span class="src-doc">     *         return 'run_mode_x';</span></li>
<li><a name="a1512"></a><span class="src-doc">     *     }</span></li>
<li><a name="a1513"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1514"></a><span class="src-doc">     *</span></li>
<li><a name="a1515"></a><span class="src-doc">     * In the third case mentioned above, you may specify the index of the</span></li>
<li><a name="a1516"></a><span class="src-doc">     * PATH_INFO element to utilize as the run mode, where PATH_INFO elements</span></li>
<li><a name="a1517"></a><span class="src-doc">     * are separated by a '/' character. With this method, it is also wise to</span></li>
<li><a name="a1518"></a><span class="src-doc">     * pass a PARAM key which specifies a </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span><span class="src-doc"> parameter to</span></li>
<li><a name="a1519"></a><span class="src-doc">     * use as a fallback. For example:</span></li>
<li><a name="a1520"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1521"></a><span class="src-doc">     *     $webapp-&gt;mode_param(array('path_info' =&gt; 2, 'param' =&gt; 'q'));</span></li>
<li><a name="a1522"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1523"></a><span class="src-doc">     * would look for the second element in the PATH_INFO string for the run</span></li>
<li><a name="a1524"></a><span class="src-doc">     * mode, or the 'q' </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span><span class="src-doc"> key if not found. So, in the</span></li>
<li><a name="a1525"></a><span class="src-doc">     * following:</span></li>
<li><a name="a1526"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1527"></a><span class="src-doc">     *     /path/to/webapp.php/do/view/2</span></li>
<li><a name="a1528"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1529"></a><span class="src-doc">     * the run mode would be set to 'view' (as that's the second element in the</span></li>
<li><a name="a1530"></a><span class="src-doc">     * PATH_INFO string). But in this:</span></li>
<li><a name="a1531"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1532"></a><span class="src-doc">     *     /path/to/webapp.php/do/?q=form&amp;id=2</span></li>
<li><a name="a1533"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1534"></a><span class="src-doc">     * since there is no second element in the PATH_INFO string, the application</span></li>
<li><a name="a1535"></a><span class="src-doc">     * would grab the parameter from the 'q' </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span><span class="src-doc"> element.</span></li>
<li><a name="a1536"></a><span class="src-doc">     *</span></li>
<li><a name="a1537"></a><span class="src-doc">     * If you use a negative index, then Cgiapp2 will look from the end of the</span></li>
<li><a name="a1538"></a><span class="src-doc">     * PATH_INFO list. In the example above, if '-2' were passed as the index,</span></li>
<li><a name="a1539"></a><span class="src-doc">     * it would use the item 'view' (second from the end).</span></li>
<li><a name="a1540"></a><span class="src-doc">     *</span></li>
<li><a name="a1541"></a><span class="src-doc">     * If 'param' is not specified in the array passed to mode_param(), then the</span></li>
<li><a name="a1542"></a><span class="src-doc">     * default run mode of 'rm' is assumed.</span></li>
<li><a name="a1543"></a><span class="src-doc">     * </span></li>
<li><a name="a1544"></a><span class="src-doc">     * &lt;b&gt;NOTE:&lt;/b&gt; As of 1.5.2, if the value passed to mode_param() is the name</span></li>
<li><a name="a1545"></a><span class="src-doc">     * of a Cgiapp2 internal method (other than </span><span class="src-doc-inlinetag">{@link dump()}</span><span class="src-doc">, </span><span class="src-doc-inlinetag">{@link }</span></li>
<li><a name="a1546"></a><span class="src-doc">     * dump_html()}, </span><span class="src-doc-inlinetag">{@link carp()}</span><span class="src-doc">, or </span><span class="src-doc-inlinetag">{@link croak()}</span><span class="src-doc">) or PHP internal</span></li>
<li><a name="a1547"></a><span class="src-doc">     * function, the run mode will be pulled from the </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span></li>
<li><a name="a1548"></a><span class="src-doc">     * parameter. This is to enhance security and also to allow using common</span></li>
<li><a name="a1549"></a><span class="src-doc">     * keywords as mode parameters.</span></li>
<li><a name="a1550"></a><span class="src-doc">     * </span></li>
<li><a name="a1551"></a><span class="src-doc">     * &lt;b&gt;NOTE 2:&lt;/b&gt; Try not to use PHP internal function names as mode</span></li>
<li><a name="a1552"></a><span class="src-doc">     * parameters. In order to check against the PHP internal function list when</span></li>
<li><a name="a1553"></a><span class="src-doc">     * a mode parameter matching a function is passed, Cgiapp2 calls</span></li>
<li><a name="a1554"></a><span class="src-doc">     * get_defined_functions(), which causes a significant performance hit.</span></li>
<li><a name="a1555"></a><span class="src-doc">     *</span></li>
<li><a name="a1556"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string</span><span class="src-doc">|</span><span class="src-doc-type">array</span><span class="src-doc-var">$mode_param </span><span class="src-doc">Optional; the name of the CGI run mode</span></li>
<li><a name="a1557"></a><span class="src-doc">     *  parameter, the name of a function or class method that can return a run</span></li>
<li><a name="a1558"></a><span class="src-doc">     *  mode, or an array specifying the index in PATH_INFO to use and an</span></li>
<li><a name="a1559"></a><span class="src-doc">     *  optional PARAM that could specify a run mode</span></li>
<li><a name="a1560"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">Run mode parameter</span></li>
<li><a name="a1561"></a><span class="src-doc">     */</span></li>
<li><a name="a1562"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodmode_param">mode_param</a><span class="src-sym">(</span><span class="src-var">$mode_param </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a1563"></a>    <span class="src-sym">{</span></li>
<li><a name="a1564"></a>        <span class="src-comm">// First use?  Create new _MODE_PARAM!</span></li>
<li><a name="a1565"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_MODE_PARAM</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1566"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_MODE_PARAM </span>= <span class="src-str">'rm'</span><span class="src-sym">;</span></li>
<li><a name="a1567"></a>        <span class="src-sym">}</span></li>
<li><a name="a1568"></a>&nbsp;</li>
<li><a name="a1569"></a>        <span class="src-comm">// If data is provided, set it!</span></li>
<li><a name="a1570"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$mode_param</span><span class="src-sym">)</span></li>
<li><a name="a1571"></a>            &amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$mode_param</span><span class="src-sym">))</span></li>
<li><a name="a1572"></a>        <span class="src-sym">{</span></li>
<li><a name="a1573"></a>            <span class="src-comm">// String passed</span></li>
<li><a name="a1574"></a>            <span class="src-comm">// Originally checked to see if mode_param was a method or function</span></li>
<li><a name="a1575"></a>            <span class="src-comm">// first, but run() does that already. For now, we can just set it</span></li>
<li><a name="a1576"></a>            <span class="src-comm">// directly to the string</span></li>
<li><a name="a1577"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_MODE_PARAM </span>= <span class="src-var">$mode_param</span><span class="src-sym">;</span></li>
<li><a name="a1578"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$mode_param</span><span class="src-sym">)</span></li>
<li><a name="a1579"></a>            &amp;&amp; <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$mode_param</span><span class="src-sym">)) </span></li>
<li><a name="a1580"></a>        <span class="src-sym">{</span></li>
<li><a name="a1581"></a>            <span class="src-comm">// Possibly retrieving from path info</span></li>
<li><a name="a1582"></a>            <span class="src-var">$params </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">cap_hash</span><span class="src-sym">(</span><span class="src-var">$mode_param</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1583"></a>&nbsp;</li>
<li><a name="a1584"></a>            <span class="src-comm">// Grab the param element, if available</span></li>
<li><a name="a1585"></a>            <span class="src-var">$mode_param </span>= <span class="src-sym">((</span>isset<span class="src-sym">(</span><span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">'PARAM'</span><span class="src-sym">]</span><span class="src-sym">)) </span>? <span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">'PARAM'</span><span class="src-sym">] </span>: <span class="src-str">'rm'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1586"></a>&nbsp;</li>
<li><a name="a1587"></a>            <span class="src-comm">// Check to see of PATH_INFO passed</span></li>
<li><a name="a1588"></a>            <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">'PATH_INFO'</span><span class="src-sym">]</span><span class="src-sym">) </span></li>
<li><a name="a1589"></a>                &amp;&amp; <span class="src-sym">(</span><span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">'PATH_INFO'</span><span class="src-sym">] </span>== <a href="http://www.php.net/strval">strval</a><span class="src-sym">(</span><a href="http://www.php.net/intval">intval</a><span class="src-sym">(</span><span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">'PATH_INFO'</span><span class="src-sym">]</span><span class="src-sym">))))</span></li>
<li><a name="a1590"></a>            <span class="src-sym">{</span></li>
<li><a name="a1591"></a>                <span class="src-comm">// Attempting to use PATH_INFO</span></li>
<li><a name="a1592"></a>                <span class="src-var">$idx </span>= <span class="src-var">$params</span><span class="src-sym">[</span><span class="src-str">'PATH_INFO'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a1593"></a>                <span class="src-var">$idx </span>= <span class="src-sym">(</span><span class="src-num">0 </span>&gt; <span class="src-var">$idx</span><span class="src-sym">) </span>? <span class="src-var">$idx </span>+ <span class="src-num">1 </span>: <span class="src-var">$idx </span>- <span class="src-num">1</span><span class="src-sym">;</span></li>
<li><a name="a1594"></a>                <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">false </span>!== <span class="src-sym">(</span><span class="src-var">$param </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">path_info</span><span class="src-sym">(</span><span class="src-var">$idx</span><span class="src-sym">))) </span></li>
<li><a name="a1595"></a>                <span class="src-sym">{</span></li>
<li><a name="a1596"></a>                    <span class="src-comm">// Using PATH_INFO</span></li>
<li><a name="a1597"></a>                    <span class="src-var">$mode_param </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">'run_mode' </span>=&gt; <span class="src-var">$param</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1598"></a>                <span class="src-sym">}</span></li>
<li><a name="a1599"></a>            <span class="src-sym">}</span></li>
<li><a name="a1600"></a>&nbsp;</li>
<li><a name="a1601"></a>            <span class="src-comm">// Set _MODE_PARAM</span></li>
<li><a name="a1602"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_MODE_PARAM </span>= <span class="src-var">$mode_param</span><span class="src-sym">;</span></li>
<li><a name="a1603"></a>        <span class="src-sym">}</span></li>
<li><a name="a1604"></a>&nbsp;</li>
<li><a name="a1605"></a>        <span class="src-comm">// If we've gotten this far, return the value!</span></li>
<li><a name="a1606"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_MODE_PARAM</span><span class="src-sym">;</span></li>
<li><a name="a1607"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1608"></a>&nbsp;</li>
<li><a name="a1609"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1610"></a><span class="src-doc">     * Define or return a list of the valid run modes for the application</span></li>
<li><a name="a1611"></a><span class="src-doc">     * </span></li>
<li><a name="a1612"></a><span class="src-doc">     * run_modes() expects an associative array which specifies the</span></li>
<li><a name="a1613"></a><span class="src-doc">     * dispatch table for the different CGI states.  The </span><span class="src-doc-inlinetag">{@link run()}</span><span class="src-doc"> method</span></li>
<li><a name="a1614"></a><span class="src-doc">     * uses the data in this table to send the CGI to the correct function as</span></li>
<li><a name="a1615"></a><span class="src-doc">     * determined by reading the CGI parameter specified by </span><span class="src-doc-inlinetag">{@link mode_param()}</span></li>
<li><a name="a1616"></a><span class="src-doc">     * (defaults to 'rm' for &quot;Run Mode&quot;).  These functions are referred to as</span></li>
<li><a name="a1617"></a><span class="src-doc">     * &quot;run mode methods&quot;.</span></li>
<li><a name="a1618"></a><span class="src-doc">     * </span></li>
<li><a name="a1619"></a><span class="src-doc">     * The associative array set by this method is expected to contain the mode</span></li>
<li><a name="a1620"></a><span class="src-doc">     * name as a key.  The value should be either a reference to a function or</span></li>
<li><a name="a1621"></a><span class="src-doc">     * method  to the run mode method which you want to be called when the CGI</span></li>
<li><a name="a1622"></a><span class="src-doc">     * enters the specified run mode, or the name of the run mode method to be</span></li>
<li><a name="a1623"></a><span class="src-doc">     * called (preferred):</span></li>
<li><a name="a1624"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1625"></a><span class="src-doc">     *     'mode_name_by_ref'  =&gt; &amp;mode_function()</span></li>
<li><a name="a1626"></a><span class="src-doc">     *     'mode_name_by_name' =&gt; 'mode_function'</span></li>
<li><a name="a1627"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1628"></a><span class="src-doc">     * The run_mode() method specified is expected to return a block of text</span></li>
<li><a name="a1629"></a><span class="src-doc">     * (e.g.: HTML) which will eventually be sent back to the web browser.</span></li>
<li><a name="a1630"></a><span class="src-doc">     * Commonly, this block of text will be returned by using a construction</span></li>
<li><a name="a1631"></a><span class="src-doc">     * like:</span></li>
<li><a name="a1632"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1633"></a><span class="src-doc">     *     return $this-&gt;load_tmpl('some_template.tpl');</span></li>
<li><a name="a1634"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1635"></a><span class="src-doc">     * An advantage of specifying your run mode methods by name instead of by</span></li>
<li><a name="a1636"></a><span class="src-doc">     * reference is that you can more easily create derivative applications</span></li>
<li><a name="a1637"></a><span class="src-doc">     * using inheritance.  For instance, if you have a new application which is</span></li>
<li><a name="a1638"></a><span class="src-doc">     * exactly the same as an existing application with the exception of one run</span></li>
<li><a name="a1639"></a><span class="src-doc">     * mode, you could simply inherit from that other application and override</span></li>
<li><a name="a1640"></a><span class="src-doc">     * the run mode method which is different.  If you specified your run mode</span></li>
<li><a name="a1641"></a><span class="src-doc">     * method by reference, your child class would still use the function from</span></li>
<li><a name="a1642"></a><span class="src-doc">     * the parent class.</span></li>
<li><a name="a1643"></a><span class="src-doc">     * </span></li>
<li><a name="a1644"></a><span class="src-doc">     * In perl, there's a speed advantage to assigning by reference; however, in</span></li>
<li><a name="a1645"></a><span class="src-doc">     * PHP this is not the case, which provides yet another reason to specify</span></li>
<li><a name="a1646"></a><span class="src-doc">     * your run modes by name rather than reference.</span></li>
<li><a name="a1647"></a><span class="src-doc">     * </span></li>
<li><a name="a1648"></a><span class="src-doc">     * The run_modes() method may be called more than once.  Additional values</span></li>
<li><a name="a1649"></a><span class="src-doc">     * passed into run_modes() will be added to the run modes table.  In the</span></li>
<li><a name="a1650"></a><span class="src-doc">     * case that an existing run mode is re-defined, the new value will override</span></li>
<li><a name="a1651"></a><span class="src-doc">     * the existing value.  This behavior might be useful for applications which</span></li>
<li><a name="a1652"></a><span class="src-doc">     * are created via inheritance from another application, or some advanced</span></li>
<li><a name="a1653"></a><span class="src-doc">     * application which modifies its own capabilities based on user input.</span></li>
<li><a name="a1654"></a><span class="src-doc">     * </span></li>
<li><a name="a1655"></a><span class="src-doc">     * A second interface for designating run modes and their methods is via an</span></li>
<li><a name="a1656"></a><span class="src-doc">     * indexed array:</span></li>
<li><a name="a1657"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1658"></a><span class="src-doc">     *     $webapp-&gt;run_modes(array('mode1', 'method1, 'mode2', 'method2'));</span></li>
<li><a name="a1659"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1660"></a><span class="src-doc">     * This is the same as the following, via an associative array:</span></li>
<li><a name="a1661"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1662"></a><span class="src-doc">     *     $webapp-&gt;run_modes(array(</span></li>
<li><a name="a1663"></a><span class="src-doc">     *         'mode1' =&gt; 'method1',</span></li>
<li><a name="a1664"></a><span class="src-doc">     *         'mode2' =&gt; 'method2'</span></li>
<li><a name="a1665"></a><span class="src-doc">     *     ));</span></li>
<li><a name="a1666"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1667"></a><span class="src-doc">     * </span></li>
<li><a name="a1668"></a><span class="src-doc">     * Finally, you can also pass an array &lt;b&gt;plus&lt;/b&gt; an optional flag set to</span></li>
<li><a name="a1669"></a><span class="src-doc">     * true to. This will assign each element of the array to the</span></li>
<li><a name="a1670"></a><span class="src-doc">     * correspondingly named method as its run mode:</span></li>
<li><a name="a1671"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1672"></a><span class="src-doc">     *     // Sets run mode 'mode1' to point to method 'mode1', and so on</span></li>
<li><a name="a1673"></a><span class="src-doc">     *     $webapp-&gt;run_modes(array('mode1', 'mode2'), true);</span></li>
<li><a name="a1674"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1675"></a><span class="src-doc">     * </span></li>
<li><a name="a1676"></a><span class="src-doc">     * Note that another importance of specifying your run modes in either an</span></li>
<li><a name="a1677"></a><span class="src-doc">     * array or associative array is to assure that only those methods which are</span></li>
<li><a name="a1678"></a><span class="src-doc">     * specifically designated may be called via your application.  Application</span></li>
<li><a name="a1679"></a><span class="src-doc">     * environments which don't specify allowed methods and disallow all others</span></li>
<li><a name="a1680"></a><span class="src-doc">     * are insecure, potentially opening the door to allowing execution of</span></li>
<li><a name="a1681"></a><span class="src-doc">     * arbitrary code.  Cgiapp2 maintains a strict &quot;default-deny&quot; stance on all</span></li>
<li><a name="a1682"></a><span class="src-doc">     * method invocation, thereby allowing secure applications to be built upon</span></li>
<li><a name="a1683"></a><span class="src-doc">     * it.</span></li>
<li><a name="a1684"></a><span class="src-doc">     * </span></li>
<li><a name="a1685"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1686"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1687"></a><span class="src-doc">     *     $webapp-&gt;run_modes(array(</span></li>
<li><a name="a1688"></a><span class="src-doc">     *         'mode1' =&gt; 'some_sub_by_name',</span></li>
<li><a name="a1689"></a><span class="src-doc">     *         'mode2' =&gt; &amp;some_other_sub_by_ref()</span></li>
<li><a name="a1690"></a><span class="src-doc">     *     ));</span></li>
<li><a name="a1691"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1692"></a><span class="src-doc">     * </span></li>
<li><a name="a1693"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$data </span><span class="src-doc">(Associative) array of run mode =&gt; method mappings</span></li>
<li><a name="a1694"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">bool </span><span class="src-doc-var">$flag </span><span class="src-doc">Optional flag indicating that $data is a regular array</span></li>
<li><a name="a1695"></a><span class="src-doc">     *  and that each element refers to a corresponding class method.</span></li>
<li><a name="a1696"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">array </span><span class="src-doc">Associative array of run mode =&gt; method mappings</span></li>
<li><a name="a1697"></a><span class="src-doc">     */</span></li>
<li><a name="a1698"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodrun_modes">run_modes</a><span class="src-sym">(</span><span class="src-var">$data </span>= <span class="src-id">null</span><span class="src-sym">, </span><span class="src-var">$flag </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a1699"></a>    <span class="src-sym">{</span></li>
<li><a name="a1700"></a>        <span class="src-comm">// First use?  Create new _RUN_MODES!</span></li>
<li><a name="a1701"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_RUN_MODES</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1702"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_RUN_MODES </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1703"></a>        <span class="src-sym">}</span></li>
<li><a name="a1704"></a>&nbsp;</li>
<li><a name="a1705"></a>        <span class="src-var">$rr_m </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_RUN_MODES</span><span class="src-sym">;</span></li>
<li><a name="a1706"></a>&nbsp;</li>
<li><a name="a1707"></a>        <span class="src-comm">// If data is provided, set it!</span></li>
<li><a name="a1708"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1709"></a>            <span class="src-comm">// Received a hash; merge it with the current run modes</span></li>
<li><a name="a1710"></a>            <span class="src-var">$rr_m </span>= <a href="http://www.php.net/array_merge">array_merge</a><span class="src-sym">(</span><span class="src-var">$rr_m</span><span class="src-sym">, </span><span class="src-var">$data</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1711"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a1712"></a>            &amp;&amp; <span class="src-sym">((</span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>% <span class="src-num">2</span><span class="src-sym">) </span>== <span class="src-num">0</span><span class="src-sym">) </span></li>
<li><a name="a1713"></a>            &amp;&amp; <span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$flag</span><span class="src-sym">)) </span></li>
<li><a name="a1714"></a>        <span class="src-sym">{</span></li>
<li><a name="a1715"></a>            <span class="src-comm">// Received an even number of elements; create a hash out of them</span></li>
<li><a name="a1716"></a>            <span class="src-comm">// and merge with existing contents</span></li>
<li><a name="a1717"></a>            <span class="src-var">$rr_m </span>= <a href="http://www.php.net/array_merge">array_merge</a><span class="src-sym">(</span><span class="src-var">$rr_m</span><span class="src-sym">, </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">array_to_hash</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1718"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>&amp;&amp; <span class="src-var">$flag</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1719"></a>            <span class="src-comm">// Received an array and $flag is true; create an associative array</span></li>
<li><a name="a1720"></a>            <span class="src-comm">// where each element of data points to itself.</span></li>
<li><a name="a1721"></a>            <span class="src-var">$run_modes </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1722"></a>            <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-var">$data </span><span class="src-key">as </span><span class="src-var">$mode</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1723"></a>                <span class="src-comm">// Only assign if the method actually exists</span></li>
<li><a name="a1724"></a>                <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/method_exists">method_exists</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-var">$mode</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1725"></a>                    <span class="src-var">$run_modes</span><span class="src-sym">[</span><span class="src-var">$mode</span><span class="src-sym">] </span>= <span class="src-var">$mode</span><span class="src-sym">;</span></li>
<li><a name="a1726"></a>                <span class="src-sym">}</span></li>
<li><a name="a1727"></a>            <span class="src-sym">}</span></li>
<li><a name="a1728"></a>            <span class="src-var">$rr_m </span>= <a href="http://www.php.net/array_merge">array_merge</a><span class="src-sym">(</span><span class="src-var">$rr_m</span><span class="src-sym">, </span><span class="src-var">$run_modes</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1729"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1730"></a>            <span class="src-comm">// Don't quite understand what we got here...</span></li>
<li><a name="a1731"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Odd number of elements passed to run_modes().  Not a valid hash&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1732"></a>        <span class="src-sym">}</span></li>
<li><a name="a1733"></a>&nbsp;</li>
<li><a name="a1734"></a>        <span class="src-comm">// If we've gotten this far, return the value!</span></li>
<li><a name="a1735"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_RUN_MODES </span>= <span class="src-var">$rr_m</span><span class="src-sym">;</span></li>
<li><a name="a1736"></a>        <span class="src-key">return </span><span class="src-var">$rr_m</span><span class="src-sym">;</span></li>
<li><a name="a1737"></a>    <span class="src-sym">}</span></li>
<li><a name="a1738"></a>&nbsp;</li>
<li><a name="a1739"></a>&nbsp;</li>
<li><a name="a1740"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1741"></a><span class="src-doc">     * Set the default run mode to use when no run mode is specified by the</span></li>
<li><a name="a1742"></a><span class="src-doc">     * client</span></li>
<li><a name="a1743"></a><span class="src-doc">     *</span></li>
<li><a name="a1744"></a><span class="src-doc">     * The start_mode() contains the name of the mode as specified in the</span></li>
<li><a name="a1745"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link run_modes()}</span><span class="src-doc"> table.  Default mode is &quot;start&quot;.  The mode key</span></li>
<li><a name="a1746"></a><span class="src-doc">     * specified here will be used whenever the value of the CGI form parameter</span></li>
<li><a name="a1747"></a><span class="src-doc">     * specified by </span><span class="src-doc-inlinetag">{@link mode_param()}</span><span class="src-doc"> is not defined.  Generally, this is the</span></li>
<li><a name="a1748"></a><span class="src-doc">     * first time your application is executed.</span></li>
<li><a name="a1749"></a><span class="src-doc">     * </span></li>
<li><a name="a1750"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1751"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1752"></a><span class="src-doc">     *     $webapp-&gt;start_mode('mode1');</span></li>
<li><a name="a1753"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1754"></a><span class="src-doc">     * </span></li>
<li><a name="a1755"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$start_mode </span><span class="src-doc">Optional; the name of the default run mode</span></li>
<li><a name="a1756"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">Name of the default run mode</span></li>
<li><a name="a1757"></a><span class="src-doc">     */</span></li>
<li><a name="a1758"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodstart_mode">start_mode</a><span class="src-sym">(</span><span class="src-var">$start_mode </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a1759"></a>    <span class="src-sym">{</span></li>
<li><a name="a1760"></a>        <span class="src-comm">// First use?  Create new _START_MODE!</span></li>
<li><a name="a1761"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_START_MODE</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1762"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_START_MODE </span>= <span class="src-str">'start'</span><span class="src-sym">;</span></li>
<li><a name="a1763"></a>        <span class="src-sym">}</span></li>
<li><a name="a1764"></a>&nbsp;</li>
<li><a name="a1765"></a>        <span class="src-comm">// If data is provided, set it!</span></li>
<li><a name="a1766"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$start_mode</span><span class="src-sym">) </span>&amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$start_mode</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1767"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_START_MODE </span>= <span class="src-var">$start_mode</span><span class="src-sym">;</span></li>
<li><a name="a1768"></a>        <span class="src-sym">}</span></li>
<li><a name="a1769"></a>&nbsp;</li>
<li><a name="a1770"></a>        <span class="src-comm">// If we've gotten this far, return the value!</span></li>
<li><a name="a1771"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_START_MODE</span><span class="src-sym">;</span></li>
<li><a name="a1772"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1773"></a>&nbsp;</li>
<li><a name="a1774"></a>&nbsp;</li>
<li><a name="a1775"></a>&nbsp;</li>
<li><a name="a1776"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1777"></a><span class="src-doc">     * Override the run mode that was passed to the application</span></li>
<li><a name="a1778"></a><span class="src-doc">     * </span></li>
<li><a name="a1779"></a><span class="src-doc">     * The prerun_mode() method is an accessor/mutator which can be used within</span></li>
<li><a name="a1780"></a><span class="src-doc">     * your </span><span class="src-doc-inlinetag">{@link cgiapp_prerun()}</span><span class="src-doc"> method to change the run mode which is about</span></li>
<li><a name="a1781"></a><span class="src-doc">     * to be executed.  For example, consider:</span></li>
<li><a name="a1782"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1783"></a><span class="src-doc">     *     // In WebApp.pm:</span></li>
<li><a name="a1784"></a><span class="src-doc">     *     require_once 'Cgiapp2.class.php';</span></li>
<li><a name="a1785"></a><span class="src-doc">     *     class WebApp extends Cgiapp2</span></li>
<li><a name="a1786"></a><span class="src-doc">     *     {</span></li>
<li><a name="a1787"></a><span class="src-doc">     *         function cgiapp_prerun($rm)</span></li>
<li><a name="a1788"></a><span class="src-doc">     *         {</span></li>
<li><a name="a1789"></a><span class="src-doc">     *             # Get the web user name, if any</span></li>
<li><a name="a1790"></a><span class="src-doc">     *             $user = $this-&gt;s_param('remote_user');</span></li>
<li><a name="a1791"></a><span class="src-doc">     *       </span></li>
<li><a name="a1792"></a><span class="src-doc">     *             # Redirect to login, if necessary</span></li>
<li><a name="a1793"></a><span class="src-doc">     *             if (!$user) {</span></li>
<li><a name="a1794"></a><span class="src-doc">     *                 $this-&gt;prerun_mode('login');</span></li>
<li><a name="a1795"></a><span class="src-doc">     *             }</span></li>
<li><a name="a1796"></a><span class="src-doc">     *         }</span></li>
<li><a name="a1797"></a><span class="src-doc">     *     }</span></li>
<li><a name="a1798"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1799"></a><span class="src-doc">     * In this example, the web user will be forced into the &quot;login&quot; run mode</span></li>
<li><a name="a1800"></a><span class="src-doc">     * unless they have already logged in.  The prerun_mode() method permits a</span></li>
<li><a name="a1801"></a><span class="src-doc">     * scalar text string to be set which overrides whatever the run mode would</span></li>
<li><a name="a1802"></a><span class="src-doc">     * otherwise be.</span></li>
<li><a name="a1803"></a><span class="src-doc">     * </span></li>
<li><a name="a1804"></a><span class="src-doc">     * The use of prerun_mode() within </span><span class="src-doc-inlinetag">{@link cgiapp_prerun()}</span><span class="src-doc"> differs from</span></li>
<li><a name="a1805"></a><span class="src-doc">     * setting </span><span class="src-doc-inlinetag">{@link mode_param()}</span><span class="src-doc"> to use a call-back via subroutine reference.</span></li>
<li><a name="a1806"></a><span class="src-doc">     * It differs because </span><span class="src-doc-inlinetag">{@link cgiapp_prerun()}</span><span class="src-doc"> allows you to selectively set</span></li>
<li><a name="a1807"></a><span class="src-doc">     * the run mode based on some logic in your </span><span class="src-doc-inlinetag">{@link cgiapp_prerun()}</span><span class="src-doc"> method.</span></li>
<li><a name="a1808"></a><span class="src-doc">     * The call-back facility of </span><span class="src-doc-inlinetag">{@link mode_param()}</span><span class="src-doc"> forces you to entirely</span></li>
<li><a name="a1809"></a><span class="src-doc">     * replace Cgiapp2's mechanism for determining the run mode with your own</span></li>
<li><a name="a1810"></a><span class="src-doc">     * method.  The prerun_mode() method should be used in cases where you want</span></li>
<li><a name="a1811"></a><span class="src-doc">     * to use Cgiapp2's normal run mode switching facility, but you want to make</span></li>
<li><a name="a1812"></a><span class="src-doc">     * selective changes to the mode under specific conditions.</span></li>
<li><a name="a1813"></a><span class="src-doc">     * </span></li>
<li><a name="a1814"></a><span class="src-doc">     * &lt;b&gt;Note:&lt;/b&gt;  The prerun_mode() method may ONLY be called in the context</span></li>
<li><a name="a1815"></a><span class="src-doc">     * of a </span><span class="src-doc-inlinetag">{@link cgiapp_prerun()}</span><span class="src-doc"> method.  Your application will die() if you</span></li>
<li><a name="a1816"></a><span class="src-doc">     * call prerun_mode() elsewhere, such as in </span><span class="src-doc-inlinetag">{@link setup()}</span><span class="src-doc"> or a run mode</span></li>
<li><a name="a1817"></a><span class="src-doc">     * method.</span></li>
<li><a name="a1818"></a><span class="src-doc">     * </span></li>
<li><a name="a1819"></a><span class="src-doc">     * &lt;b&gt;Example usage&lt;/b&gt;</span></li>
<li><a name="a1820"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1821"></a><span class="src-doc">     *     $webapp-&gt;prerun_mode('new_run_mode');</span></li>
<li><a name="a1822"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1823"></a><span class="src-doc">     * </span></li>
<li><a name="a1824"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$prerun_mode </span><span class="src-doc">String containing name of the new run mode to</span></li>
<li><a name="a1825"></a><span class="src-doc">     *  be used</span></li>
<li><a name="a1826"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">Name of the run mode that will override the requested run</span></li>
<li><a name="a1827"></a><span class="src-doc">     *  mode</span></li>
<li><a name="a1828"></a><span class="src-doc">     */</span></li>
<li><a name="a1829"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodprerun_mode">prerun_mode</a><span class="src-sym">(</span><span class="src-var">$prerun_mode </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a1830"></a>    <span class="src-sym">{</span></li>
<li><a name="a1831"></a>        <span class="src-comm">// First use?  Create new _PRERUN_MODE</span></li>
<li><a name="a1832"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1833"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE </span>= <span class="src-str">''</span><span class="src-sym">;</span></li>
<li><a name="a1834"></a>        <span class="src-sym">}</span></li>
<li><a name="a1835"></a>&nbsp;</li>
<li><a name="a1836"></a>        <span class="src-comm">// Was data provided?</span></li>
<li><a name="a1837"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$prerun_mode</span><span class="src-sym">) </span>&amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$prerun_mode</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1838"></a>            <span class="src-comm">// Are we allowed to set prerun_mode?</span></li>
<li><a name="a1839"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE_LOCKED</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1840"></a>                <span class="src-comm">// Not allowed!  Throw an exception.</span></li>
<li><a name="a1841"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">&quot;prerun_mode() can only be called within cgiapp_prerun()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1842"></a>                <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a1843"></a>            <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a1844"></a>                <span class="src-comm">// If data is provided, set it!</span></li>
<li><a name="a1845"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE </span>= <span class="src-var">$prerun_mode</span><span class="src-sym">;</span></li>
<li><a name="a1846"></a>            <span class="src-sym">}</span></li>
<li><a name="a1847"></a>        <span class="src-sym">}</span></li>
<li><a name="a1848"></a>&nbsp;</li>
<li><a name="a1849"></a>        <span class="src-comm">// If we've gotten this far, return the value!</span></li>
<li><a name="a1850"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PRERUN_MODE</span><span class="src-sym">;</span></li>
<li><a name="a1851"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1852"></a>&nbsp;</li>
<li><a name="a1853"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1854"></a><span class="src-doc">     * Reset the body contents post-run mode, but prior to returning or echoing</span></li>
<li><a name="a1855"></a><span class="src-doc">     * the value. Use this method from </span><span class="src-doc-inlinetag">{@link cgiapp_postrun()}</span><span class="src-doc"> or a postrun</span></li>
<li><a name="a1856"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link call_hook() callback hook}</span><span class="src-doc"> to reset the content returned by the</span></li>
<li><a name="a1857"></a><span class="src-doc">     * run mode. A typical usage would be to place the content in a sitewide</span></li>
<li><a name="a1858"></a><span class="src-doc">     * template.</span></li>
<li><a name="a1859"></a><span class="src-doc">     * </span></li>
<li><a name="a1860"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@final</span></li>
<li><a name="a1861"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a1862"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$body </span></li>
<li><a name="a1863"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">void </span></li>
<li><a name="a1864"></a><span class="src-doc">     */</span></li>
<li><a name="a1865"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodpostrun_body">postrun_body</a><span class="src-sym">(</span><span class="src-var">$body</span><span class="src-sym">)</span></li>
<li><a name="a1866"></a>    <span class="src-sym">{</span></li>
<li><a name="a1867"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_POSTRUN_MODE_LOCKED</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a1868"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">croak</span><span class="src-sym">(</span><span class="src-str">'postrun_body() can only be called from cgiapp_postrun() or a postrun callback hook'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1869"></a>            <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a1870"></a>        <span class="src-sym">}</span></li>
<li><a name="a1871"></a>&nbsp;</li>
<li><a name="a1872"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">__body </span>= <span class="src-var">$body</span><span class="src-sym">;</span></li>
<li><a name="a1873"></a>    <span class="src-sym">}</span></li>
<li><a name="a1874"></a>&nbsp;</li>
<li><a name="a1875"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1876"></a><span class="src-doc">     * Display the currently selected run mode</span></li>
<li><a name="a1877"></a><span class="src-doc">     * </span></li>
<li><a name="a1878"></a><span class="src-doc">     * The get_current_runmode() method will return a text scalar containing the</span></li>
<li><a name="a1879"></a><span class="src-doc">     * name of the run mode which is currently being executed.  If the run mode</span></li>
<li><a name="a1880"></a><span class="src-doc">     * has not yet been determined, such as during </span><span class="src-doc-inlinetag">{@link setup()}</span><span class="src-doc">, this method</span></li>
<li><a name="a1881"></a><span class="src-doc">     * will return undef.</span></li>
<li><a name="a1882"></a><span class="src-doc">     *</span></li>
<li><a name="a1883"></a><span class="src-doc">     * &lt;b&gt;Example usage&lt;/b&gt;</span></li>
<li><a name="a1884"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1885"></a><span class="src-doc">     *     $webapp-&gt;get_current_runmode();</span></li>
<li><a name="a1886"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1887"></a><span class="src-doc">     * </span></li>
<li><a name="a1888"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">Name of currently selected run mode</span></li>
<li><a name="a1889"></a><span class="src-doc">     */</span></li>
<li><a name="a1890"></a>    <span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodget_current_runmode">get_current_runmode</a><span class="src-sym">(</span><span class="src-sym">)</span></li>
<li><a name="a1891"></a>    <span class="src-sym">{</span></li>
<li><a name="a1892"></a>        <span class="src-comm">// It's OK if we return undef if this method is called too early</span></li>
<li><a name="a1893"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_CURRENT_RUNMODE</span><span class="src-sym">;</span></li>
<li><a name="a1894"></a>    <span class="src-sym">}    </span></li>
<li><a name="a1895"></a>&nbsp;</li>
<li><a name="a1896"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1897"></a><span class="src-doc">     * Set or retrieve the method to use for handling errors</span></li>
<li><a name="a1898"></a><span class="src-doc">     * </span></li>
<li><a name="a1899"></a><span class="src-doc">     * The error_mode() contains the name of a run mode to call in the event</span></li>
<li><a name="a1900"></a><span class="src-doc">     * that the planned run mode call fails. No error_mode is defined by</span></li>
<li><a name="a1901"></a><span class="src-doc">     * default. The death of your error_mode() run mode is not trapped, so you</span></li>
<li><a name="a1902"></a><span class="src-doc">     * can also use it to die in your own special way.</span></li>
<li><a name="a1903"></a><span class="src-doc">     * </span></li>
<li><a name="a1904"></a><span class="src-doc">     * error_mode() is used in the </span><span class="src-doc-inlinetag">{@link run()}</span><span class="src-doc"> method. If your run mode (or a</span></li>
<li><a name="a1905"></a><span class="src-doc">     * method it calls) generates an exception, error_mode() is called to</span></li>
<li><a name="a1906"></a><span class="src-doc">     * determine a method to run that should generate the content to return to</span></li>
<li><a name="a1907"></a><span class="src-doc">     * the user (i.e., the method should act like a run mode).</span></li>
<li><a name="a1908"></a><span class="src-doc">     * </span></li>
<li><a name="a1909"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$error_mode </span></li>
<li><a name="a1910"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span></li>
<li><a name="a1911"></a><span class="src-doc">     */</span></li>
<li><a name="a1912"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methoderror_mode">error_mode</a><span class="src-sym">(</span><span class="src-var">$error_mode </span>= <span class="src-id">null</span><span class="src-sym">)</span></li>
<li><a name="a1913"></a>    <span class="src-sym">{</span></li>
<li><a name="a1914"></a>        <span class="src-comm">// First use?  Create new __ERROR_MODE</span></li>
<li><a name="a1915"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_ERROR_MODE</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a1916"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_ERROR_MODE </span>= <span class="src-str">''</span><span class="src-sym">;</span></li>
<li><a name="a1917"></a>        <span class="src-sym">}</span></li>
<li><a name="a1918"></a>&nbsp;</li>
<li><a name="a1919"></a>        <span class="src-comm">// If data is provided, and the method exists, set it</span></li>
<li><a name="a1920"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$error_mode</span><span class="src-sym">) </span></li>
<li><a name="a1921"></a>            &amp;&amp; <a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$error_mode</span><span class="src-sym">) </span></li>
<li><a name="a1922"></a>            &amp;&amp; <a href="http://www.php.net/method_exists">method_exists</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">, </span><span class="src-var">$error_mode</span><span class="src-sym">))</span></li>
<li><a name="a1923"></a>        <span class="src-sym">{</span></li>
<li><a name="a1924"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_ERROR_MODE </span>= <span class="src-var">$error_mode</span><span class="src-sym">;</span></li>
<li><a name="a1925"></a>        <span class="src-sym">}</span></li>
<li><a name="a1926"></a>&nbsp;</li>
<li><a name="a1927"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_ERROR_MODE</span><span class="src-sym">;</span></li>
<li><a name="a1928"></a>    <span class="src-sym">}</span></li>
<li><a name="a1929"></a>&nbsp;</li>
<li><a name="a1930"></a>    <span class="src-doc">/**</span></li>
<li><a name="a1931"></a><span class="src-doc">     * Set one or more application parameters; retrieve an application</span></li>
<li><a name="a1932"></a><span class="src-doc">     * parameter; or retrieve a list of available application parameters</span></li>
<li><a name="a1933"></a><span class="src-doc">     *</span></li>
<li><a name="a1934"></a><span class="src-doc">     * The param() method provides a facility through which you may set</span></li>
<li><a name="a1935"></a><span class="src-doc">     * application instance properties which are accessible throughout</span></li>
<li><a name="a1936"></a><span class="src-doc">     * your application.</span></li>
<li><a name="a1937"></a><span class="src-doc">     * </span></li>
<li><a name="a1938"></a><span class="src-doc">     * The param() method may be used in two basic ways.  First, you may use it</span></li>
<li><a name="a1939"></a><span class="src-doc">     * to get or set the value of a parameter:</span></li>
<li><a name="a1940"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1941"></a><span class="src-doc">     *     $webapp-&gt;param('scalar_param', '123');</span></li>
<li><a name="a1942"></a><span class="src-doc">     *     $scalar_param_values = $webapp-&gt;param('some_param');</span></li>
<li><a name="a1943"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1944"></a><span class="src-doc">     * Second, when called in the context of an array, with no parameter name</span></li>
<li><a name="a1945"></a><span class="src-doc">     * specified, param() returns an array containing all the parameters which</span></li>
<li><a name="a1946"></a><span class="src-doc">     * currently exist:</span></li>
<li><a name="a1947"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1948"></a><span class="src-doc">     *     $all_params = $webapp-&gt;param();</span></li>
<li><a name="a1949"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1950"></a><span class="src-doc">     * The param() method also allows you to set a bunch of parameters at once</span></li>
<li><a name="a1951"></a><span class="src-doc">     * by passing in an associative array or array:</span></li>
<li><a name="a1952"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1953"></a><span class="src-doc">     *     $webapp-&gt;param(array(</span></li>
<li><a name="a1954"></a><span class="src-doc">     *         'key1' =&gt; 'val1',</span></li>
<li><a name="a1955"></a><span class="src-doc">     *         'key2' =&gt; 'val2',</span></li>
<li><a name="a1956"></a><span class="src-doc">     *         'key3' =&gt; 'val3'</span></li>
<li><a name="a1957"></a><span class="src-doc">     *     ));</span></li>
<li><a name="a1958"></a><span class="src-doc">     * </span></li>
<li><a name="a1959"></a><span class="src-doc">     *     // or</span></li>
<li><a name="a1960"></a><span class="src-doc">     * </span></li>
<li><a name="a1961"></a><span class="src-doc">     *     $webapp-&gt;param(array(</span></li>
<li><a name="a1962"></a><span class="src-doc">     *         'key1', 'val1',</span></li>
<li><a name="a1963"></a><span class="src-doc">     *         'key2', 'val2',</span></li>
<li><a name="a1964"></a><span class="src-doc">     *         'key3', 'val3'</span></li>
<li><a name="a1965"></a><span class="src-doc">     *     ));</span></li>
<li><a name="a1966"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1967"></a><span class="src-doc">     * The param() method enables a very valuable system for customizing your</span></li>
<li><a name="a1968"></a><span class="src-doc">     * applications on a per-instance basis.  One Application Class might be</span></li>
<li><a name="a1969"></a><span class="src-doc">     * instantiated by different Instance Scripts.  Each Instance Script might</span></li>
<li><a name="a1970"></a><span class="src-doc">     * set different values for a set of parameters.  This allows similar</span></li>
<li><a name="a1971"></a><span class="src-doc">     * applications to share a common code-base, but behave differently.  For</span></li>
<li><a name="a1972"></a><span class="src-doc">     * example, imagine a mail form application with a single Application Class,</span></li>
<li><a name="a1973"></a><span class="src-doc">     * but multiple Instance Scripts.  Each Instance Script might specify a</span></li>
<li><a name="a1974"></a><span class="src-doc">     * different recipient.  Another example would be a web bulletin boards</span></li>
<li><a name="a1975"></a><span class="src-doc">     * system.  There could be multiple boards, each with a different topic and</span></li>
<li><a name="a1976"></a><span class="src-doc">     * set of administrators.</span></li>
<li><a name="a1977"></a><span class="src-doc">     * </span></li>
<li><a name="a1978"></a><span class="src-doc">     * The constructor method provides a shortcut for specifying a number of</span></li>
<li><a name="a1979"></a><span class="src-doc">     * run-time parameters at once.  Internally, Cgiapp2 calls the param() method</span></li>
<li><a name="a1980"></a><span class="src-doc">     * to set these properties.  The param() method is a powerful tool for</span></li>
<li><a name="a1981"></a><span class="src-doc">     * greatly increasing your application's re-usability.</span></li>
<li><a name="a1982"></a><span class="src-doc">     * </span></li>
<li><a name="a1983"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a1984"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a1985"></a><span class="src-doc">     *     $webapp-&gt;param('pname', $somevalue);</span></li>
<li><a name="a1986"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a1987"></a><span class="src-doc">     * </span></li>
<li><a name="a1988"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">mixed </span><span class="src-doc-var">$data </span><span class="src-doc">Optional</span></li>
<li><a name="a1989"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">mixed </span><span class="src-doc">What is returned depends on what is given; see the docs</span></li>
<li><a name="a1990"></a><span class="src-doc">     */</span></li>
<li><a name="a1991"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-sym">) </span></li>
<li><a name="a1992"></a>    <span class="src-sym">{</span></li>
<li><a name="a1993"></a>        <span class="src-comm">// param(): set or return an object property. This method normalizes the</span></li>
<li><a name="a1994"></a>        <span class="src-comm">// property name (to upper case), and allows setting either a single</span></li>
<li><a name="a1995"></a>        <span class="src-comm">// parameter (param($key, $val)) or multiple parameters (my passing</span></li>
<li><a name="a1996"></a>        <span class="src-comm">// either an associative array or an even-count array with ($key, $val,</span></li>
<li><a name="a1997"></a>        <span class="src-comm">// $key2, $val2) structure). Calling it with an empty string returns a</span></li>
<li><a name="a1998"></a>        <span class="src-comm">// list of all parameters that have been registered with it. Calling it</span></li>
<li><a name="a1999"></a>        <span class="src-comm">// with the name of an unregistered paremeter</span></li>
<li><a name="a2000"></a>        <span class="src-comm">// ($this-&gt;param('param_name')) will return false.</span></li>
<li><a name="a2001"></a>&nbsp;</li>
<li><a name="a2002"></a>        <span class="src-comm">// First use?  Create new _PARAMS!</span></li>
<li><a name="a2003"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PARAMS</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2004"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PARAMS </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2005"></a>        <span class="src-sym">}</span></li>
<li><a name="a2006"></a>&nbsp;</li>
<li><a name="a2007"></a>        <span class="src-var">$rp </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PARAMS</span><span class="src-sym">;</span></li>
<li><a name="a2008"></a>&nbsp;</li>
<li><a name="a2009"></a>        <span class="src-comm">// Determine how many arguments were sent</span></li>
<li><a name="a2010"></a>        <span class="src-var">$numargs </span>= <a href="http://www.php.net/func_num_args">func_num_args</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2011"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-num">0 </span>== <span class="src-var">$numargs</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2012"></a>            <span class="src-comm">// If no values passed, return the list of parameters</span></li>
<li><a name="a2013"></a>            <span class="src-var">$params </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2014"></a>            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$rp </span><span class="src-key">as </span><span class="src-var">$idx </span>=&gt; <span class="src-var">$param</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2015"></a>                <span class="src-var">$params</span><span class="src-sym">[</span><span class="src-var">$idx</span><span class="src-sym">] </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$idx</span><span class="src-sym">;</span></li>
<li><a name="a2016"></a>            <span class="src-sym">}</span></li>
<li><a name="a2017"></a>            <span class="src-key">return </span><span class="src-var">$params</span><span class="src-sym">;</span></li>
<li><a name="a2018"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-num">1 </span>== <span class="src-var">$numargs</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2019"></a>            <span class="src-comm">// one argument passed to param; grab it.</span></li>
<li><a name="a2020"></a>            <span class="src-var">$data </span>= <a href="http://www.php.net/func_get_arg">func_get_arg</a><span class="src-sym">(</span><span class="src-num">0</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2021"></a>            <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2022"></a>                <span class="src-comm">// Argument is a scalar</span></li>
<li><a name="a2023"></a>                <span class="src-var">$data </span>= <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2024"></a>                <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$rp</span><span class="src-sym">[</span><span class="src-var">$data</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2025"></a>                    <span class="src-comm">// Argument is in parameter list; return it</span></li>
<li><a name="a2026"></a>                    <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$data</span><span class="src-sym">;</span></li>
<li><a name="a2027"></a>                <span class="src-sym">}</span></li>
<li><a name="a2028"></a>&nbsp;</li>
<li><a name="a2029"></a>                <span class="src-comm">// Argument is not in parameter list; return false</span></li>
<li><a name="a2030"></a>                <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2031"></a>            <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2032"></a>                <span class="src-comm">// Object sent to param; error!</span></li>
<li><a name="a2033"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Bad arguments (object) sent to param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2034"></a>                <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a2035"></a>            <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a2036"></a>                &amp;&amp; <span class="src-sym">(</span><span class="src-num">0 </span>== <span class="src-sym">(</span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>% <span class="src-num">2</span><span class="src-sym">)))</span></li>
<li><a name="a2037"></a>            <span class="src-sym">{</span></li>
<li><a name="a2038"></a>                <span class="src-comm">// even-indexed array passed to method; turn it into a hash</span></li>
<li><a name="a2039"></a>                <span class="src-var">$data </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">array_to_hash</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2040"></a>            <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a2041"></a>                &amp;&amp; <span class="src-sym">(</span><span class="src-num">0 </span>!= <span class="src-sym">(</span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>% <span class="src-num">2</span><span class="src-sym">)))</span></li>
<li><a name="a2042"></a>            <span class="src-sym">{</span></li>
<li><a name="a2043"></a>                <span class="src-comm">// odd-indexed array passed to method -- error!</span></li>
<li><a name="a2044"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Bad arguments (array) sent to param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2045"></a>                <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a2046"></a>            <span class="src-sym">}</span></li>
<li><a name="a2047"></a>&nbsp;</li>
<li><a name="a2048"></a>            <span class="src-comm">// At this point, we know we have an associative array.</span></li>
<li><a name="a2049"></a>            <span class="src-comm">// Initialize each parameter in it and add it to our parameter list</span></li>
<li><a name="a2050"></a>            <span class="src-var">$params </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2051"></a>            <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-var">$data </span><span class="src-key">as </span><span class="src-var">$key </span>=&gt; <span class="src-var">$val</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2052"></a>                <span class="src-var">$key          </span>= <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">))</span><span class="src-sym">; </span><span class="src-comm">// normalize the key</span></li>
<li><a name="a2053"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key   </span>= <span class="src-var">$val</span><span class="src-sym">;                   </span><span class="src-comm">// set the property</span></li>
<li><a name="a2054"></a>                <span class="src-var">$params</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>= <span class="src-id">true</span><span class="src-sym">;                   </span><span class="src-comm">// store param for later</span></li>
<li><a name="a2055"></a>            <span class="src-sym">}</span></li>
<li><a name="a2056"></a>            <span class="src-var">$rp </span>= <a href="http://www.php.net/array_merge">array_merge</a><span class="src-sym">(</span><span class="src-var">$rp</span><span class="src-sym">, </span><span class="src-var">$params</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2057"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-num">2 </span>== <span class="src-var">$numargs</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2058"></a>            <span class="src-comm">// Two arguments passed</span></li>
<li><a name="a2059"></a>            <span class="src-var">$key </span>= <a href="http://www.php.net/func_get_arg">func_get_arg</a><span class="src-sym">(</span><span class="src-num">0</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2060"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2061"></a>                <span class="src-comm">// Non-scalar key sent -- error</span></li>
<li><a name="a2062"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Bad key (non-string) sent to param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2063"></a>                <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a2064"></a>            <span class="src-sym">}</span></li>
<li><a name="a2065"></a>            <span class="src-var">$key        </span>= <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2066"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key </span>= <a href="http://www.php.net/func_get_arg">func_get_arg</a><span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2067"></a>            <span class="src-var">$rp         </span>= <a href="http://www.php.net/array_merge">array_merge</a><span class="src-sym">(</span><span class="src-var">$rp</span><span class="src-sym">, </span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$key </span>=&gt; <span class="src-id">true</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2068"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a2069"></a>            <span class="src-comm">// Two many arguments sent to param.</span></li>
<li><a name="a2070"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Too many arguments sent to param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2071"></a>            <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a2072"></a>        <span class="src-sym">}</span></li>
<li><a name="a2073"></a>&nbsp;</li>
<li><a name="a2074"></a>        <span class="src-comm">// If we got here, we set one or more parameters; set the attribute</span></li>
<li><a name="a2075"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PARAMS </span>= <span class="src-var">$rp</span><span class="src-sym">;</span></li>
<li><a name="a2076"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a2077"></a>    <span class="src-sym">}</span></li>
<li><a name="a2078"></a>&nbsp;</li>
<li><a name="a2079"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2080"></a><span class="src-doc">     * Delete an application parameter</span></li>
<li><a name="a2081"></a><span class="src-doc">     * </span></li>
<li><a name="a2082"></a><span class="src-doc">     * The delete() method is used to delete a parameter that was previously</span></li>
<li><a name="a2083"></a><span class="src-doc">     * stored inside of your application either by using the PARAMS associative</span></li>
<li><a name="a2084"></a><span class="src-doc">     * array that was passed when instantiating the object or by a call to the</span></li>
<li><a name="a2085"></a><span class="src-doc">     * </span><span class="src-doc-inlinetag">{@link param()}</span><span class="src-doc"> method.  It is useful if your application makes decisions</span></li>
<li><a name="a2086"></a><span class="src-doc">     * based on the existence of certain params that may have been removed in</span></li>
<li><a name="a2087"></a><span class="src-doc">     * previous sections of your app or simply to clean-up your param()s.</span></li>
<li><a name="a2088"></a><span class="src-doc">     * </span></li>
<li><a name="a2089"></a><span class="src-doc">     * &lt;b&gt;Example usage:&lt;/b&gt;</span></li>
<li><a name="a2090"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a2091"></a><span class="src-doc">     *     $webapp-&gt;delete('my_param');</span></li>
<li><a name="a2092"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a2093"></a><span class="src-doc">     * </span></li>
<li><a name="a2094"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$key </span><span class="src-doc">The name of the parameter to delete</span></li>
<li><a name="a2095"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">bool </span></li>
<li><a name="a2096"></a><span class="src-doc">     */</span></li>
<li><a name="a2097"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methoddelete">delete</a><span class="src-sym">(</span><span class="src-var">$key </span>= <span class="src-id">null</span><span class="src-sym">)</span></li>
<li><a name="a2098"></a>    <span class="src-sym">{</span></li>
<li><a name="a2099"></a>        <span class="src-comm">// Is the _PARAMS property set? if not, return</span></li>
<li><a name="a2100"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PARAMS</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2101"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">'Cannot call delete without params'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2102"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2103"></a>        <span class="src-sym">}</span></li>
<li><a name="a2104"></a>&nbsp;</li>
<li><a name="a2105"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2106"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">'Called delete without key'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2107"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2108"></a>        <span class="src-sym">}</span></li>
<li><a name="a2109"></a>&nbsp;</li>
<li><a name="a2110"></a>        <span class="src-var">$key </span>= <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2111"></a>        <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PARAMS</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2112"></a>            unset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">_PARAMS</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2113"></a>            unset<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2114"></a>            <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a2115"></a>        <span class="src-sym">}</span></li>
<li><a name="a2116"></a>&nbsp;</li>
<li><a name="a2117"></a>        <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2118"></a>    <span class="src-sym">}</span></li>
<li><a name="a2119"></a>&nbsp;</li>
<li><a name="a2120"></a>&nbsp;</li>
<li><a name="a2121"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2122"></a><span class="src-doc">     * Add, list, or retrieve session parameters</span></li>
<li><a name="a2123"></a><span class="src-doc">     * </span></li>
<li><a name="a2124"></a><span class="src-doc">     * Similar to </span><span class="src-doc-inlinetag">{@link param()}</span><span class="src-doc">, s_param() sets a session parameter for use</span></li>
<li><a name="a2125"></a><span class="src-doc">     * with the application.  Internally, it does the following:</span></li>
<li><a name="a2126"></a><span class="src-doc">     * &lt;ul&gt;</span></li>
<li><a name="a2127"></a><span class="src-doc">     *     &lt;li&gt;Checks to see if session handling is active; if not, it</span></li>
<li><a name="a2128"></a><span class="src-doc">     *         produces a warning and returns false.&lt;/li&gt;</span></li>
<li><a name="a2129"></a><span class="src-doc">     *     &lt;li&gt;Determines the session ID:</span></li>
<li><a name="a2130"></a><span class="src-doc">     *         &lt;ul&gt;</span></li>
<li><a name="a2131"></a><span class="src-doc">     *             &lt;li&gt;It checks for the existence of a parameter called</span></li>
<li><a name="a2132"></a><span class="src-doc">     *                 '</span><span class="src-doc-inlinetag">{@link $_SESSION_ID}</span><span class="src-doc">' and fetches it if found;&lt;/li&gt;</span></li>
<li><a name="a2133"></a><span class="src-doc">     *             &lt;li&gt;If the </span><span class="src-doc-inlinetag">{@link $_SESSION_ID}</span><span class="src-doc"> parameter is *not* found,</span></li>
<li><a name="a2134"></a><span class="src-doc">     *                 call PHP's session_name() and use that value.&lt;/li&gt;</span></li>
<li><a name="a2135"></a><span class="src-doc">     *         &lt;/ul&gt;</span></li>
<li><a name="a2136"></a><span class="src-doc">     *     &lt;/li&gt;</span></li>
<li><a name="a2137"></a><span class="src-doc">     *     &lt;li&gt;If no values are passed, returns an array of all $_SESSION</span></li>
<li><a name="a2138"></a><span class="src-doc">     *         variables, whether or not they were set with the s_param</span></li>
<li><a name="a2139"></a><span class="src-doc">     *         method.&lt;/li&gt;</span></li>
<li><a name="a2140"></a><span class="src-doc">     *     &lt;li&gt;If a single string value is passed to the method, prepend the</span></li>
<li><a name="a2141"></a><span class="src-doc">     *         </span><span class="src-doc-inlinetag">{@link $_SESSION_ID}</span><span class="src-doc"> to the value and return the value of that</span></li>
<li><a name="a2142"></a><span class="src-doc">     *         session key; if the session key does not exist, return false; if</span></li>
<li><a name="a2143"></a><span class="src-doc">     *         the session key is invalid (array, object), emit a warning.&lt;/li&gt;</span></li>
<li><a name="a2144"></a><span class="src-doc">     *     &lt;li&gt;If two values are passed to the method, and the first value is a</span></li>
<li><a name="a2145"></a><span class="src-doc">     *         string, prepend the </span><span class="src-doc-inlinetag">{@link $_SESSION_ID}</span><span class="src-doc"> to the first value and</span></li>
<li><a name="a2146"></a><span class="src-doc">     *         set a session variable with that name and assign it a value of</span></li>
<li><a name="a2147"></a><span class="src-doc">     *         the second parameter sent to s_param().&lt;/li&gt;</span></li>
<li><a name="a2148"></a><span class="src-doc">     *     &lt;li&gt;If an associative array is passed to the method, prepend each key</span></li>
<li><a name="a2149"></a><span class="src-doc">     *         with the </span><span class="src-doc-inlinetag">{@link $_SESSION_ID}</span><span class="src-doc"> and create session variables with</span></li>
<li><a name="a2150"></a><span class="src-doc">     *         each key and value.&lt;/li&gt;</span></li>
<li><a name="a2151"></a><span class="src-doc">     *     &lt;li&gt;If an array with an even number of elements is passed to the</span></li>
<li><a name="a2152"></a><span class="src-doc">     *         method, use </span><span class="src-doc-inlinetag">{@link array_to_hash()}</span><span class="src-doc"> to create an associative</span></li>
<li><a name="a2153"></a><span class="src-doc">     *         array out of it, and do the same as the above.&lt;/li&gt;</span></li>
<li><a name="a2154"></a><span class="src-doc">     *     &lt;li&gt;If more than two values are passed, emit a warning.&lt;/li&gt;</span></li>
<li><a name="a2155"></a><span class="src-doc">     * &lt;/ul&gt;</span></li>
<li><a name="a2156"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">mixed </span><span class="src-doc-var">$data </span><span class="src-doc">Optional</span></li>
<li><a name="a2157"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">mixed </span><span class="src-doc">What is returned depends on what is given; see the docs</span></li>
<li><a name="a2158"></a><span class="src-doc">     */</span></li>
<li><a name="a2159"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methods_param">s_param</a><span class="src-sym">(</span><span class="src-sym">)</span></li>
<li><a name="a2160"></a>    <span class="src-sym">{</span></li>
<li><a name="a2161"></a>        <span class="src-comm">// function s_param(): initialize or return a session variable.  Use</span></li>
<li><a name="a2162"></a>        <span class="src-comm">// s_param() to initialize session variables. It will prepend all</span></li>
<li><a name="a2163"></a>        <span class="src-comm">// session variables with the current session id, or, if set, the</span></li>
<li><a name="a2164"></a>        <span class="src-comm">// _session_id parameter, plus the character '_',  and normalize the</span></li>
<li><a name="a2165"></a>        <span class="src-comm">// name to upper case to ensure (1) uniqueness of name and (2) to</span></li>
<li><a name="a2166"></a>        <span class="src-comm">// correct typos.</span></li>
<li><a name="a2167"></a>&nbsp;</li>
<li><a name="a2168"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$_SESSION</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2169"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">'Session handling has not been activated'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2170"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2171"></a>        <span class="src-sym">}</span></li>
<li><a name="a2172"></a>&nbsp;</li>
<li><a name="a2173"></a>        <span class="src-comm">// Get the current session name</span></li>
<li><a name="a2174"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-str">'_session_id'</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2175"></a>            <span class="src-var">$session_id </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-str">'_session_id'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2176"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a2177"></a>            <span class="src-var">$session_id </span>= <a href="http://www.php.net/session_name">session_name</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2178"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-str">'_session_id'</span><span class="src-sym">, </span><span class="src-var">$session_id</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2179"></a>        <span class="src-sym">}</span></li>
<li><a name="a2180"></a>&nbsp;</li>
<li><a name="a2181"></a>        <span class="src-comm">// Determine how many arguments were sent</span></li>
<li><a name="a2182"></a>        <span class="src-var">$numargs </span>= <a href="http://www.php.net/func_num_args">func_num_args</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2183"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-num">2 </span>&lt; <span class="src-var">$numargs</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2184"></a>            <span class="src-comm">// Bad number of arguments passed to s_param</span></li>
<li><a name="a2185"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Too many arguments sent to s_param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2186"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2187"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-num">0 </span>== <span class="src-var">$numargs</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2188"></a>            <span class="src-key">return </span><span class="src-var">$_SESSION</span><span class="src-sym">;</span></li>
<li><a name="a2189"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-num">1 </span>== <span class="src-var">$numargs</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2190"></a>            <span class="src-comm">// One argument passed</span></li>
<li><a name="a2191"></a>            <span class="src-var">$data </span>= <a href="http://www.php.net/func_get_arg">func_get_arg</a><span class="src-sym">(</span><span class="src-num">0</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2192"></a>            <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2193"></a>                <span class="src-comm">// Scalar arument passed -- return the session value associated</span></li>
<li><a name="a2194"></a>                <span class="src-comm">// with it</span></li>
<li><a name="a2195"></a>                <span class="src-var">$skey </span>= <span class="src-var">$session_id </span>. <span class="src-str">'_' </span>. <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2196"></a>                <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$_SESSION</span><span class="src-sym">[</span><span class="src-var">$skey</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2197"></a>                    <span class="src-key">return </span><span class="src-var">$_SESSION</span><span class="src-sym">[</span><span class="src-var">$skey</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2198"></a>                <span class="src-sym">}</span></li>
<li><a name="a2199"></a>&nbsp;</li>
<li><a name="a2200"></a>                <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2201"></a>            <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2202"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Bad argument(s) sent to s_param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2203"></a>                <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2204"></a>            <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a2205"></a>                &amp;&amp; <span class="src-sym">(</span><span class="src-num">0 </span>== <span class="src-sym">(</span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>% <span class="src-num">2</span><span class="src-sym">)))</span></li>
<li><a name="a2206"></a>            <span class="src-sym">{</span></li>
<li><a name="a2207"></a>                <span class="src-comm">// even-indexed array passed to method; turn it into a hash</span></li>
<li><a name="a2208"></a>                <span class="src-var">$data </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">array_to_hash</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2209"></a>            <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a2210"></a>                &amp;&amp; <span class="src-sym">(</span><span class="src-num">1 </span>== <span class="src-sym">(</span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>% <span class="src-num">2</span><span class="src-sym">)))</span></li>
<li><a name="a2211"></a>            <span class="src-sym">{</span></li>
<li><a name="a2212"></a>                <span class="src-comm">// odd-indexed array passed to method -- error!</span></li>
<li><a name="a2213"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Bad argument (array) sent to s_param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2214"></a>                <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2215"></a>            <span class="src-sym">}</span></li>
<li><a name="a2216"></a>&nbsp;</li>
<li><a name="a2217"></a>            <span class="src-comm">// We have an associative array; set each key/val pair accordingly</span></li>
<li><a name="a2218"></a>            <span class="src-comm">// in the SESSION array</span></li>
<li><a name="a2219"></a>            <span class="src-var">$params </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2220"></a>            <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-var">$data </span><span class="src-key">as </span><span class="src-var">$key </span>=&gt; <span class="src-var">$val</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2221"></a>                <span class="src-var">$_SESSION</span><span class="src-sym">[</span><span class="src-var">$session_id </span>. <span class="src-str">'_' </span>. <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">))</span><span class="src-sym">] </span>= <span class="src-var">$val</span><span class="src-sym">;</span></li>
<li><a name="a2222"></a>            <span class="src-sym">}</span></li>
<li><a name="a2223"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a2224"></a>            <span class="src-comm">// two arguments passed; assume key/val pair</span></li>
<li><a name="a2225"></a>            <span class="src-var">$key </span>= <a href="http://www.php.net/func_get_arg">func_get_arg</a><span class="src-sym">(</span><span class="src-num">0</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2226"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">) </span>|| <span class="src-sym">!</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2227"></a>                <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;Bad key passed to s_param()&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2228"></a>                <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2229"></a>            <span class="src-sym">}</span></li>
<li><a name="a2230"></a>&nbsp;</li>
<li><a name="a2231"></a>            <span class="src-comm">// Set key and val</span></li>
<li><a name="a2232"></a>            <span class="src-var">$key </span>= <span class="src-var">$session_id </span>. <span class="src-str">'_' </span>. <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2233"></a>            <span class="src-var">$val </span>= <a href="http://www.php.net/func_get_arg">func_get_arg</a><span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2234"></a>&nbsp;</li>
<li><a name="a2235"></a>            <span class="src-comm">// Otherwise, set the value</span></li>
<li><a name="a2236"></a>            <span class="src-var">$_SESSION</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>= <span class="src-var">$val</span><span class="src-sym">;</span></li>
<li><a name="a2237"></a>        <span class="src-sym">}</span></li>
<li><a name="a2238"></a>&nbsp;</li>
<li><a name="a2239"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a2240"></a>    <span class="src-sym">}</span></li>
<li><a name="a2241"></a>&nbsp;</li>
<li><a name="a2242"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2243"></a><span class="src-doc">     * Remove a session variable</span></li>
<li><a name="a2244"></a><span class="src-doc">     *</span></li>
<li><a name="a2245"></a><span class="src-doc">     * Like </span><span class="src-doc-inlinetag">{@link delete()}</span><span class="src-doc">, s_delete() deletes a session parameter.</span></li>
<li><a name="a2246"></a><span class="src-doc">     * </span></li>
<li><a name="a2247"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$key </span><span class="src-doc">The name of the session parameter to delete</span></li>
<li><a name="a2248"></a><span class="src-doc">     */</span></li>
<li><a name="a2249"></a>    <span class="src-key">final </span><span class="src-key">public </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methods_delete">s_delete</a><span class="src-sym">(</span><span class="src-var">$key </span>= <span class="src-id">null</span><span class="src-sym">)</span></li>
<li><a name="a2250"></a>    <span class="src-sym">{</span></li>
<li><a name="a2251"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$_SESSION</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2252"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">'Session handling has not been activated'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2253"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2254"></a>        <span class="src-sym">}</span></li>
<li><a name="a2255"></a>&nbsp;</li>
<li><a name="a2256"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">) </span>|| <span class="src-sym">!</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2257"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">'Bad key passed to s_delete'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2258"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2259"></a>        <span class="src-sym">}</span></li>
<li><a name="a2260"></a>&nbsp;</li>
<li><a name="a2261"></a>        <span class="src-comm">// Get the current session name</span></li>
<li><a name="a2262"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-str">'_session_id'</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2263"></a>            <span class="src-var">$session_id </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-str">'_session_id'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2264"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a2265"></a>            <span class="src-var">$session_id </span>= <a href="http://www.php.net/session_name">session_name</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2266"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodparam">param</a><span class="src-sym">(</span><span class="src-str">'_session_id'</span><span class="src-sym">, </span><span class="src-var">$session_id</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2267"></a>        <span class="src-sym">}</span></li>
<li><a name="a2268"></a>&nbsp;</li>
<li><a name="a2269"></a>        <span class="src-var">$skey </span>= <span class="src-var">$session_id </span>. <span class="src-str">'_' </span>. <a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2270"></a>        <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$_SESSION</span><span class="src-sym">[</span><span class="src-var">$skey</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2271"></a>            unset<span class="src-sym">(</span><span class="src-var">$_SESSION</span><span class="src-sym">[</span><span class="src-var">$skey</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2272"></a>            <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a2273"></a>        <span class="src-sym">}</span></li>
<li><a name="a2274"></a>&nbsp;</li>
<li><a name="a2275"></a>        <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2276"></a>    <span class="src-sym">}</span></li>
<li><a name="a2277"></a>&nbsp;</li>
<li><a name="a2278"></a>    <span class="src-comm">// PRIVATE METHODS</span></li>
<li><a name="a2279"></a>&nbsp;</li>
<li><a name="a2279"></a>    </li>
<li><a name="a2280"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2281"></a><span class="src-doc">     * _send_headers() - send HTTP headers before displaying content</span></li>
<li><a name="a2282"></a><span class="src-doc">     * </span></li>
<li><a name="a2283"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> protected</span></li>
<li><a name="a2284"></a><span class="src-doc">     */</span></li>
<li><a name="a2285"></a>    <span class="src-key">final </span><span class="src-key">protected </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#method_send_headers">_send_headers</a><span class="src-sym">(</span><span class="src-sym">) </span></li>
<li><a name="a2286"></a>    <span class="src-sym">{</span></li>
<li><a name="a2287"></a>        <span class="src-var">$header_type  </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodheader_type">header_type</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2288"></a>        <span class="src-var">$header_props </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Cgiapp2/Cgiapp2.html#methodheader_props">header_props</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2289"></a>&nbsp;</li>
<li><a name="a2290"></a>        <span class="src-key">if </span><span class="src-sym">((</span><span class="src-var">$header_type </span>== <span class="src-str">'redirect'</span><span class="src-sym">) </span></li>
<li><a name="a2291"></a>            &amp;&amp; <span class="src-sym">!</span><a href="http://www.php.net/headers_sent">headers_sent</a><span class="src-sym">(</span><span class="src-sym">)) </span></li>
<li><a name="a2292"></a>        <span class="src-sym">{</span></li>
<li><a name="a2293"></a>            <span class="src-comm">// If it's a redirect, we'll send that right away</span></li>
<li><a name="a2294"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$header_props</span><span class="src-sym">) </span></li>
<li><a name="a2295"></a>                &amp;&amp; isset<span class="src-sym">(</span><span class="src-var">$header_props</span><span class="src-sym">[</span><span class="src-str">'Location'</span><span class="src-sym">]</span><span class="src-sym">))</span></li>
<li><a name="a2296"></a>            <span class="src-sym">{</span></li>
<li><a name="a2297"></a>                <a href="http://www.php.net/header">header</a><span class="src-sym">(</span><span class="src-str">&quot;Location: &quot; </span>. <span class="src-var">$header_props</span><span class="src-sym">[</span><span class="src-str">'Location'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2298"></a>                <span class="src-key">exit</span><span class="src-sym">(</span><span class="src-num">0</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2299"></a>            <span class="src-sym">}</span></li>
<li><a name="a2300"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">((</span><span class="src-var">$header_type </span>== <span class="src-str">'header'</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">!</span><a href="http://www.php.net/headers_sent">headers_sent</a><span class="src-sym">(</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2301"></a>            <span class="src-comm">// If we're sending extra headers, we'll loop through each </span></li>
<li><a name="a2302"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$header_props</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2303"></a>                <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-var">$header_props </span><span class="src-key">as </span><span class="src-var">$header </span>=&gt; <span class="src-var">$value</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2304"></a>                    <span class="src-var">$header </span>= <a href="http://www.php.net/ucfirst">ucfirst</a><span class="src-sym">(</span><span class="src-var">$header</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2305"></a>                    <a href="http://www.php.net/header">header</a><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-var">$header</span>: <span class="src-var">$value</span></span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2306"></a>                <span class="src-sym">}</span></li>
<li><a name="a2307"></a>            <span class="src-sym">}</span></li>
<li><a name="a2308"></a>        <span class="src-sym">} </span><span class="src-key">elseif </span><span class="src-sym">((</span><span class="src-var">$header_type </span>!= <span class="src-str">'none'</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">!</span><a href="http://www.php.net/headers_sent">headers_sent</a><span class="src-sym">(</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2309"></a>            <span class="src-comm">// self::croak() if we have an unknown header type</span></li>
<li><a name="a2310"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">carp</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-id">Invalid</span> <span class="src-id">header_type</span> '<span class="src-var">$header_type</span>' <span class="src-id">given</span> <span class="src-id">to</span> <span class="src-id">_send_headers</span></span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2311"></a>            <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a2312"></a>        <span class="src-sym">}</span></li>
<li><a name="a2313"></a>&nbsp;</li>
<li><a name="a2314"></a>        <span class="src-comm">// Do nothing if header type eq &quot;none&quot;.</span></li>
<li><a name="a2315"></a>        <span class="src-comm">// Simply return</span></li>
<li><a name="a2316"></a>        <span class="src-key">return</span><span class="src-sym">;</span></li>
<li><a name="a2317"></a>    <span class="src-sym">}    </span></li>
<li><a name="a2318"></a>&nbsp;</li>
<li><a name="a2319"></a>&nbsp;</li>
<li><a name="a2320"></a>    <span class="src-comm">// STATIC METHODS</span></li>
<li><a name="a2321"></a>    <span class="src-comm">// These methods are used throughout the class, and may be used in any</span></li>
<li><a name="a2322"></a>    <span class="src-comm">// subclass. In addition, they may be called using the Cgiapp2:: syntax as</span></li>
<li><a name="a2323"></a>    <span class="src-comm">// they do nothing with the object.</span></li>
<li><a name="a2324"></a>&nbsp;</li>
<li><a name="a2324"></a>    </li>
<li><a name="a2325"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2326"></a><span class="src-doc">     * Get POST and GET variables and store them for usage</span></li>
<li><a name="a2327"></a><span class="src-doc">     *</span></li>
<li><a name="a2328"></a><span class="src-doc">     * This method grabs all POST and GET variables and puts them in a single,</span></li>
<li><a name="a2329"></a><span class="src-doc">     * protected array, </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span><span class="src-doc">. This array may then be</span></li>
<li><a name="a2330"></a><span class="src-doc">     * referenced when you wish to scrutinize GET or POST variables, but don't</span></li>
<li><a name="a2331"></a><span class="src-doc">     * care where they come from. It is somewhat safer than using $_REQUEST as</span></li>
<li><a name="a2332"></a><span class="src-doc">     * it does not utilize $_COOKIE variables, thus limiting one more source for</span></li>
<li><a name="a2333"></a><span class="src-doc">     * a particular variable.</span></li>
<li><a name="a2334"></a><span class="src-doc">     *</span></li>
<li><a name="a2335"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a2336"></a><span class="src-doc">     * This method is now static.</span></li>
<li><a name="a2337"></a><span class="src-doc">     *</span></li>
<li><a name="a2338"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a2339"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a2340"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">array </span><span class="src-doc">Reference to </span><span class="src-doc-inlinetag">{@link $CGIAPP_REQUEST}</span></li>
<li><a name="a2341"></a><span class="src-doc">     */</span></li>
<li><a name="a2342"></a>    <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><span class="src-sym">&amp;</span><a href="../Cgiapp2/Cgiapp2.html#methodquery">query</a><span class="src-sym">(</span><span class="src-sym">)</span></li>
<li><a name="a2343"></a>    <span class="src-sym">{</span></li>
<li><a name="a2344"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_REQUEST</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2345"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_REQUEST </span>= <span class="src-id">array_merge</span><span class="src-sym">(</span><span class="src-var">$_GET</span><span class="src-sym">, </span><span class="src-var">$_POST</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2346"></a>        <span class="src-sym">}</span></li>
<li><a name="a2347"></a>&nbsp;</li>
<li><a name="a2348"></a>        <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_REQUEST</span><span class="src-sym">;</span></li>
<li><a name="a2349"></a>    <span class="src-sym">}</span></li>
<li><a name="a2350"></a>&nbsp;</li>
<li><a name="a2351"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2352"></a><span class="src-doc">     * Generate array of PATH_INFO arguments</span></li>
<li><a name="a2353"></a><span class="src-doc">     *</span></li>
<li><a name="a2354"></a><span class="src-doc">     * If PATH_INFO exists in the server API, creates an array of elements found</span></li>
<li><a name="a2355"></a><span class="src-doc">     * in PATH_INFO.</span></li>
<li><a name="a2356"></a><span class="src-doc">     *</span></li>
<li><a name="a2357"></a><span class="src-doc">     * If called with no arguments, the entire array is passed. If provided a</span></li>
<li><a name="a2358"></a><span class="src-doc">     * positive integer argument, the element in the array with that index is</span></li>
<li><a name="a2359"></a><span class="src-doc">     * returned (if it exists); a negative integer argument returns that element</span></li>
<li><a name="a2360"></a><span class="src-doc">     * from the end of the array.</span></li>
<li><a name="a2361"></a><span class="src-doc">     *</span></li>
<li><a name="a2362"></a><span class="src-doc">     * Additionally, if passed a string argument, it will look for a path</span></li>
<li><a name="a2363"></a><span class="src-doc">     * element matching that string and pass the value to its right:</span></li>
<li><a name="a2364"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a2365"></a><span class="src-doc">     * // path is: /controller/action/article/1/page/2</span></li>
<li><a name="a2366"></a><span class="src-doc">     * $page    = Cgiapp2::path_info('page');</span></li>
<li><a name="a2367"></a><span class="src-doc">     * $article = Cgiapp2::path_info('article');</span></li>
<li><a name="a2368"></a><span class="src-doc">     * $action  = Cgiapp2::path_info('action');</span></li>
<li><a name="a2369"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a2370"></a><span class="src-doc">     *</span></li>
<li><a name="a2371"></a><span class="src-doc">     * Returns false if PATH_INFO is unavailable or an index does not exist.</span></li>
<li><a name="a2372"></a><span class="src-doc">     *</span></li>
<li><a name="a2373"></a><span class="src-doc">     * NOTE: Indices begin with 0!</span></li>
<li><a name="a2374"></a><span class="src-doc">     * </span></li>
<li><a name="a2375"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a2376"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a2377"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">int </span><span class="src-doc-var">$idx </span><span class="src-doc">Optional index of element to fetch</span></li>
<li><a name="a2378"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">array</span><span class="src-doc">|</span><span class="src-doc-type">false</span></li>
<li><a name="a2379"></a><span class="src-doc">     */</span></li>
<li><a name="a2380"></a>    <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodpath_info">path_info</a><span class="src-sym">(</span><span class="src-var">$idx </span>= <span class="src-id">false</span><span class="src-sym">)</span></li>
<li><a name="a2381"></a>    <span class="src-sym">{</span></li>
<li><a name="a2382"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2383"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">'PATH_INFO'</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2384"></a>                <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">'REQUEST_URI'</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2385"></a>                    <span class="src-comm">// Get path info from request URI</span></li>
<li><a name="a2386"></a>                    <span class="src-var">$pi </span>= <span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">'REQUEST_URI'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2387"></a>&nbsp;</li>
<li><a name="a2388"></a>                    <span class="src-comm">// See if we can remove the path to the script from the</span></li>
<li><a name="a2389"></a>                    <span class="src-comm">// request URI</span></li>
<li><a name="a2390"></a>                    <span class="src-var">$script  </span>= <span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">'SCRIPT_FILENAME'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2391"></a>                    <span class="src-var">$docroot </span>= <span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">'DOCUMENT_ROOT'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2392"></a>                    <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">strstr</span><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">, </span><span class="src-var">$docroot</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2393"></a>                        <span class="src-comm">// Okay, the document root is in the script_filename --</span></li>
<li><a name="a2394"></a>                        <span class="src-comm">// good!</span></li>
<li><a name="a2395"></a>                        <span class="src-var">$request </span>= <a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">, </span><span class="src-num">0</span><span class="src-sym">, </span><a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><span class="src-var">$docroot</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2396"></a>                        <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/strstr">strstr</a><span class="src-sym">(</span><span class="src-var">$pi</span><span class="src-sym">, </span><span class="src-var">$request</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2397"></a>                            <span class="src-comm">// The script path is in the request uri!</span></li>
<li><a name="a2398"></a>                            <span class="src-var">$pi </span>= <a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$pi</span><span class="src-sym">, </span><a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><span class="src-var">$request</span><span class="src-sym">) </span>- <span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2399"></a>                        <span class="src-sym">}</span></li>
<li><a name="a2400"></a>                    <span class="src-sym">}</span></li>
<li><a name="a2401"></a>&nbsp;</li>
<li><a name="a2402"></a>                    <span class="src-comm">// Remove the query string, if present</span></li>
<li><a name="a2403"></a>                    <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/strstr">strstr</a><span class="src-sym">(</span><span class="src-var">$pi</span><span class="src-sym">, </span><span class="src-str">'?'</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2404"></a>                        <span class="src-var">$pi </span>= <a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$pi</span><span class="src-sym">, </span><span class="src-num">0</span><span class="src-sym">, </span><a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$pi</span><span class="src-sym">, </span><span class="src-str">'?'</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2405"></a>                    <span class="src-sym">}</span></li>
<li><a name="a2406"></a>                <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a2407"></a>                    <span class="src-comm">// Otherwise, we have no way to know.</span></li>
<li><a name="a2408"></a>                    <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2409"></a>                <span class="src-sym">}</span></li>
<li><a name="a2410"></a>            <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a2411"></a>                <span class="src-var">$pi </span>= <span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">'PATH_INFO'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2412"></a>            <span class="src-sym">}</span></li>
<li><a name="a2413"></a>&nbsp;</li>
<li><a name="a2414"></a>            <span class="src-comm">// Trim beginning and ending slashes, and explode on the slash</span></li>
<li><a name="a2415"></a>            <span class="src-var">$pi </span>= <a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><span class="src-var">$pi</span><span class="src-sym">, </span><span class="src-str">'/'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2416"></a>            <span class="src-var">$pi </span>= <a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">'/'</span><span class="src-sym">, </span><span class="src-var">$pi</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2417"></a>&nbsp;</li>
<li><a name="a2418"></a>            <span class="src-comm">// Loop through the elements, and make associative elements for each</span></li>
<li><a name="a2419"></a>            <span class="src-comm">// string, allowing fetching by 'key'</span></li>
<li><a name="a2420"></a>            <span class="src-var">$last </span>= <a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$pi</span><span class="src-sym">) </span>- <span class="src-num">1</span><span class="src-sym">;</span></li>
<li><a name="a2421"></a>            <span class="src-key">for </span><span class="src-sym">(</span><span class="src-var">$i </span>= <span class="src-num">0</span><span class="src-sym">; </span><span class="src-var">$i </span>&lt; <span class="src-var">$last</span><span class="src-sym">; </span><span class="src-var">$i</span>++<span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2422"></a>                <span class="src-var">$key </span>= <span class="src-var">$pi</span><span class="src-sym">[</span><span class="src-var">$i</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2423"></a>                <span class="src-var">$val </span>= <span class="src-var">$pi</span><span class="src-sym">[</span><span class="src-var">$i </span>+ <span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2424"></a>                <span class="src-var">$pi</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>= <span class="src-var">$val</span><span class="src-sym">;</span></li>
<li><a name="a2425"></a>            <span class="src-sym">}</span></li>
<li><a name="a2426"></a>&nbsp;</li>
<li><a name="a2427"></a>            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO </span>= <span class="src-var">$pi</span><span class="src-sym">;</span></li>
<li><a name="a2428"></a>        <span class="src-sym">}</span></li>
<li><a name="a2429"></a>&nbsp;</li>
<li><a name="a2430"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">false </span>=== <span class="src-var">$idx</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2431"></a>            <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO</span><span class="src-sym">;</span></li>
<li><a name="a2432"></a>        <span class="src-sym">}</span></li>
<li><a name="a2433"></a>&nbsp;</li>
<li><a name="a2434"></a>        <span class="src-comm">// Fetch text indices</span></li>
<li><a name="a2435"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$idx </span>!= <span class="src-id">intval</span><span class="src-sym">(</span><span class="src-var">$idx</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2436"></a>            <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO</span><span class="src-sym">[</span><span class="src-var">$idx</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2437"></a>                <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO</span><span class="src-sym">[</span><span class="src-var">$idx</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2438"></a>            <span class="src-sym">}</span></li>
<li><a name="a2439"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2440"></a>        <span class="src-sym">}</span></li>
<li><a name="a2441"></a>&nbsp;</li>
<li><a name="a2442"></a>        <span class="src-comm">// Fetch by numeric index</span></li>
<li><a name="a2443"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-num">0 </span>&lt;= <span class="src-var">$idx</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2444"></a>            <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO</span><span class="src-sym">[</span><span class="src-var">$idx</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2445"></a>                <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO</span><span class="src-sym">[</span><span class="src-var">$idx</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2446"></a>            <span class="src-sym">}</span></li>
<li><a name="a2447"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a2448"></a>            <span class="src-var">$reversed </span>= <span class="src-id">array_reverse</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$CGIAPP_PATH_INFO</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2449"></a>            <span class="src-var">$idx </span>= <span class="src-id">abs</span><span class="src-sym">(</span><span class="src-var">$idx</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2450"></a>            <span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$reversed</span><span class="src-sym">[</span><span class="src-var">$idx</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2451"></a>                <span class="src-key">return </span><span class="src-var">$reversed</span><span class="src-sym">[</span><span class="src-var">$idx</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2452"></a>            <span class="src-sym">}</span></li>
<li><a name="a2453"></a>        <span class="src-sym">}</span></li>
<li><a name="a2454"></a>&nbsp;</li>
<li><a name="a2455"></a>        <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2456"></a>    <span class="src-sym">}</span></li>
<li><a name="a2457"></a>&nbsp;</li>
<li><a name="a2458"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2459"></a><span class="src-doc">     * Convert the keys of an associative array to UPPER CASE</span></li>
<li><a name="a2460"></a><span class="src-doc">     * </span></li>
<li><a name="a2461"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a2462"></a><span class="src-doc">     * This method is now static.</span></li>
<li><a name="a2463"></a><span class="src-doc">     *</span></li>
<li><a name="a2464"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a2465"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a2466"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$rprops </span></li>
<li><a name="a2467"></a><span class="src-doc">     */</span></li>
<li><a name="a2468"></a>    <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodcap_hash">cap_hash</a><span class="src-sym">(</span><span class="src-var">$rprops </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a2469"></a>    <span class="src-sym">{</span></li>
<li><a name="a2470"></a>        <span class="src-comm">// Return a false value if we weren't passed an associative array</span></li>
<li><a name="a2471"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2472"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2473"></a>        <span class="src-sym">}</span></li>
<li><a name="a2474"></a>&nbsp;</li>
<li><a name="a2475"></a>        <span class="src-key">return </span><a href="http://www.php.net/array_change_key_case">array_change_key_case</a><span class="src-sym">(</span><span class="src-var">$rprops</span><span class="src-sym">, </span><span class="src-id">CASE_UPPER</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2476"></a>    <span class="src-sym">}    </span></li>
<li><a name="a2477"></a>&nbsp;</li>
<li><a name="a2478"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2479"></a><span class="src-doc">     * Test an array to determine if it is associative</span></li>
<li><a name="a2480"></a><span class="src-doc">     * </span></li>
<li><a name="a2481"></a><span class="src-doc">     * is_assoc_array() tests an array to determine if it is an associative</span></li>
<li><a name="a2482"></a><span class="src-doc">     * array; this is necessary functionality for a number of other methods,</span></li>
<li><a name="a2483"></a><span class="src-doc">     * including </span><span class="src-doc-inlinetag">{@link param()}</span><span class="src-doc"> and </span><span class="src-doc-inlinetag">{@link run_modes()}</span><span class="src-doc">. It is based on a</span></li>
<li><a name="a2484"></a><span class="src-doc">     * function found in the document comments for is_array on php.net. It's</span></li>
<li><a name="a2485"></a><span class="src-doc">     * primary bug is that an associative array made with sequential integer</span></li>
<li><a name="a2486"></a><span class="src-doc">     * keys will look just like a regular array and thus return a false result.</span></li>
<li><a name="a2487"></a><span class="src-doc">     * </span></li>
<li><a name="a2488"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a2489"></a><span class="src-doc">     * This method is now static.</span></li>
<li><a name="a2490"></a><span class="src-doc">     *</span></li>
<li><a name="a2491"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a2492"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a2493"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$php_val </span><span class="src-doc">A value to test</span></li>
<li><a name="a2494"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">bool </span><span class="src-doc">Success</span></li>
<li><a name="a2495"></a><span class="src-doc">     */</span></li>
<li><a name="a2496"></a>    <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodis_assoc_array">is_assoc_array</a><span class="src-sym">(</span><span class="src-var">$php_val </span>= <span class="src-id">null</span><span class="src-sym">) </span></li>
<li><a name="a2497"></a>    <span class="src-sym">{</span></li>
<li><a name="a2498"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$php_val</span><span class="src-sym">))</span><span class="src-sym">{</span></li>
<li><a name="a2499"></a>            <span class="src-comm"># Neither an associative, nor non-associative array.</span></li>
<li><a name="a2500"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2501"></a>        <span class="src-sym">}</span></li>
<li><a name="a2502"></a>&nbsp;</li>
<li><a name="a2503"></a>        <span class="src-key">return </span><a href="http://www.php.net/array_keys">array_keys</a><span class="src-sym">(</span><span class="src-var">$php_val</span><span class="src-sym">) </span>!== <a href="http://www.php.net/range">range</a><span class="src-sym">(</span><span class="src-num">0</span><span class="src-sym">, </span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$php_val</span><span class="src-sym">) </span>- <span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2504"></a>    <span class="src-sym">}</span></li>
<li><a name="a2505"></a>&nbsp;</li>
<li><a name="a2506"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2507"></a><span class="src-doc">     * Convert an even-itemed array into an associative array</span></li>
<li><a name="a2508"></a><span class="src-doc">     * </span></li>
<li><a name="a2509"></a><span class="src-doc">     * array_to_hash() can be used to turn an even-itemed array into an</span></li>
<li><a name="a2510"></a><span class="src-doc">     * associative arary, where the even elements become keys for the odd</span></li>
<li><a name="a2511"></a><span class="src-doc">     * elements. In a nutshell,</span></li>
<li><a name="a2512"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a2513"></a><span class="src-doc">     *     array('key1', 'val1', 'key2', 'val2')</span></li>
<li><a name="a2514"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a2515"></a><span class="src-doc">     * becomes</span></li>
<li><a name="a2516"></a><span class="src-doc">     * &lt;code&gt;</span></li>
<li><a name="a2517"></a><span class="src-doc">     *     array('key1' =&gt; 'val1', 'key2' =&gt; 'val2')</span></li>
<li><a name="a2518"></a><span class="src-doc">     * &lt;/code&gt;</span></li>
<li><a name="a2519"></a><span class="src-doc">     * </span></li>
<li><a name="a2520"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a2521"></a><span class="src-doc">     * This method is now static.</span></li>
<li><a name="a2522"></a><span class="src-doc">     *</span></li>
<li><a name="a2523"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a2524"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a2525"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">array </span><span class="src-doc-var">$data </span><span class="src-doc">The array to convert</span></li>
<li><a name="a2526"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">array </span><span class="src-doc">An associative array</span></li>
<li><a name="a2527"></a><span class="src-doc">     */</span></li>
<li><a name="a2528"></a>    <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodarray_to_hash">array_to_hash</a><span class="src-sym">(</span><span class="src-var">$data </span>= <span class="src-id">null</span><span class="src-sym">)</span></li>
<li><a name="a2529"></a>    <span class="src-sym">{</span></li>
<li><a name="a2530"></a>        <span class="src-comm">// Given an indexed array with an even number of elements, create</span></li>
<li><a name="a2531"></a>        <span class="src-comm">// an associative array out of them</span></li>
<li><a name="a2532"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a2533"></a>            || <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">is_assoc_array</span><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a2534"></a>            || <span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span></li>
<li><a name="a2535"></a>                &amp;&amp; <span class="src-sym">((</span><a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">) </span>% <span class="src-num">2</span><span class="src-sym">) </span>!= <span class="src-num">0</span><span class="src-sym">)))</span></li>
<li><a name="a2536"></a>        <span class="src-sym">{</span></li>
<li><a name="a2537"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a2538"></a>        <span class="src-sym">}</span></li>
<li><a name="a2539"></a>&nbsp;</li>
<li><a name="a2540"></a>        <span class="src-var">$hash </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2541"></a>        <span class="src-key">for </span><span class="src-sym">(</span><span class="src-var">$i </span>= <span class="src-num">0</span><span class="src-sym">; </span><span class="src-var">$i </span>&lt; <a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$data</span><span class="src-sym">)</span><span class="src-sym">; </span><span class="src-var">$i </span>= <span class="src-var">$i </span>+ <span class="src-num">2</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a2542"></a>            <span class="src-var">$k </span>= <span class="src-var">$data</span><span class="src-sym">[</span><span class="src-var">$i</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2543"></a>            <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_string">is_string</a><span class="src-sym">(</span><span class="src-var">$k</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2544"></a>                <span class="src-var">$hash</span><span class="src-sym">[</span><span class="src-var">$k</span><span class="src-sym">] </span>= <span class="src-var">$data</span><span class="src-sym">[</span><span class="src-var">$i </span>+ <span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2545"></a>            <span class="src-sym">}</span></li>
<li><a name="a2546"></a>        <span class="src-sym">}</span></li>
<li><a name="a2547"></a>&nbsp;</li>
<li><a name="a2548"></a>        <span class="src-key">return </span><span class="src-var">$hash</span><span class="src-sym">;</span></li>
<li><a name="a2549"></a>    <span class="src-sym">}</span></li>
<li><a name="a2550"></a>&nbsp;</li>
<li><a name="a2551"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2552"></a><span class="src-doc">     * Echo a warning to screen</span></li>
<li><a name="a2553"></a><span class="src-doc">     * </span></li>
<li><a name="a2554"></a><span class="src-doc">     * Carp is the name of a perl module and is used to provide warnings -- in</span></li>
<li><a name="a2555"></a><span class="src-doc">     * other words, to notify the user/developer of non-fatal errors. The carp()</span></li>
<li><a name="a2556"></a><span class="src-doc">     * method does similarly, but uses PHP's native trigger_error() function to</span></li>
<li><a name="a2557"></a><span class="src-doc">     * do so, with an E_USER_WARNING level error.</span></li>
<li><a name="a2558"></a><span class="src-doc">     * &lt;b&gt;Note:&lt;/b&gt; If your application sets custom headers, a carp() may break</span></li>
<li><a name="a2559"></a><span class="src-doc">     * them, if the INI setting 'display_errors' is on.</span></li>
<li><a name="a2560"></a><span class="src-doc">     * </span></li>
<li><a name="a2561"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a2562"></a><span class="src-doc">     * This method is now static.</span></li>
<li><a name="a2563"></a><span class="src-doc">     *</span></li>
<li><a name="a2564"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a2565"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a2566"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$message </span><span class="src-doc">The warning message to display</span></li>
<li><a name="a2567"></a><span class="src-doc">     */</span></li>
<li><a name="a2568"></a>    <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodcarp">carp</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">)</span></li>
<li><a name="a2569"></a>    <span class="src-sym">{</span></li>
<li><a name="a2570"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_scalar">is_scalar</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2571"></a>            <span class="src-var">$message </span>= <a href="http://www.php.net/print_r">print_r</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2572"></a>        <span class="src-sym">}</span></li>
<li><a name="a2573"></a>        <a href="http://www.php.net/trigger_error">trigger_error</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">, </span><span class="src-id">E_USER_WARNING</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2574"></a>    <span class="src-sym">}</span></li>
<li><a name="a2575"></a>&nbsp;</li>
<li><a name="a2576"></a>    <span class="src-doc">/**</span></li>
<li><a name="a2577"></a><span class="src-doc">     * Exit the script with a warning message</span></li>
<li><a name="a2578"></a><span class="src-doc">     *</span></li>
<li><a name="a2579"></a><span class="src-doc">     * croak() was originally a method of the perl Carp module; it's purpose is</span></li>
<li><a name="a2580"></a><span class="src-doc">     * to trigger fatal errors. The croak() method here does the same, utilizing</span></li>
<li><a name="a2581"></a><span class="src-doc">     * PHP's native trigger_error() function with an E_USER_ERROR level error.</span></li>
<li><a name="a2582"></a><span class="src-doc">     * </span></li>
<li><a name="a2583"></a><span class="src-doc">     * &lt;b&gt;UPGRADE NOTE:&lt;/b&gt;</span></li>
<li><a name="a2584"></a><span class="src-doc">     * This method is now static.</span></li>
<li><a name="a2585"></a><span class="src-doc">     *</span></li>
<li><a name="a2586"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@static</span></li>
<li><a name="a2587"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@access</span><span class="src-doc"> public</span></li>
<li><a name="a2588"></a><span class="src-doc">     * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc-var">$message </span><span class="src-doc">The warning message to display</span></li>
<li><a name="a2589"></a><span class="src-doc">     */</span></li>
<li><a name="a2590"></a>    <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Cgiapp2/Cgiapp2.html#methodcroak">croak</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">)</span></li>
<li><a name="a2591"></a>    <span class="src-sym">{</span></li>
<li><a name="a2592"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_scalar">is_scalar</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a2593"></a>            <span class="src-var">$message </span>= <a href="http://www.php.net/print_r">print_r</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">, </span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2594"></a>        <span class="src-sym">}</span></li>
<li><a name="a2595"></a>        <a href="http://www.php.net/trigger_error">trigger_error</a><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">, </span><span class="src-id">E_USER_ERROR</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2596"></a>    <span class="src-sym">}</span></li>
<li><a name="a2597"></a><span class="src-sym">}</span></li>
</ol></pre></div>
</div>
        <div class="credit">
		    <hr />
		    Documentation generated on Sat, 03 Jun 2006 10:48:38 -0400 by <a href="http://www.phpdoc.org">phpDocumentor 1.3.0RC5</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
</table>

</body>
</html>
Return current item: Cgiapp.class.php