Beispiel #1
0
function dumpNode(\SamIT\ExpressionManager\Nodes\Node $n, $indent = 0)
{
    switch (get_class($n)) {
        case \SamIT\ExpressionManager\Nodes\FunctionNode::class:
            out($n->getName() . "\n", $indent);
            dumpNode($n->getOperand(), $indent + 4);
            break;
        case \SamIT\ExpressionManager\Nodes\ListNode::class:
            out("List: [\n", $indent);
            for ($i = 0; $i < $n->length(); $i++) {
                dumpNode($n->item($i), $indent + 4);
            }
            out("]\n", $indent);
            break;
        case \SamIT\ExpressionManager\Nodes\BinaryNode::class:
            out($n->getOperator() . "\n", $indent);
            out("Left:\n", $indent);
            dumpNode($n->getOperand1(), $indent + 4);
            out("Right:\n", $indent);
            dumpNode($n->getOperand2(), $indent + 4);
            break;
        case \SamIT\ExpressionManager\Nodes\UnaryNode::class:
            out($n->getOperator() . "\n", $indent);
            out("Operand:\n", $indent);
            break;
        case \SamIT\ExpressionManager\Nodes\VariableNode::class:
            out("Variable `{$n->getName()}`\n", $indent);
            break;
        case \SamIT\ExpressionManager\Nodes\ValueNode::class:
            if (is_int($n->getValue())) {
                out("(int) {$n->getValue()}\n", $indent);
            } elseif (is_float($n->getValue())) {
                out("(float) {$n->getValue()}\n", $indent);
            } elseif (is_string($n->getValue())) {
                out("(string) {$n->getValue()}\n", $indent);
            }
            break;
        case \SamIT\ExpressionManager\Nodes\Token::class:
            out($n . "\n", $indent);
            break;
        default:
            var_dump($n);
    }
}
Beispiel #2
0
function dumpNode($tree, $level = 0)
{
    foreach ($tree as $key => $node) {
        $k = '';
        if (is_string($key)) {
            $k = $key . ' -> ';
        }
        if (is_object($node)) {
            echo str_repeat(" ", $level) . $k . colorGreen(get_class($node)) . "\n";
        } else {
            if (!is_array($node)) {
                echo str_repeat(" ", $level) . $k . print_r($node, true) . "\n";
            } else {
                if (strlen($k) > 0) {
                    echo str_repeat(" ", $level) . $k . ":\n";
                }
            }
        }
        if ($node instanceof Traversable || is_array($node)) {
            dumpNode($node, $level + 1);
        }
    }
}
Beispiel #3
0
function load_config($file)
{
    global $dictionary;
    if (!file_exists($file)) {
        return;
    }
    // Load via SimpleXML.
    $xml_document = simplexml_load_file($file);
    // Add all of the settings to the dictionary.
    foreach ($xml_document->xpath('/settings/*') as $item) {
        $item_content = dumpNode($item);
        $item_name = getTagName($item);
        if ($item_name[strlen($item_name) - 1] == "/") {
            $item_name = substr($item_name, 0, strlen($item_name) - 1);
        }
        $dictionary["{$item_name}"] = $item_content;
    }
    $servers = array();
    $uploadFileType = array();
    // Add all of the languages to the dictionary.
    foreach ($xml_document->xpath('/settings/servers/server') as $item) {
        //print_r($item);
        $temp = object2array($item);
        array_push($servers, $temp);
    }
    foreach ($xml_document->xpath('/settings/uploadFileType') as $item) {
        $temp = object2array($item);
        array_push($uploadFileType, $temp);
    }
    $dictionary["servers"] = $servers;
    $dictionary["uploadFileType"] = $uploadFileType;
    //  print_r($dictionary);
}
Beispiel #4
0
    $data = $curl->get($url);
    $output = htmlentities($data);
    $dom = new DOMDocument();
    @$dom->loadHTML($data);
    $xp = new DOMXPath($dom);
    $query = $xp->query($xpath);
    foreach ($query as $q) {
        $debug .= dumpNode($q);
        if ($sub1) {
            $q1 = $xp->query($sub1, $q);
            foreach ($q1 as $c1) {
                $debug .= dumpNode($c1, '  ');
                if ($sub2) {
                    $q2 = $xp->query($sub2, $c1);
                    foreach ($q2 as $c2) {
                        $debug .= dumpNode($c2, '    ');
                    }
                }
            }
        }
    }
}
?>
<html>
    <head><title>XPath Playground</title></head>
    <body>
        <form>
            <div>URL: <input type="text" name="url" id="url" size="80" value="<?=$url?>"/></div>
            <div>XPath: <input type="text" name="xpath" id="xpath" size="80" value="<?=$xpath?>"/></div>
            <div>Sub-1: <input type="text" name="sub1" id="sub1" size="80" value="<?=$sub1?>"/></div>
            <div>Sub-2: <input type="text" name="sub2" id="sub2" size="80" value="<?=$sub2?>"/></div>