Commit 9b46e3aa authored by Cobra_Fast's avatar Cobra_Fast

Update README.md

parent 5969a00d
......@@ -153,10 +153,82 @@ $c = new bar();
$d = OOPHelper::Cast($c, 'foo'); // __castedDown will be called, since bar->c could not be copied
```
### TransientCache
Provides key-value (and arbitrary object) caching in named stores.
Intended to be used in webserver scripts with a short lifetime as it abuses a global variable (`$___transientcache`) to store all instances. Works well in `DbThing->Select($id)` kind of situations where the same object might be needed several times.
```php
function FetchObject($request_id)
{
$cache = TransientCache::Load("example"); // load or create by name
if (($result = $cache->Get($request_id)) !== false) // attempt value retrieval
return $result; // return cached result if hit
$result = $mysqlihelper->Query('SELECT * FROM things WHERE id = ?', $request_id)->fetch_object();
$cache->Set($request_id, $result); // store painstakingly computed result for later reuse
return $result;
}
```
The cache can be disabled (i.e. made to always miss) by setting the constant `DISABLE_TRANSIENT_CACHE` to a truey value.
## Data
### MySQLiHelper
Wraps a standard MySQLi instance.
```php
$sql = new MySQLiHelper(new mysqli('host', 'user', 'password', 'database'));
$insert_id = $sql->Query('INSERT INTO table (column, data) VALUES (?, ?)', 123, 'foo'); // supports prepared statements
$result = $sql->Query('SELECT * FROM table'); // returns mysqli_result
$sqli = $sql->GetLink(); // returns the underlying mysqli instace
```
### SimpleXMLHelper
Provides supplementary functions for working with SimpleXML.
```php
$xml = simplexml_load_file('test.xml');
print_r(SimpleXMLHelper::ToArray($xml));
\ No newline at end of file
print_r(SimpleXMLHelper::ToArray($xml));
```
## Math
Contains classes for common math tasks not part of PHP.
### Vector3
A three dimensional vector.
```php
$v = new Vector3(1.0, 1.5, 2.0);
$v = new Vector3(1.0); // supports short initializing, copying X to Y and Z too
$v = new Vector3(1.0, 1.5) // ... or copy Y to Z too
$v = new Vector3($v); // supports copying
$v->Length(); // calculate length from (0, 0, 0)
$v->IsZero(); // true if == (0, 0, 0)
$v->Dot(Vector2); // calculate dot product with a Vector2
$v->Multiply(2); // multiply by a scalar, returns itself
$v->Multiply($v); // multiply by a Vector3, returns itself
// ... same pattern for ->Divide(), ->Add(), and ->Substract()
$v->Inverse(); // invert (x = 1/x)
$v->Negate(); // negate (x = -x)
Vector3::sMultiply($v, 2); // multiply, returns new Vector3
// ... same pattern for ::sDivide(), ::sAdd(), and sSubstract()
```
### Vector2
A two dimensional vector. Supports all methods Vector3 does, substituting Vector3 for Vector2 in parameters.
### Color3
Extends Vector3 with specialized methods for RGB-color handling. RGB is mapped to XYZ respectively.
```php
$c = new Color3(); // see Vector3 constructor
$c->Normalize(); // clamps all values in {0..1}
$c->To255(); // returns array('r' =>, 'g' =>, 'b' =>) with values in {0..255}
$c->To255Hex(); // returns hex style color value, e.g. "#12FE34"
Color3::FromHex("#12FE34"); // parses hex style color and returns a corresponding Color3 instance
Color3::FromByte($r, $g, $b); // maps values in {0..255} to internal {0..1} representation and returns a corresponding Color3 instance
Color3::FromFloat($r, $g, $b); // synonymous to new Color3($r, $g, $b);
```
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment