Output Framework
The output framework is a backend framework that makes sanitizing information as a specific format easier.
There are several different output types:
- intOutput
- Outputs status strings (such as "ok", "generic_err", etc) as an integer.
- jsonOutput
- Sanitizes objects as JSON.
- xmlOutput
- Sanitizes objects as XML.
- textareaOutput
- Puts json data in a textarea. Usefull for use with dojo.io.iframe
intOutput Guide
Here is a list of errors and their error codes taken directly from the output framework.
"ok" => 0, "generic_err" => 1, "not_authed" => 2, "not_found" => 3, "db_connect_err" => 4, "db_select_err" => 5, "db_query_err" => 6, "permission_denied" => 7, "mail_connect_err" => 8, "feature_not_available" => 9, "quota_exceeded" => 10
To create an intOutput, just do:
$number = new intOutput();
Now we got us an output. That's going to return 0 at the end of the code no matter what. To change what it outputs:
$number->set("generic_error");
Now it's going to return a 1 at the end of the code no matter what. We can then clear it, and cancel it so it will not output anything.
$number->clear(); unset($number);
intOutput Example
The following code:
<?php
require("path/to/lib/includes.php");
$blah = new intOutput();
$blah->set("mail_connect_err");
?>
Will return (in plaintext):
8
Easy, huh?
jsonOutput Example
The following code:
<?php
require("path/to/lib/includes.php");
$blah = new jsonOutput();
$blah->append("name", "Jay");
$blah->append("ruleOMeter", "1000");
?>
Will output (in JSON):
[{name: "Jay", ruleOMeter: "1000"}]
Common functions
- set($val)
- sets the whole value of the output
- append($key, $value)
- Appends a value onto the output (object-based output only)
- clear()
- Clears any output stored
Use
the class will automatically dump it's value when the script dies or the object is destroyed.
$out = new intOutput();
$out->set("generic_err");
// OR
$out = new jsonOutput();
$out->append("key", "somevalue");
//OR
$out = new jsonOutput();
$out->set(array("foo", "bar", "baz"));
//OR
$out = new xmlOutput();
$out->append("foo", array("innerText" => "bar", "someAttr" => "baz"));
