Overview

Namespaces

  • Csim
    • Controller
    • Model
    • Util
  • PHP

Classes

  • Util
  • WebConsole
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Csim\Util;
 4: 
 5: /** * *************************************************************
 6:  * Class used to log value of variable, array on Browser console.
 7:  * author: Tousif Khan     
 8:  * Downloaded from http://www.techzoo.org/web-programming/debugging-php-in-browsers-javascript-console.html
 9:  * ************************************************************** */
10: final class WebConsole {
11: 
12:     private function __construct($param) {
13:         
14:     }
15: 
16:     private static function write($data, $type = 'info') {
17:         $method_types = array('error', 'info', 'log', 'warn');
18:         $msg_type = '';
19:         if (in_array($type, $method_types)) {
20:             $msg_type = sprintf("console.%s", $type);
21:         } else {
22:             $msg_type = sprintf("console.%s", 'info');
23:         }
24: 
25:         if (is_array($data)) {
26:             echo("<script>$msg_type('" . implode(', ', $data) . "');</script>");
27:         } else {
28:             echo("<script>$msg_type('" . $data . "');</script>");
29:         }
30:     }
31: 
32:     public static function info($data) {
33:         self::write($data);
34:     }
35: 
36:     public static function error($data) {
37:         self::write($data, 'error');
38:     }
39: 
40:     public static function log($data) {
41:         self::write($data, 'log');
42:     }
43: 
44:     public static function warn($data) {
45:         self::write($data, 'warn');
46:     }
47: 
48: }
49: 
csim-jquery-nophpfw API documentation generated by ApiGen 2.8.0