Exemplo n.º 1
0
 public static function dump_r(&$raw, $ret = false, $html = true, $depth = 1000.0, $expand = 1000.0)
 {
     $root = Type::fact($raw, [], $depth);
     // remove array recursion detection keys from orig
     foreach (Type::$dic as $key2 => &$raw_ref) {
         if (is_array($raw_ref)) {
             unset($raw_ref[Node\_Array::$ref_key]);
         }
     }
     self::cleanArrRefTags($root);
     Type::$dic = [];
     // get the input arg passed to the function
     $src = debug_backtrace();
     $idx = strpos($src[0]['file'], 'dump_r.php') ? 1 : 0;
     $src = (object) $src[$idx];
     $file = file($src->file);
     $i = 1;
     do {
         $line = $file[$src->line - $i++];
     } while (strpos($line, 'dump_r') === false);
     preg_match('/dump_r\\((.+?)\\)?(?:$|;|\\?>)/', $line, $m);
     $key = $m[1];
     $key = trim(explode(',', $key)[0]);
     if (PHP_SAPI == 'cli' || !$html) {
         $out = $root->text0($src->file, $src->line, $key);
     } else {
         $out = $root->html0($src->file, $src->line, $key, $expand);
     }
     if ($ret) {
         return $out;
     }
     echo $out;
 }
Exemplo n.º 2
0
                        $type->class[] = '_JSON\\_Array';
                        $type->inter = $json;
                    } else {
                        if (substr($raw, 0, 5) == '<?xml') {
                            // strip namespaces
                            $raw = preg_replace('/<(\\/?)[\\w-]+?:/', '<$1', preg_replace('/\\s+xmlns:.*?=".*?"/', '', $raw));
                            if ($xml = simplexml_load_string($raw)) {
                                $type->class[] = '_XML';
                                $type->inter = $xml;
                            }
                            // _XML\\_Array
                            // _XML\\_Object
                        }
                    }
                }
            }
        }
    }
    return $type;
});
Type::hook('_Resource', function ($raw, Type $type, $path) {
    $kind = get_resource_type($raw);
    // this is valuable for other resources
    switch ($kind) {
        case 'stream':
            $meta = stream_get_meta_data($raw);
            $type->class[] = '_Stream';
            $type->inter = $meta;
    }
    return $type;
});
Exemplo n.º 3
0
function csv2array($file)
{
    $csv = [];
    $rows = array_map('str_getcsv', file($file));
    $header = array_shift($rows);
    foreach ($rows as $row) {
        $csv[] = array_combine($header, $row);
    }
    return $csv;
}
// prevent arrays keyed under 'c' from dumping sub-nodes
Type::hook('_Array', function ($raw, Type $type, $path) {
    if (end($path) === 'c') {
        $type->depth = 1;
    }
    return $type;
});
// prevent anything keyd under 'xxx' from dumping
Type::hook('*', function ($raw, Type $type, $path) {
    if (end($path) === 'xxx') {
        return false;
    }
});
// tag specific keys with addl rend classes
Type::hook('*', function ($raw, Type $type, $path) {
    if (end($path) === 'yyy') {
        $type->classes[] = 'marked';
    }
    return $type;
});
dump_r($stuff);