aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-08-20 15:35:06 -0300
committerSilvio <silvio@devlet.com.br>2010-08-20 15:35:06 -0300
commit9afef951067cfacb0e3a808e33670ae67e3e0583 (patch)
treedb00dd78810791ce2141164d4a9b360046699e94
parent9d6df04cfa4f4afb8e4d3bfadfefc02ff84607f2 (diff)
downloadcinisis-9afef951067cfacb0e3a808e33670ae67e3e0583.tar.gz
cinisis-9afef951067cfacb0e3a808e33670ae67e3e0583.tar.bz2
Using magic methods at CinisisDisplayHelper
-rw-r--r--apps/field.php6
-rw-r--r--apps/index.php2
-rw-r--r--apps/repetition.php6
-rw-r--r--apps/subfield.php8
-rw-r--r--classes/helpers/CinisisDisplayHelper.php222
5 files changed, 152 insertions, 92 deletions
diff --git a/apps/field.php b/apps/field.php
index 3d36df6..697bd90 100644
--- a/apps/field.php
+++ b/apps/field.php
@@ -12,8 +12,8 @@ $fid = CinisisHttpHelper::get_numeric_arg('fid');
// Draw the document.
$display = new CinisisDisplayHelper('Field finder');
-$form = $display->form_input_text('entry', $entry);
-$form .= $display->form_input_text('fid', $fid);
+$form = $display->formInputText('entry', $entry);
+$form .= $display->formInputText('fid', $fid);
$display->form($form, basename(__FILE__));
// Get a db instance.
@@ -31,7 +31,7 @@ if ($isis) {
// Format output.
echo "<pre>\n";
echo "Selected field: $fid: ". $field['name'] ."\n";
- echo "Showing entry ". $display->entry_link($entry) ." from ". $isis->entries ." total entries.\n";
+ echo "Showing entry ". $display->entryLink($entry) ." from ". $isis->entries ." total entries.\n";
echo "Repetitions found: ". count($result[$field['name']]) .".\n";
echo "\n";
print_r($result[$field['name']]);
diff --git a/apps/index.php b/apps/index.php
index cd5e5bb..fd8877b 100644
--- a/apps/index.php
+++ b/apps/index.php
@@ -11,7 +11,7 @@ $entry = CinisisHttpHelper::get_numeric_arg('entry');
// Draw the document.
$display = new CinisisDisplayHelper('Isis Navigator');
-$display->form($display->form_input_text('entry', $entry));
+$display->form($display->formInputText('entry', $entry));
// Get a db instance.
$isis = new Cinisis();
diff --git a/apps/repetition.php b/apps/repetition.php
index a45e6f4..9e47361 100644
--- a/apps/repetition.php
+++ b/apps/repetition.php
@@ -12,8 +12,8 @@ $fid = CinisisHttpHelper::get_numeric_arg('fid');
// Draw the document.
$display = new CinisisDisplayHelper('Repetition finder');
-$form = $display->form_input_text('entry', $entry);
-$form .= $display->form_input_text('fid', $fid);
+$form = $display->formInputText('entry', $entry);
+$form .= $display->formInputText('fid', $fid);
$display->form($form, basename(__FILE__));
// Get a db instance.
@@ -31,7 +31,7 @@ if ($isis) {
// Format output.
echo "<pre>\n";
echo "Selected field: $fid: ". $field['name'] ."\n";
- echo "Showing entry ". $display->entry_link($entry) ." from ". $isis->entries ." total entries.\n";
+ echo "Showing entry ". $display->entryLink($entry) ." from ". $isis->entries ." total entries.\n";
echo "Repetitions found: ". count($result[$field['name']]) .".\n";
echo "\n";
print_r($result[$field['name']]);
diff --git a/apps/subfield.php b/apps/subfield.php
index a7a33f2..ba37291 100644
--- a/apps/subfield.php
+++ b/apps/subfield.php
@@ -13,9 +13,9 @@ $sid = CinisisHttpHelper::get_textual_arg('sid');
// Draw the document.
$display = new CinisisDisplayHelper('Subfield finder');
-$form = $display->form_input_text('entry', $entry);
-$form .= $display->form_input_text('fid', $fid);
-$form .= $display->form_input_text('sid', $sid);
+$form = $display->formInputText('entry', $entry);
+$form .= $display->formInputText('fid', $fid);
+$form .= $display->formInputText('sid', $sid);
$display->form($form, basename(__FILE__));
// Get a db instance.
@@ -35,7 +35,7 @@ if ($isis) {
echo "<pre>\n";
echo "Selected field: $fid: ". $field['name'] .".\n";
echo "Selected subfield: $sid: $subfield.\n";
- echo "Showing entry ". $display->entry_link($entry) ." from ". $isis->entries ." total entries.\n";
+ echo "Showing entry ". $display->entryLink($entry) ." from ". $isis->entries ." total entries.\n";
echo "Repetitions found: ". count($result[$field['name']]) .".\n";
echo "\n";
print_r($result[$field['name']]);
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
@@ -16,12 +16,70 @@ class CinisisDisplayHelper {
}
/**
+ * 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";
}
@@ -31,33 +89,36 @@ 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 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
- echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">';
- echo '<head>';
- echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
- echo '<title>'. $title .'</title>';
- echo '</head>';
- echo '<body>';
- }
+ protected static function webHeader($title) {
+ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
+ echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">';
+ echo '<head>';
+ echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
+ echo '<title>'. $title .'</title>';
+ echo '</head>';
+ echo '<body>';
}
/**
* Draws the page footer.
*/
- static function footer() {
- if (php_sapi_name() != "cli") {
- echo '</body>';
- }
+ protected static function webFooter() {
+ echo '</body>';
}
/**
@@ -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 '<form action="'. $action .'" method="'. $method .'">';
- echo $content;
- echo '<input type="submit" />';
- echo '</form>';
- echo '<br />';
- }
+ protected static function webForm($content, $action = 'index.php', $method = 'get') {
+ echo '<form action="'. $action .'" method="'. $method .'">';
+ echo $content;
+ echo '<input type="submit" />';
+ echo '</form>';
+ echo '<br />';
}
/**
@@ -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 '<a href="'. $action . $args .'">'. $title .'</a>';
- }
+ protected static function webLink($action, $args, $title) {
+ return '<a href="'. $action . $args .'">'. $title .'</a>';
}
/**
@@ -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 '<table><tr>';
- }
+ protected static function webOpenTable() {
+ echo '<table><tr>';
}
/**
* Draws tags for closing a table.
*/
- static function close_table() {
- if (php_sapi_name() != "cli") {
- echo '</tr></table>';
- }
+ protected static function webCloseTable() {
+ echo '</tr></table>';
}
/**
@@ -201,13 +244,18 @@ class CinisisDisplayHelper {
* @param $text
* Inner text.
*/
- static function h2($text) {
- if (php_sapi_name() == "cli") {
- echo "$text\n";
- }
- else {
- echo "<h2>$text</h2>";
- }
+ protected static function webH2($text) {
+ echo "<h2>$text</h2>";
+ }
+
+ /**
+ * 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 "<h3>$text</h3>";
- }
+ protected static function webH3($text) {
+ echo "<h3>$text</h3>";
+ }
+
+ /**
+ * 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 "<br />";
- }
+ protected static function webBr() {
+ echo "<br />";
+ }
+
+ /**
+ * 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 "<pre>\n$text</pre>";
- }
- }
+ protected static function webPre($text) {
+ echo "<pre>\n$text</pre>";
+ }
+
+ /**
+ * Draws a pre format block element.
+ *
+ * @param $text
+ * Inner text.
+ */
+ protected static function cliPre($text) {
+ echo "$text\n";
+ }
}