Location: PHPKode > scripts > LOCO > loco.html
<html>
 <head>
  <title>LOCO Documentation</title>
 </head>
 <body>
<h1>LOCO</h1>
<p>Base class for LOCO functionality.<br />
The class LOCO has not much separate logic and is just a collector for
all calls and variable set calls.</p>


<h2>__constructor</h2>
<p>The first argument in the constructor is the class that should be used
when executing the actions.</p>p>

<h2>__lococall</h2>
<p>The first argument in this call is the function that should return a
value when executing the actions later.<br />
The __lococall returns an array containing all actions stored in LOCO.</p>

<h2>__locoinclude</h2>
<p>Tells LOCO to include a specific file at runtime.</p>


<h1>xLOCO</h1>
<p>Extends the basic LOCO class by adding two static functions.</p>

<h2>Execute</h2>
<p>Executes an array of actions (that you get from __lococall)</p>

<h2>ExecuteFile</h2>
<p>Loads the specified file and then calls Execute</p>


<h1>GoLOCO</h1>
<p>A more stand-alone extension of the LOCO class adding the special
functions __locogo, __locoobject, __locoget, __locoset, __locosave
and __locoload.</p>

<h2>__locogo</h2>
<p>Executes the stored actions. The return value of the last call is used
as a return value for this function.</p>

<h2>__locoobject</h2>
<p>Returns the object used by LOCO internally.</p>

<h2>__locoget</h2>
<p>Get the list of actions.</p>

<h2>__locoset</h2>
<p>Set a new list of actions.</p>

<h2>__locosave</h2>
<p>Save the list of actions to a file.</p>

<h2>__locoload</h2>
<p>Load a new list of actions from a file.</p>



<h1>When to use LOCO?</h1>
<p>LOCO can be used to decrease the execution time for a request by
extracting tasks that are heavy time consumers to an external task,
for instance a cronjob, without the need for the new context to know
any context specific information about the old context.<br />
An example is to send mail from the web server to the webmaster without
putting any delay to the request.
</p>
<p>In file where you wish to send a mail but doesn't bother if it
filed or not. (Note that you does not have to include PHPMailer in
this file. This is because it is never actually called.)</p>

<pre>
include_once(INCLUDE_PATH_TO_LOCO.'/loco.php');
$mail = new GoLOCO('PHPMailer');
$mail->__locoinclude(INCLUDE_PATH_TO_PHPMAILER.'/class.phpmailer.php');
$mail->IsHTML();
$mail->AddAddress('hide@address.com', 'Thomas');
$mail->Subject = 'GoLOCO test';
$mail->Body = 'This mail is sent by using <strong>GoLOCO</strong>';
$mail->__locosave(SAVEPATH.'/filename.loco');
</pre>

<p>Then there might be a cronjob running in the background calling
another file containing this code:</p>

<pre>
include_once(INCLUDE_PATH_TO_LOCO.'/loco.php');
$send = new GoLOCO();
$send->__locoload(SAVEPATH.'/filename.loco');
$send->__locogo('Send');
</pre>


<h1>Examples</h1>

<h2>Demo 1</h2>
<p>A rather complicated way to create an object from the class Test,
setting the $value to a value and then print the $value.</p>
<pre>
&lt;?php
// demo1.php
include_once('../loco.php');
class Test {
  var $value;
}

$gl = new GoLOCO('Test');
$gl->value = 42;
$actions = $gl->__locoget();

$gl2 = new GoLOCO();
$gl2->__locoset($actions);
$gl2->__locogo();
$test = $gl2->__locoobject();

echo $test->value;
echo "\n";
?&gt;
</pre>
<p>Should print out 42</p>


<h2>Demo 2</h2>
<p>Simple way to include at time of execution.
The basic function is Demo 1 but split into three files</p>
<pre>
&lt;?php
// demo2a.php
class Test {
  var $value;
}
?&gt;
</pre>

<pre>
&lt;?php
// demo2b.php
include_once('../loco.php');
$gl = new GoLOCO('Test');
$gl->__locoinclude('./demo2a.php');
$gl->value = 42;
$gl->__locosave('./demo2.loco');
?&gt;
</pre>

<pre>
&lt;?php
// demo2c.php
include_once('../loco.php');
$gl = new GoLOCO();
$gl->__locoload('./demo2.loco');
$gl->__locogo();
$test = $gl->__locoobject();
echo $test->value;
?&gt;
</pre>

<p>Running demo2b.php followed by demo2c.php should print out 42</p>

<p>The script demo2b.php generates a file called demo2.loco that contains
the actions performed in demo2c.php.</p>


<h2>Demo 3</h2>
<pre>
&lt;?php
// demo3.php
include_once('../loco.php');
class Test {
  var $value;
  
  public function ShowValue() {
    echo $this->value;
  }
  
}

$gl = new xLOCO('Test');
$gl->value = 42;
$actions = $gl->__lococall('ShowValue');
xLOCO::Execute($actions);
?&gt;
</pre>
 </body>
</html>
Return current item: LOCO