/** * Sets a node factory. * * @param NodeFactory $factory */ public function setNodeFactory(NodeFactory $factory) { if ($factory === null) { throw new Exception("Parameter \$factory can not be null"); } $this->_nodeFactory = $factory; $this->_nodeFactory->setFilterContainer($this->getFilterContainer()); }
/** * @param NodeFactory $nodeFactory Instance of the NodeFactory to use. * @param string $value Value of the node. * @param string $type Can be uri, bnode, var or literal * @param string $datatype URI of the datatype (optional) * @param string $language Language tag (optional) * @return Node Node instance */ public static function createNodeInstance(NodeFactory $nodeFactory, $value, $type, $datatype = null, $language = null) { switch ($type) { case 'uri': return $nodeFactory->createNamedNode($value); case 'bnode': return $nodeFactory->createBlankNode($value); case 'literal': return $nodeFactory->createLiteral($value, $datatype, $language); case 'var': return $nodeFactory->createAnyPattern(); default: throw new \Exception('Unknown $type given: ' . $type); } }
public function test() { $nf = new NodeFactory('utf-8'); $expected = $nf->form(['class' => 'someclass anotherclass', 'id' => 'someid'], $nf->input(['type' => 'hidden', 'value' => '12345', 'name' => 'xsrf_token']), $nf->div('onAttr')); $nf->onAttr('id', 'someid', function ($attributes, $children) use($nf) { $children[] = $nf->div('onAttr'); return [$attributes, $children]; }); $nf->onClass('someclass', function ($attributes, $children) { $attributes['class'] = $attributes['class'] . ' anotherclass'; return [$attributes, $children]; }); $nf->onTag('form', function ($attributes, $children) use($nf) { $children[] = $nf->input(['type' => 'hidden', 'value' => '12345', 'name' => 'xsrf_token']); return [$attributes, $children]; }); $node = $nf->form(['class' => 'someclass', 'id' => 'someid']); $this->assertEquals((string) $expected, (string) $node); }
/** * @return array */ public function exportTree() { $tree = new TreeComposite(); $tree->createNode(new Node('country')); $tree->createNode(new Node('kiev'), $tree->getNode('country')); $tree->createNode(new Node('kremlin'), $tree->getNode('kiev')); $tree->createNode(new Node('house'), $tree->getNode('kremlin')); $tree->createNode(new Node('tower'), $tree->getNode('kremlin')); $tree->createNode(new Node('moskow'), $tree->getNode('country')); $tree->attachNode($tree->getNode('kremlin'), $tree->getNode('moskow')); $tree->createNode(new Node('maidan'), $tree->getNode('kiev')); $tree->deleteNode($tree->getNode('kiev')); $tree->createNode(NodeFactory::create('domen', 'product1')); $tree->createNode(NodeFactory::create('RU', 'product2'), $tree->getNode('domen')); $tree->createNode(NodeFactory::create('EU', 'product2'), $tree->getNode('domen')); $tree->createNode(NodeFactory::create('RU', 'product2'), $tree->getNode('domen')); return $tree->export(); }
public function test_UriInjectionWithWhitespace() { $nf = new NodeFactory('utf-8'); $this->setExpectedException('InvalidArgumentException'); $nf->a(['href' => ' javascript: alert(1) ']); }
public function test_childNeitherObjectNorString() { $nf = new NodeFactory('utf-8'); $node = $nf->div('1', 1); $this->assertEquals($nf->div('1', '1'), $node); }
<?php // STANDALONE $ctype = "application/json"; $ctype = "text/html"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: " . $ctype); echo "<pre>JSON<br/>"; $json = array("site" => array("hash" => $siteHash, "token" => $siteToken, "timestamp" => getmicrotime())); echo json_encode($json); echo "<hr/>"; $n = new NodeFactory($mt->system["dbCon"]); $obj = $n->getNode(131); echo $obj . "<br/>"; print_r($obj); $obj = $n->getNode(100000780); echo $obj . "<br/>"; print_r($obj); $obj = $n->getNode(100000778); echo $obj . "<br/>"; print_r($obj); //$obj = $obj->save(); print_r($obj); //print_r($n->getNode(100000780)); //print_r($n->getNode(100000778)); /*print_r($n->getNode(412)); $n = new Node($mt->system ["dbCon"],100000780); print_r($n); $n = new Node($mt->system ["dbCon"],100000778);
$route = new Route(); $route->start(); $tree = new TreeComposite(); $tree->createNode(new Node('country')); $tree->createNode(new Node('kiev'), $tree->getNode('country')); $tree->createNode(new Node('kremlin'), $tree->getNode('kiev')); $tree->createNode(new Node('house'), $tree->getNode('kremlin')); $tree->createNode(new Node('tower'), $tree->getNode('kremlin')); $tree->createNode(new Node('moskow'), $tree->getNode('country')); $tree->attachNode($tree->getNode('kremlin'), $tree->getNode('moskow')); $tree->createNode(new Node('maidan'), $tree->getNode('kiev')); $tree->deleteNode($tree->getNode('kiev')); $tree->createNode(NodeFactory::create('domen', 'product1')); $tree->createNode(NodeFactory::create('RU', 'product2'), $tree->getNode('domen')); $tree->createNode(NodeFactory::create('EU', 'product2'), $tree->getNode('domen')); $tree->createNode(NodeFactory::create('RU', 'product2'), $tree->getNode('domen')); function print_pre($ar) { echo "<pre>"; print_r($ar); echo "</pre>"; } ?> <!DOCTYPE html> <html> <head> <title>Senior task</title> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> <link rel="stylesheet" href="style.css"> <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>