Created
November 20, 2011 17:47
-
-
Save jadell/1380565 to your computer and use it in GitHub Desktop.
UTF-8 with Neo4jPHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
use Everyman\Neo4j\Transport, | |
Everyman\Neo4j\Client, | |
Everyman\Neo4j\Index, | |
Everyman\Neo4j\Relationship, | |
Everyman\Neo4j\Node; | |
error_reporting(-1); | |
ini_set('display_errors', 1); | |
function loaderTestAutoloader($sClass) | |
{ | |
$sLibPath = __DIR__.'/../lib/'; | |
$sClassFile = str_replace('\\',DIRECTORY_SEPARATOR,$sClass).'.php'; | |
$sClassPath = $sLibPath.$sClassFile; | |
if (file_exists($sClassPath)) { | |
require($sClassPath); | |
} | |
} | |
spl_autoload_register('loaderTestAutoloader'); | |
$cmd = !empty($argv[1]) ? $argv[1] : null; | |
$from = ''; | |
$to = ''; | |
if (!$cmd) { | |
echo <<<HELP | |
Usage: | |
{$argv[0]} | |
Display usage instructions | |
{$argv[0]} create | |
Create a node with UTF-8 properties. | |
{$argv[0]} node <id> | |
Retrieve a node by id. | |
HELP; | |
exit(0); | |
} | |
$transport = new Transport('xubuntu'); | |
$client = new Client($transport); | |
// Initialize the data | |
if ($cmd == 'create') { | |
$node = $client->makeNode() | |
->setProperties(array( | |
'name' => 'Keanu Reeves', | |
'property1' => 'πᾂ◈', | |
'property2' => '⚀ ⚁ ⚂with some ascii⚃ ⚄ ⚅ ⚆ ⚇ ⚈ ⚉', | |
))->save(); | |
echo "Node ".$node->getId()." created:\n"; | |
print_r($node->getProperties()); | |
// Find a path | |
} else if ($cmd == 'node' && !empty($argv[2])) { | |
$node = $client->getNode($argv[2]); | |
if ($node) { | |
echo "Node ".$node->getId()." found:\n"; | |
print_r($node->getProperties()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment