Location: PHPKode > projects > Open Power Template > docs/Opt/extending.instructions.plugins.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>Instruction plugins - 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>Instruction plugins</h2>
		<p class="generated">@ 02.09.2010</p>
		<p class="location"><a href="index.html"><strong>User manual</strong></a> &raquo; <a href="extending.html">Extending OPT</a> &raquo; <a href="extending.instructions.html">New instructions</a> &raquo; <a href="extending.instructions.plugins.html">Instruction plugins</a></p>
	</div>
	
	<div id="content"><dl class="location"><dt><a href="extending.instructions.html">5.8. New instructions</a><br/>5.8.9. Instruction plugins</dt><dd class="prev">5.8.8. Tips and tricks<br/><a href="extending.instructions.tips.html">&laquo; Previous</a></dd><dd class="next">6. Migration<br/><a href="migration.html">Next &raquo;</a></dd></dl>	<h1>5.8.9. Instruction plugins</h1><p>Instructions can be packed as plugins, however, they need a more sophisticated format. Open Power Template requires the instruction plugins to:</p>

<ul>
<li>The file name must be in the format: <code>instruction.Foo.php</code></li>
<li>The class name must be in the format: <code>Opt_Instruction_Foo</code>, where <code>Foo</code> must be the same, as in the file name.</li>
</ul>

<p>A sample instruction plugin can be found below:</p>

<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// instruction.Plugin.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Opt_Instruction_Plugin <span style="color: #000000; font-weight: bold;">extends</span> Opt_Compiler_Processor
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end Opt_Instruction_Plugin;</span></pre>

<p>Note that you can also register the instruction manually:</p>

<pre class="php"><span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span>Opt_Class<span style="color: #339933;">::</span><span style="color: #004000;">OPT_INSTRUCTION</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Foo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Registers &quot;Opt_Instruction_Foo&quot;</span>
<span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span>Opt_Class<span style="color: #339933;">::</span><span style="color: #004000;">OPT_INSTRUCTION</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Foo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Some_Class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Registers &quot;Foo&quot; in the &quot;Some_Class&quot; class</span></pre>

<p>In this case, the class name does not have to begin with <code>Opt_Instruction</code>. The second line shows, how to register such classes in OPT.</p>
<h4>See also:</h4><ul><li><a href="extending.plugins.html">5.1. Introduction to plugins</a></li></ul><dl class="location location-bottom"><dt>5.8.9. Instruction plugins<br/><a href="extending.instructions.html">5.8. New instructions</a></dt><dd class="prev"><a href="extending.instructions.tips.html">&laquo; Previous</a><br/>5.8.8. Tips and tricks</dd><dd class="next"><a href="migration.html">Next &raquo;</a><br/>6. Migration</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