Location: PHPKode > projects > Open Power Template > docs/Opt/installation.phar.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="robots" content="all" />

	<title>PHAR installation - Open Power Template</title>
	
	<link rel="stylesheet" type="text/css" href="design/generic.css" media="all"  />
	<link rel="stylesheet" type="text/css" href="design/print.css" media="print" />
	<!--[if lte IE 6]><link rel="stylesheet" href="design/ie.css" type="text/css" /><![endif]-->	
	<!--[if IE 7]><link rel="stylesheet" href="design/ie7.css" type="text/css" /><![endif]-->
</head>
<body>

<div id="wrap">
	<div id="header">
		<h1>Open Power Template 2.0</h1>
		<h2>PHAR installation</h2>
		<p class="generated">@ 02.09.2010</p>
		<p class="location"><a href="index.html"><strong>User manual</strong></a> &raquo; <a href="installation.html">Installation</a> &raquo; <a href="installation.phar.html">PHAR installation</a></p>
	</div>
	
	<div id="content"><dl class="location"><dt><a href="installation.html">2. Installation</a><br/>2.2. PHAR installation</dt><dd class="prev">2.1. Standard installation<br/><a href="installation.standard.html">&laquo; Previous</a></dd><dd class="next">3. Template syntax<br/><a href="syntax.html">Next &raquo;</a></dd></dl>	<h1>2.2. PHAR installation</h1><blockquote class="warning">
  <p>This chapter describes an experimental feature that is not completed yet. The details might change before releasing the first stable version.</p>
</blockquote>
<p>This chapter describes installing OPT as PHAR. It is recommended to read the previous chapter, too, because here we will only explain the differences.</p>

<h2>PHARs</h2>

<p>PHARs (PHP Archives) are special files similar to JAR in Java. In other words, they group several files as one bigger archive. PHP supports PHAR since PHP 5.2.0 after installing the necessary module, and since PHP 5.3.0, PHAR extension is enabled by default.</p>

<h2>OPL as PHAR</h2>

<p>Because PHARs can do the initial configuration on their own, the startup code is a bit simpler here. All we have to do is to put somewhere the downloaded archives and to include them:</p>

<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./opl.phar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./opt.phar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
try
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$tpl</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Opt_Class<span style="color: #339933;">;</span>
    <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sourceDir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./templates/'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">compileDir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./templates_c/'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contentType</span> <span style="color: #339933;">=</span> Opt_Output_Http<span style="color: #339933;">::</span><span style="color: #004000;">XHTML</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">charset</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'utf-8'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Opt_View<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template.tpl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hello</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hello, world!'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Opt_Output_Http<span style="color: #339933;">;</span>
    <span style="color: #000088;">$out</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$out</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch<span style="color: #009900;">&#40;</span>Opt_Exception <span style="color: #000088;">$exception</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    Opl_Error_Handler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$exception</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre>

<blockquote class="information">
  <p>Even with PHARs, there may be a need to keep additional directory structure for OPL. For example, if an add-on is not available as PHAR, you must put it in the filesystem and inform OPL, where it can find it.</p>

<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./opl.phar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./opt.phar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Opl_Loader<span style="color: #339933;">::</span><span style="color: #004000;">setDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./libs/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre>
  
  <p>The details can be found in OPL documentation.</p>
</blockquote>
<h4>See also:</h4><ul><li><a href="installation.standard.html">2.1. Standard installation</a></li></ul><dl class="location location-bottom"><dt>2.2. PHAR installation<br/><a href="installation.html">2. Installation</a></dt><dd class="prev"><a href="installation.standard.html">&laquo; Previous</a><br/>2.1. Standard installation</dd><dd class="next"><a href="syntax.html">Next &raquo;</a><br/>3. Template syntax</dd></dl>		</div>
	
	<div id="footer">
		<p>Copyright &copy; <a href="http://www.invenzzia.org/">Invenzzia Group 2008-2009</a></p>
		<p>Available under the terms of license: <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License 1.2</a></p>
		<p>Generated by <strong>TypeFriendly 0.1.4</strong> by <a href="http://www.invenzzia.org/">Invenzzia</a></p>
	</div>
</div>

</body>
</html>
Return current item: Open Power Template