This is the time to write your first OPT instruction. It will be very simple and do nothing interesting, but it will give you a clue, what is going on here. First, an instruction processor is a class that extends optInstruction class and overwrites some of its methods. In configure() we return an array with the information about the tags we want to register, and instructionNodeProcess() is called by the parent-level processor to process the node. Here we will write our code.
Example 5.4. Your first instruction
<?php class optFirst extends optInstruction // 1 { public function configure() { return array( // 2 // processor name 0 => 'first', // instructions 'first' => OPT_MASTER, '/first' => OPT_ENDER ); } // end configure(); public function instructionNodeProcess(ioptNode $node) { foreach($node as $block) // 3 { switch($block -> getName()) // 4 { case 'first': $this -> firstBegin($block-> getAttributes()); $this -> defaultTreeProcess($block); // 5 break; case '/first': $this -> firstEnd(); break; } } } // end process(); private function firstBegin($attributes) { $this -> compiler -> out('Beginning tag<br/>', true); // 6 } // end firstBegin(); private function firstEnd() { $this -> compiler -> out('Ending tag<br/>', true); } // end firstEnd(); } ?>
The description of the main parts:
optInstruction
class, which
has some very important methods and all the logic of the tree
processing.In order to install this instruction, copy it to your plugins
directory, set the path (do not forget to remove plugins.php
and compile.php
files) and try to parse the following template:
Here is a small guide through the optInstruction
class (Where To Find The Things I Need):