<?
/**
* @ignore
*/
// First of all, define the constant LIBDIR with the path where all the libraries reside, don't forget the ending slash /
define ("LIBDIR", "../");
// Include the patternizer_commandparser class
include LIBDIR."patternizer/patternizer_commandparser.class.php";
// Here we're building a very simple dummy class, wich is supposed to be one of the classes of your real projects
class myclass
{
var $text = "This text comes from myclass!";
function dosomething ()
{
return $this->text." <br>";
}
function dosomething2 ($p1)
{
return $this->text." ($p1)<br>";
}
function dosomething3 ($p1, $p2)
{
return $this->text." ($p1, $p2)<br>";
}
}
// Build two objects instantiated from our dummy class
$myclass = new myclass;
$myclass2 = new myclass;
// Build a patternizer_commandparser object
$patternizer = new patternizer_commandparser ();
// Now, the more important step.
// Using the method addclasses of patternizer, we set up the methods we want to be accessible trough in-pattern commands
$patternizer->addclasses(
array
(
"myclass" => array
(
"pointer" => &$myclass, // A reference to the object, note the & symbol
"methods" => array
(
"dosomething" => 0, // The name of the first method, and the number of parameters it gets
"dosomething2" => 1,
"dosomething3" => 2
)
),
"myclass2" => array
(
"pointer" => &$myclass2,
"methods" => array
(
"dosomething2" => 1
)
)
)
);
// So, now we have our own class wich does some sort of stuff, and we've added our methods to the patternizer object, so they can be called using commands in the pattern.
// But ... if we can set up any method from any object to be used within the patterns, why not we add the method "patternize", so we can place patterns over patterns, just like an "include" sentence? Do it!
$patternizer->addclasses(
array
(
"patternizer" => array
(
"pointer" => &$patternizer,
"methods" => array
(
"patternize" => 1
)
)
)
);
// Setting up the method patternize allows you to perform calls to different patterns recursively, wich is the real power of using patterns!
// And the last step, just do this to dump a parsed pattern to the user's browser:
echo $patternizer->patternize ("pattern1.html");
?>
|