Пример #1
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;
});
Пример #2
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);