From 9afef951067cfacb0e3a808e33670ae67e3e0583 Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 20 Aug 2010 15:35:06 -0300 Subject: Using magic methods at CinisisDisplayHelper --- classes/helpers/CinisisDisplayHelper.php | 222 ++++++++++++++++++++----------- 1 file changed, 141 insertions(+), 81 deletions(-) (limited to 'classes/helpers') diff --git a/classes/helpers/CinisisDisplayHelper.php b/classes/helpers/CinisisDisplayHelper.php index d00ad20..468beb1 100644 --- a/classes/helpers/CinisisDisplayHelper.php +++ b/classes/helpers/CinisisDisplayHelper.php @@ -15,13 +15,71 @@ class CinisisDisplayHelper { $this->title($title); } + /** + * Determine internal method names. + * + * @param $method + * Method name. + * + * @return + * Method name. + */ + static function methodName($method) { + if (php_sapi_name() == "cli") { + return 'cli'. ucfirst($method); + } + else { + return 'web'. ucfirst($method); + } + } + + /** + * Dispatcher, dynamic version. + * + * @param $method + * Method name. + * + * @param $arguments + * Argument list. + * + * @return + * Callback result. + */ + public function __call($method, $arguments) { + $method = $this->methodName($method); + + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } + } + + /** + * Dispatcher, static version. + * + * @param $method + * Method name. + * + * @param $arguments + * Argument list. + * + * @return + * Callback result. + */ + public static function __callStatic($method, $arguments) { + $method = self::methodName($method); + + if (is_callable('self', $method)) { + return call_user_func_array(array('self', $method), $arguments); + } + } + /** * Draws a page title. * * @param $title * Page title; */ - static function title($title) { + protected static function webTitle($title) { if (php_sapi_name() == "cli") { echo "$title\n"; } @@ -30,34 +88,37 @@ class CinisisDisplayHelper { } } + /** + * Draws title, CLI version. + * + * @param $title + * Page title; + */ + protected static function cliTitle($title) { + echo "$title\n"; + } + /** * Draws the page header. * * @param $title * Page title; */ - static function header($title) { - if (php_sapi_name() == "cli") { - echo "$title\n"; - } - else { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''. $title .''; - echo ''; - echo ''; - } + protected static function webHeader($title) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''. $title .''; + echo ''; + echo ''; } /** * Draws the page footer. */ - static function footer() { - if (php_sapi_name() != "cli") { - echo ''; - } + protected static function webFooter() { + echo ''; } /** @@ -72,14 +133,12 @@ class CinisisDisplayHelper { * @param $method * Form method. */ - static function form($content, $action = 'index.php', $method = 'get') { - if (php_sapi_name() != "cli") { - echo '
'; - echo $content; - echo ''; - echo '
'; - echo '
'; - } + protected static function webForm($content, $action = 'index.php', $method = 'get') { + echo '
'; + echo $content; + echo ''; + echo '
'; + echo '
'; } /** @@ -94,11 +153,7 @@ class CinisisDisplayHelper { * @return * Rendered text input. */ - static function form_input_text($name, $default = null) { - if (php_sapi_name() == "cli") { - return; - } - + protected static function webFormInputText($name, $default = null) { if ($default) { $default = 'value="'. $default .'"'; } @@ -121,11 +176,7 @@ class CinisisDisplayHelper { * @param $extra * Extra parameters. */ - static function navbar($entry, $entries, $action = 'index.php', $extra = NULL) { - if (php_sapi_name() == "cli") { - return; - } - + protected static function webNavbar($entry, $entries, $action = 'index.php', $extra = NULL) { // First / prev links. if ($entry != 1) { $prev = $entry - 1; @@ -156,10 +207,8 @@ class CinisisDisplayHelper { * @return * Formatted link. */ - static function link($action, $args, $title) { - if (php_sapi_name() != "cli") { - return ''. $title .''; - } + protected static function webLink($action, $args, $title) { + return ''. $title .''; } /** @@ -171,28 +220,22 @@ class CinisisDisplayHelper { * @return * Formatted link. */ - static function entry_link($entry) { - if (php_sapi_name() != "cli") { - return self::link('index.php', '?entry='. $entry, $entry); - } + protected static function webEntryLink($entry) { + return self::link('index.php', '?entry='. $entry, $entry); } /** * Draws tags for opening a table. */ - static function open_table() { - if (php_sapi_name() != "cli") { - echo ''; - } + protected static function webOpenTable() { + echo '
'; } /** * Draws tags for closing a table. */ - static function close_table() { - if (php_sapi_name() != "cli") { - echo '
'; - } + protected static function webCloseTable() { + echo ''; } /** @@ -201,13 +244,18 @@ class CinisisDisplayHelper { * @param $text * Inner text. */ - static function h2($text) { - if (php_sapi_name() == "cli") { - echo "$text\n"; - } - else { - echo "

$text

"; - } + protected static function webH2($text) { + echo "

$text

"; + } + + /** + * Draws a h2 element, CLI version. + * + * @param $text + * Inner text. + */ + protected static function cliH2($text) { + echo "$text\n"; } /** @@ -216,25 +264,32 @@ class CinisisDisplayHelper { * @param $text * Inner text. */ - static function h3($text) { - if (php_sapi_name() == "cli") { - echo "$text\n"; - } - else { - echo "

$text

"; - } + protected static function webH3($text) { + echo "

$text

"; + } + + /** + * Draws a h3 element, CLI version. + * + * @param $text + * Inner text. + */ + protected static function cliH3($text) { + echo "$text\n"; } /** * Draws a line break element. */ - static function br() { - if (php_sapi_name() == "cli") { - echo "\n"; - } - else { - echo "
"; - } + protected static function webBr() { + echo "
"; + } + + /** + * Draws a line break element, CLI version. + */ + protected static function cliBr() { + echo "\n"; } /** @@ -243,12 +298,17 @@ class CinisisDisplayHelper { * @param $text * Inner text. */ - static function pre($text) { - if (php_sapi_name() == "cli") { - echo "$text\n"; - } - else { - echo "
\n$text
"; - } - } + protected static function webPre($text) { + echo "
\n$text
"; + } + + /** + * Draws a pre format block element. + * + * @param $text + * Inner text. + */ + protected static function cliPre($text) { + echo "$text\n"; + } } -- cgit v1.2.3