Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "everyman/neo4jphp",
"name": "tomcorbett/neo4jphp",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing package name ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Kwattro sorry I have been away for 2 weeks so just seeing this now. Anything I changed was because I was branching off of this project as after speaking to @jadell he didn't have time to review and advised I just forked and continued using my fork, so I am for now as I am actively using this library in one of my own projects.

If we do get some people to review my changes of course I will go through all changes with them and happy to change everything back.

"type": "library",
"description": "Wrapper for the Neo4j graph database REST interface",
"keywords": ["neo4j","graph","database"],
"homepage": "http://github.com/jadell/neo4jphp/wiki",
"license": "MIT",
"authors": [
{"name": "Josh Adell", "email": "josh.adell@gmail.com", "homepage": "http://joshadell.com"}
{"name": "Josh Adell", "email": "josh.adell@gmail.com", "homepage": "http://joshadell.com"},
{"name": "Thomas Corbett", "email": "thomas.michael.corbett@gmail.com"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe provide a contributors name that link to the repository contributors : https://github.com/jadell/neo4jphp/graphs/contributors

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kwattro Yes I did mean to do that, all of this was done pretty quickly but completely agree!

],
"require": {
"php": ">=5.3.0",
Expand All @@ -19,5 +20,6 @@
},
"autoload": {
"psr-0": {"Everyman\\Neo4j":"lib/"}
}
},
"version": "1.0.1-beta"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest tag is 0.1.0, so should be 0.1.1 IMO

}
81 changes: 81 additions & 0 deletions lib/Everyman/Neo4j/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Client
const CapabilityGremlin = 'gremlin';
const CapabilityLabel = 'label';
const CapabilityTransactions = 'transactions';
const CapabilitySpatialPlugin = 'spatial';

protected $transport = null;
protected $entityMapper = null;
Expand Down Expand Up @@ -504,6 +505,12 @@ public function hasCapability($capability)
return $info['extensions']['GremlinPlugin']['execute_script'];
}
return false;

case self::CapabilitySpatialPlugin:
if (isset($info['extensions']['SpatialPlugin'])) {
return true;
}
return false;

default:
return false;
Expand Down Expand Up @@ -726,6 +733,80 @@ public function searchIndex(Index $index, $key, $value)
return $this->runCommand($command);
}

/**
* Create a new simple point layer
*
* @param string $layer
* @param string $lon
* @param string $lat
* @return \Everyman\Neo4j\SpatialLayer\SimplePointLayer
*/
public function makeSimplePointLayer($layer, $lon = null, $lat = null)
{
$simplePointLayer = new SpatialLayer\SimplePointLayer($this, $layer, $lat, $lon);
return $simplePointLayer;
}

/**
* Save the given layer
*
* @param SpatialLayer $layer
* @return boolean
*/
public function saveLayer(SpatialLayer $layer)
{
return $this->runCommand(new Command\CreateSimplePointLayer($this, $layer));
}

/**
* Add an entity to a Layer
*
* @param SpatialLayer $layer
* @param PropertyContainer $entity
* @return boolean
*/
public function addToLayer(SpatialLayer $layer, PropertyContainer $entity)
{
// @todo implement batching support
return $this->runCommand(new Command\AddToLayer($this, $layer, $entity));
}

/**
* Search for nodes within a specified distance of X and Y
*
* @param \Everyman\Neo4j\SpatialLayer $layer
* @param float $pointX
* @param float $pointY
* @param float $distance
* @return array
*/
public function findNodesWithinDistance(SpatialLayer $layer, $pointX, $pointY, $distance)
{
return $this->runCommand(new Command\FindNodesWithinDistance($this, $layer, $pointX, $pointY, $distance));
}

/**
* Search for nodes within a specified bounding box area
*
* @param \Everyman\Neo4j\SpatialLayer $layer
* @param type $pointX
* @param type $pointY
* @param type $distance
* @return type
*/
public function findNodesInBBox(SpatialLayer $layer, $minX, $maxX, $minY, $maxY)
{
return $this->runCommand(new Command\FindNodesInBBox($this, $layer, $minX, $maxX, $minY, $maxY));
}









/**
* Set the cache to use
*
Expand Down
88 changes: 88 additions & 0 deletions lib/Everyman/Neo4j/Command/AddToLayer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
namespace Everyman\Neo4j\Command;

use Everyman\Neo4j\Command,
Everyman\Neo4j\Client,
Everyman\Neo4j\Exception,
Everyman\Neo4j\PropertyContainer,
Everyman\Neo4j\SpatialLayer;

/**
* Add an entity to an a spatial layer
*/
class AddToLayer extends Command
{
protected $layer = null;
protected $entity = null;
protected $key = null;
protected $value = null;

/**
* Set the layer to drive the command
*
* @param Client $client
* @param SpatialLayer $layer
* @param PropertyContainer $entity
* @param string $key
* @param string $value
*/
public function __construct(Client $client, SpatialLayer $layer, PropertyContainer $entity)
{
parent::__construct($client);
$this->layer = $layer;
$this->entity = $entity;
}

/**
* Return the data to pass
*
* @return mixed
*/
protected function getData()
{
if (!$this->entity || !$this->entity->hasId()) {
throw new Exception('No entity to add to layer specified');
}

return array(
'node' => $this->getTransport()->getEndpoint().'/'. 'node' .'/'.$this->entity->getId(),
'layer' => $this->layer->getName()
);
}

/**
* Return the transport method to call
*
* @return string
*/
protected function getMethod()
{
return 'post';
}

/**
* Return the path to use
*
* @return string
*/
protected function getPath()
{
return '/ext/SpatialPlugin/graphdb/addNodeToLayer';
}

/**
* Use the results
*
* @param integer $code
* @param array $headers
* @param array $data
* @return integer on failure
*/
protected function handleResult($code, $headers, $data)
{
if ((int)($code / 100) != 2) {
$this->throwException('Unable to add entity to spatial layer', $code, $headers, $data);
}
return true;
}
}
104 changes: 104 additions & 0 deletions lib/Everyman/Neo4j/Command/CreateSimplePointLayer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
namespace Everyman\Neo4j\Command;

use Everyman\Neo4j\Command,
Everyman\Neo4j\Client,
Everyman\Neo4j\SpatialLayer\SimplePointLayer;

/**
* Create a SimplePointLayer
*/
class CreateSimplePointLayer extends Command
{
protected $simplePointLayer = null;

/**
* Set the simplePointLayer to drive the command
*
* @param Client $client
* @param Node $node
*/
public function __construct(Client $client, SimplePointLayer $simplePointLayer)
{
parent::__construct($client);
$this->simplePointLayer = $simplePointLayer;
}

protected function getData()
{
return array(
'layer' => $this->getName(),
'lat' => $this->getLat(),
'lon' => $this->getLon(),
);
}

/**
* Return the name of the layer
*
* @return string
*/
protected function getName()
{
return $this->simplePointLayer->getName() ?: null;
}

/**
*
* @return string
*/
protected function getLat()
{
return $this->simplePointLayer->getLat() ?: null;
}

/**
*
* @return string
*/
protected function getLon()
{
return $this->simplePointLayer->getLon() ?: null;
}

/**
* Return the transport method to call
*
* @return string
*/
protected function getMethod()
{
return 'post';
}

/**
* Return the path to use
*
* @return string
*/
protected function getPath()
{
return '/ext/SpatialPlugin/graphdb/addSimplePointLayer';
}

/**
* Use the results
*
* @param integer $code
* @param array $headers
* @param array $data
* @return boolean true on success
* @throws Exception on failure
*/
protected function handleResult($code, $headers, $data)
{
if ((int)($code / 100) != 2) {
$this->throwException('Unable to create SimplePointLayer', $code, $headers, $data);
}

//$nodeId = $this->getEntityMapper()->getIdFromUri($headers['Location']);
//$this->node->setId($nodeId);
//$this->getEntityCache()->setCachedEntity($this->node);
return true;
}
}
Loading