PHP code example of hirevoice / neo4jphp-ogm

1. Go to this page and download the library: Download hirevoice/neo4jphp-ogm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hirevoice / neo4jphp-ogm example snippets



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 {
        $this->friends = new ArrayCollection;
    }

    /* Add your accessors here */
}

// 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

$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' => '[email protected]'));

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

$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
));