Skip to content

Commit

Permalink
Add Application logic helpers
Browse files Browse the repository at this point in the history
App::Condition($bool, $closure);
App::ConditionBaseRedirect($bool, $partialUrl);
App::ConditionRedirect($bool, $url);
App::ConditionError($bool, $errorMessage);
  • Loading branch information
jlesueur committed Aug 29, 2012
1 parent f6cbadc commit acafa59
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion framework/core/app/Application.php
Expand Up @@ -13,5 +13,65 @@ function __construct()
// $this->init();
}

public function init() {}
public function init() {}

/*
*
* name: Condition
* @param bool a true/false condition
* @param closure if !bool, then closure()
* @return
*
*/
static public function Condition($bool, $closure)
{
if(!$bool)
$closure();
}

/*
*
* name: ConditionBaseRedirect
* @param bool
* @param url an application url (everything after index.php)
* @return
*
*/
static public function ConditionBaseRedirect($bool, $url)
{
self::Condition($bool, function () use ($url) {
BaseRedirect($url);
});
}

/*
*
* name: ConditionRedirect
* @param bool
* @param url a full url
* @return
*
*/
static public function ConditionRedirect($bool, $url)
{
self::Condition($bool, function () use ($url) {
redirect($url);
});
}

/*
*
* name: ConditionError
* @param bool
* @param errorMessage An error message to log with the error.
* @return
*
*/
static public function ConditionError($bool, $errorMessage)
{
self::Condition($bool, function () use ($errorMessage) {
trigger_error($errorMessage);
die();
});
}
}

0 comments on commit acafa59

Please sign in to comment.