neoxygen / neo4j-neoclient

Simple PHP HttpClient for the Neo4j ReST API with Multi DB Support
MIT License
121 stars 138 forks source link

2.0 #14

Closed ikwattro closed 9 years ago

ikwattro commented 9 years ago

This branch contains improvements from the 1.7 branch + the proof of concept for the 2.0 version :

Thoughts about the 2.0 branch :

Bootstrapping changes

The first call will not be done against the Client class, but against the ServiceContainer class that will process configuration and returns a Client object. This fixes problem accessing the methods in the Client when the library is used from a framework and using the service container.

New extension management

The extensions now extends AbstractExtension , having access to the invoke mehtod.

This brings 10x more flexibilty and user/developer friendlyness.

Also, The doc MUST be more clear to explain that commands are target to be calls to the api endpoint. Normally you should not write so much commands.

Before

For using a command from a custom extension the following was needed :

$command = $client->invoke('my_custom_command');
$command->setArguments($param1, $param2);
$command->execute();

Also, you could not write custom methods in your extension class that will be accessible through your application.

After

Your extension have automatically access to the invoke method of the commandManager, also you can write custom methods that will be available through your application, thanks to the __call magic method.

// In your Custom Extension class
public function doWhateverIWant()
{
    $this->invoke('my_super_command');
    return $command->execute();
}
// from your application
$client->doWhateverIWant();

I started to move the core methods present in the Client class to the NeoClientCoreExtension class and all my tests are still passing.

This gives really good future for new extensions with useful methods like spatial.

NB: The getAvailableCommands static function of your extension class still remains, this gives the possibility to other extensions to access the commands.

NB2: Extensions are registered in reversed order, this means you can override core commands with your specific commands.

Response handling

The client will expose automatically a Response handling system, no need to format the response yourself and the possibility to handle row parts of the api will be implemented.

Matrix

An adjacency matrix will be implemented in the Result class, in order to avoid current recursive arrays.

Ping @Mulkave

ikwattro commented 9 years ago

@Mulkave New listIndexes method, also listIndex does not return the label as key anymore :

$client->listIndexes();

Returns array of all indexes as ['labelName' => ['prop1','prop2']]

You can also pass an array of desired labels you want list the indexes of :

$client->listIndexes(['label1','label2']);
ikwattro commented 9 years ago

New bootstrap calls :

use Neoxygen\NeoClient\ClientBuilder;

$client = ClientBuilder::create()
    ->addConnection('default','http','localhost',7474)
    ->build();

$indexes = $client->listIndexes()
                   ->getResponse();

print_r($indexes);