2017 © Pedro Peláez
 

library neo4jphp-ogm

Doctrine2-style entity mapper for Neo4j graph database

image

hirevoice/neo4jphp-ogm

Doctrine2-style entity mapper for Neo4j graph database

  • Wednesday, April 27, 2016
  • by lphuberdeau
  • Repository
  • 17 Watchers
  • 160 Stars
  • 17,942 Installations
  • PHP
  • 10 Dependents
  • 0 Suggesters
  • 51 Forks
  • 31 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

About

The Neo4j PHP Object Graph Mapper is an object management layer built on top of everyman/neo4jphp. It allows manipulation of data inside the Neo4j graph database through the REST connectors., (*2)

The library is also based on Doctrine\Common and borrows significantly from the excellent Doctrine\ORM design., (*3)

Released under the MIT Licence., (*4)

Created by Louis-Philippe Huberdeau for HireVoice Inc., the library was extracted from the project's codebase into its own Open Source project. Feel free to use, comment and participate., (*5)

Basic Usage

In order to store and retrieve information using the library, you must declare your entities. If you have used Doctrine2 before, this is a very similar process., (*6)

<?php
namespace Entity;

use HireVoice\Neo4j\Annotation as OGM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * All entity classes must be declared as such.
 *
 * @OGM\Entity
 */
class User
{
    /**
     * The internal node ID from Neo4j must be stored. Thus an Auto field is required
     * @OGM\Auto
     */
    protected $id;

    /**
     * @OGM\Property
     * @OGM\Index
     */
    protected $fullName;

    /**
     * @OGM\ManyToMany
     */
    protected $follows;

    /**
     * @OGM\ManyToOne
     */
    protected $referrer;

    function __construct()
    {
        $this->friends = new ArrayCollection;
    }

    /* Add your accessors here */
}

Storing entities into the graph database

// Let's assume the entity manager is initialized. More on this later.
$em = $this->get('hirevoice.neo4j.entity_manager');
$repo = $em->getRepository('Entity\\User');

// The repository uses magic functions to search in indexed fields
$john = $repo->findOneByFullName('John Doe');

$jane = new User;
$jane->setFullName('Jane Doe');

$jane->addFollow($john);

$em->persist($jane);
$em->flush(); // Stores both Jane and John, along with the new relation

$em->remove($john);
$em->flush(); // Removes John and the relation to Jane

Fetching entities from the database

$em = $this->get('hirevoice.neo4j.entity_manager');
$repository = $em->getRepository('Entity\\User');

// Find a User by a specific field
$user = $repository->findOneByFullName('superman'); // Returns a User object

// Find some users by a specific field
$usersFromFrance = $repository->findByCountry('FR'); // Returns a collection of User object

// Find one User with more than one criteria
$nonActiveWithSuchEmail = $repository->findOneBy(array('status' => 'idle', 'email' => 'superman@chucknorris.com'));

// Find Multiple Users with more than one criteria
$activeUsersFromFrance = $repository->findBy(array('status' => 'active', 'country' => 'FR'));

Initialize the EntityManager

Ideally, this would be done through DependencyInjection in your application. Here is the procedural creation., (*7)

$em = new HireVoice\Neo4j\EntityManager(array(
    // 'transport' => 'curl', // or 'stream'
    // 'host' => 'localhost',
    // 'port' => 7474,
    // 'username' => null,
    // 'password' => null,
    // 'proxy_dir' => '/tmp',
    // 'debug' => true, // Force proxy regeneration on each request
    // 'annotation_reader' => ... // Should be a cached instance of the doctrine annotation reader in production
));

Full Documentation

To get the full documentation, see the doc directory, (*8)

The Versions

27/04 2016

dev-master

9999999-dev https://github.com/lphuberdeau/Neo4j-PHP-OGM

Doctrine2-style entity mapper for Neo4j graph database

  Sources   Download

MIT

The Requires

 

The Development Requires

database doctrine graph neo4j entity-mapper

04/03 2016

dev-disable-auth

dev-disable-auth https://github.com/lphuberdeau/Neo4j-PHP-OGM

Doctrine2-style entity mapper for Neo4j graph database

  Sources   Download

MIT

The Requires

 

The Development Requires

database doctrine graph neo4j entity-mapper

01/05 2014

v0.6.0

0.6.0.0 https://github.com/lphuberdeau/Neo4j-PHP-OGM

Doctrine2-style entity mapper for Neo4j graph database

  Sources   Download

MIT

The Requires

 

The Development Requires

database doctrine graph neo4j entity-mapper

30/04 2014

v0.5.0

0.5.0.0 https://github.com/lphuberdeau/Neo4j-PHP-OGM

Doctrine2-style entity mapper for Neo4j graph database

  Sources   Download

MIT

The Requires

 

database doctrine graph neo4j entity-mapper

24/04 2013

dev-true-relation

dev-true-relation https://github.com/lphuberdeau/Neo4j-PHP-OGM

Doctrine2-style entity mapper for Neo4j graph database

  Sources   Download

MIT

The Requires

 

database doctrine graph neo4j entity-mapper