header($title); $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; */ protected static function webTitle($title) { if (php_sapi_name() == "cli") { echo "$title\n"; } else { echo "
$text"; } /** * Draws a pre open element. */ protected static function webPreOpen() { echo "
"; } /** * Draws a pre open element. */ protected static function webPreClose() { echo ""; } /** * Draws a pre format block element. * * @param $text * Inner text. */ protected static function cliPre($text) { echo "$text\n"; } /** * Dump value. * * @param $var * Variable to dump. */ protected static function webDump($var) { self::preOpen(); print_r($var); self::preClose(); } /** * Dump value. * * @param $var * Variable to dump. */ protected static function cliDump($var) { print_r($var); } /** * Set the response helper. * * @param $mime * MIME type. * * @param $filename * File name. */ protected static function webHttpHeader($mime, $filename) { header("Content-type: $mime"); header("Content-Disposition: attachment; filename=$filename"); header("Pragma: no-cache"); header("Expires: 0"); } /** * Display a value with CSV format. * * @param $value * Value entry. */ protected static function webCsv($value = NULL) { echo '"'. preg_replace('/"/', '""', $value) .'",'; } /** * Display CSV titles. * * @param $format * ISIS database format. */ protected static function webCsvTitles($format) { // Format fields. foreach ($format['fields'] as $field) { self::csv($field['name']); if (isset($field['subfields']) && is_array($field['subfields'])) { foreach ($field['subfields'] as $key => $value) { self::csv($field['name'] .': '. $value); } } } } /** * Display a new CSV row. */ protected static function webCsvRow() { echo "\n"; } /** * Merge items in a CSV roll. * * @param $items * Array with items to be merged. */ protected function webMergeCsvItems($items) { if (!empty($items)) { self::csv(implode(';', $items)); } else { self::csv(); } } }