create() public static method

public static create ( string $host, string | null $cacheDir = null, Doctrine\Common\EventManager $eventManager = null ) : EntityManager
$host string
$cacheDir string | null
$eventManager Doctrine\Common\EventManager
return EntityManager
示例#1
0
<?php

require_once __DIR__ . '/../../../vendor/autoload.php';
use GraphAware\Neo4j\OGM\EntityManager;
use Movies\Movie;
use Movies\Person;
use Movies\User;
// Entity manager setup
$em = EntityManager::create('http://localhost:7676');
playMovies($em->getDatabaseDriver());
// Retrieving a node
$personRepository = $em->getRepository(Person::class);
$tomHanks = $personRepository->findOneBy('name', 'Tom Hanks');
// Updating an entity
$actor = new Person('Kevin Ross', 1976);
$em->persist($actor);
$em->flush();
// Managing after load
$tomHanks->setBorn(1990);
$em->flush();
// Clearing
$em->clear();
// Relationships retrieval
$tomHanks = $em->getRepository(Person::class)->findOneBy('name', 'Tom Hanks');
echo sprintf('Tom Hanks played in %d movies', count($tomHanks->getMovies())) . PHP_EOL;
/** @var Movie $movie */
foreach ($tomHanks->getMovies() as $movie) {
    echo $movie->getTitle() . PHP_EOL;
    echo count($movie->getActors()) . PHP_EOL;
}
$em->clear();
 private function createEntityManager()
 {
     $this->em = EntityManager::create(sprintf('%s://%s:%s@%s:%s', getenv('NEO4J_SCHEMA'), getenv('NEO4J_USER'), getenv('NEO4J_PASSWORD'), getenv('NEO4J_HOST'), getenv('NEO4J_PORT')), __DIR__ . '/../../_var/cache');
 }