To quickly start with Firework, just unpack the ZIP file and add a line on top of your existing PHP files:
require_once("Firework/_Firework.php");
This will enable you to instantly use all classes and features implemented in Firework without the need of separately include a bunch of required files. _Firework.php does it all automatically.
require_once("Firework/Browser.php");
$browser = new Browser; echo $browser->getUserAgent();
Returns the original UserAgent string sent by the client's browser like in $_SERVER["HTTP_USER_AGENT"].
$browser = new Browser; echo $browser->getName();
This returns one of the following strings or null if not detected.
$browser = new Browser; echo $browser->getVersion();
Returns the browser's major and sub version. Version 3.6.2 is returned as 3.6 (float).
$browser = new $browser; echo $browser->getEngine();
Returns one of the following strings (the browser's rendering engine) or null if not detected.
$browser = new $browser; echo $browser->getDevice();
Returns the name of the device the browser is running at or null if not detected. For simplification some device types were merged together as we separate devices by their type of handling things.
echo Browser::getProtocol();
Returns the protocol used (http or https).
echo Browser::getHost();
Returns the used host name.
echo Browser::getUri();
Returns the actual absolute URI, beginning with a slash, including the query string but excluding any anchor.
echo Browser::getUrl();
Returns the actual URL, beginning with "http(s)", including the query string but excluding any anchor.
Browser::restrictToHost("example.com");
Automatically relocates to the given $host, if getHost() does not match $host. This is especially useful if you do not like to offer the same content at multiple domains.
If headers are already sent, the function returns false. If no modification is needed, it returns true.
This method let the script die() in case of mismatch.
$browser = new $browser; echo $browser->getUri() . "\n"; print_r($browser->getPathParts(2));
Returns an array of the directory parts in the current URI.
If $offset is set to 2, the first 2 items will be deleted.
/blog/example/2010-01-05/first-moments-of-our-marriage.html
Array(
[0] => 2010-01-05
[1] => first-moments-of-our-marriage.html
)
$browser = new $browser; echo $browser->getUri() . "\n"; print_r($browser->getQueryParts());
Returns an array of the query variables in the current URI.
/index.php?page=5&msg=foobar
Array(
[page] => 5
[msg] => foobar
)
require_once("Firework/Cache.php");
Work in progress.
require_once("Firework/Captcha.php");
$captcha = new Captcha;
$browser->setKey("MySecretKey");
Enables you to set a key for encryption and decryption.
The key must be kept secret and must not be submitted to the client.
Captcha requires the Firework class Str.
$captcha = new Captcha;
$browser->setKey("MySecretKey");
echo $browser->getData();
Returns a unique data string that represents the string to be entered in an encrypted form.
This string can only be decrypted using the priviously set secret key via setKey().
$captcha = new Captcha;
$browser->setKey("MySecretKey");
$browser->setData("EncryptedDataReturnedByGetDataUsingASecretKey");
Sets the encrypted data string for further usage with render().
Returns false on error.
$captcha = new Captcha;
$browser->setKey("MySecretKey");
// Generate data in the script file hosting the image
$browser->setData($_GET["data"]);
$browser->render(0xFF,0xE8,0xA4);
Renders the Captcha to an image in JPEG format.
This method should be called solely in a separate script file.
You can optionally set a $red, $green and $blue value (int) to color the image specifically.
require_once("Firework/Date.php");
Date enables you to easily calculate with date and time information with precision higher than a millisecond.
$date = new Date;
$date->setTime(1262682000);
// or:
$date->setTime("2010-01-05 10:00:00");
// or NOW:
$date->setTime()
Sets or resets the date and time information.
This method can implicitly be called using the class constructor.
$date = new Date("2010-01-05");
If $dateTime is null, date/time information will be set to the current date/time/microtime.
In case of error this method returns false.
setDate() is an alias method for setTime().
$date = new Date("2010-01-05 10:00:00");
echo $date->getUnixtime();
Returns the Unix Timestamp (int number of seconds since Januar 1 1970 00:00:00 GMT) representing the current date/time information.
1262682000
$date = new Date("2010-01-05 10:00:00");
$date->addSeconds(7.5179912);
echo $date->getMicrotime();
Returns the Unix Timestamp with micro precision (float number of seconds since Januar 1 1970 00:00:00 GMT) representing the current date/time information.
This method is equivalent to getUnixtime() except the higher precision and the float return.
1262682007.5179912
Returns the second/minute/hour/day/month/year (int) of the current date/time information.
Adds the number of seconds/minutes/hours/days/months/years $param (float) to the current date/time information.
addMonths() and addYears() can produce an incalculable error of few days, as every month has another day count and every year has a bit more than 365 days, though the methods try their best to reduce known errors.
require_once("Firework/Debug.php");
This Debug class is built to override the internal error handling of PHP.
Debug::setHandler();
// is the same as:
Debug::setHandler(Debug::HANDLER_INTERNAL);
// or to reset to PHP handler:
Debug::setHandler(Debug::HANDLER_PHP);
// or to set to user defined handler:
Debug::setHandler("MyClass::MyHandler");
Sets the global error handler for all catchable errors.
This is required just once a script, right at the beginning.
If you have included Firework/_Firework.php, this is already done for you.
static setHandler();
Debug::error("This is a user defined error.",E_WARNING);
Displays an error using the message $msg (string) and the error type $type.
$type can be set to the constants E_ERROR, E_WARNING or E_NOTICE.
$data = array("Foo","Bar");
Debug::dump($data);
Displays $data (mixed) for debugging purposes.
If the optional parameter $useHtml is set to false (default: true), no HTML tags will be used.
require_once("Firework/Domain.php");
Work in progress.
require_once("Firework/Esel.php");
Esel is a parser for modified CSS (Cascading Style Sheet).
The syntax is quite similar to CSS, but enables you to use constants (commonly called "variables") and some other features described here.
ESEL (Enhanced Styling Embedding Language) is similar but different to e.g. LESS. It does not need to be manually compiled, you can include a .esl just like you would a .css file.
Esel requires the Firework class Cache.
<html>
<head>
<?php Esel::embed("mystyles.esl") ?>
</head>
<body>This is a test.</body>
</html>
This static method is used in the <head>-part of any PHP-enabled (X)HTML file.
It reads, compares and parses the ESEL file and outputs (echo) the propper <link> element.
Warning: It is necessary to set a global cache-directory using the following line before using embed().
Cache::setDirectory("public/myGlobalCacheDirectory");
Work in progress.
Work in progress.
Work in progress.
Work in progress.
Work in progress.
Work in progress.
Work in progress.
Work in progress.