예제 #1
0
 /**
  * xapp generic dump function will try to dump any input in first parameter using the passed value in second
  * parameter or if not set by default echo and print_r in cli or none cli mode. the first parameter can by
  * anything that can be printed to screen via print_r function. the second parameter can by a php function,
  * an object or class name the implements the dump method as public static or none static method. the dump
  * method of object must have its own logic for dumping objects since this function will do nothing else
  * but calling the method returning void. you can also use a php function like json_encode in second parameter
  * to encode and dump your input. overwrite like:
  *
  * <code>
  *      function xapp_dump($what, $with = null)
  *      {
  *          //your custom code here
  *      }
  * </code>
  *
  * @param mixed $what expects any type of variable
  * @param null|string|callable|object $with expects optional value with what to output first parameter
  */
 function xdump($what, $with = null)
 {
     $res = '';
     ob_start();
     if ($with !== null) {
         if (is_callable($with) && function_exists($with)) {
             $res .= call_user_func($with, $what);
         } else {
             if (is_object($with) && method_exists($with, 'dump')) {
                 $res .= $with->dump($what);
             } else {
                 if (is_string($with)) {
                     if (stripos($with, 'xapp') !== false) {
                         if (!xapped($with)) {
                             xapp_import(lcfirst(str_replace('_', '.', $with)));
                         }
                     }
                     if (method_exists($with, 'dump')) {
                         $res .= call_user_func(array($with, 'dump'), $what);
                     }
                 }
             }
         }
     }
     if (strlen($o = (string) ob_get_contents()) > 0) {
         ob_end_clean();
         $res .= $o;
     } else {
         @ob_end_clean();
         $res .= strtolower(php_sapi_name()) === 'cli' ? print_r($what, true) : "<pre>" . print_r($what, true) . "</pre>";
     }
     return $res;
 }
예제 #2
0
파일: core.php 프로젝트: xamiro-dev/xamiro
 /**
  * xapp option shortcut xapp_reset_options will reset first params options which can be:
  * 1) array = reset array
  * 2) object = object instance implementing xapp option handling or not
  * 3) string = object class name as string to handle static classes/options
  * 4) null = null when called inside class for xapp option handling for auto caller determination
  *
  * @param null|object|string|array $mixed expects value according to explanation above
  * @return void
  */
 function xapp_reset_options(&$mixed = null)
 {
     if (is_array($mixed)) {
         $mixed = array();
     } else {
         if (xapped()) {
             Xapp::resetOptions($mixed);
         } else {
             if (is_object($mixed) && xapp_can_options($mixed)) {
                 $mixed->options = array();
             } else {
                 if (is_string($mixed) && xapp_can_options($mixed)) {
                     $mixed::$options = array();
                 }
             }
         }
     }
 }