1. Go to this page and download the library: Download innmind/neo4j-onm 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/ */
innmind / neo4j-onm example snippets
use Innmind\Neo4j\ONM\{
Metadata\Aggregate,
Metadata\Aggregate\Child,
Metadata\Relationship,
Metadata\ClassName,
Metadata\Identity,
Metadata\RelationshipType,
Metadata\RelationshipEdge,
Type,
Type\StringType,
Type\DateType,
Identity\Uuid,
};
use Innmind\Immutable\{
Map,
Set,
};
$image = Aggregate::of(
new ClassName('Image'),
new Identity('uuid', Uuid::class),
Set::of('string', 'Image'), # labels
Map::of('string', Type::class)
('url', new StringType),
Set::of(
Child::class,
Child::of(
new ClassName('Description'),
Set::of('string', 'Description'), # labels
Child\Relationship::of(
new ClassName('DescriptionOf'),
new RelationshipType('DESCRIPTION_OF'),
'rel',
'description',
Map::of('string', Type::class)
('created', new DateType)
),
Map::of('string', Type::class)
('content', new StringType)
)
)
);
$relationship = Relationship::of(
new ClassName('SomeRelationship'),
new Identity('uuid', Uuid::class),
new RelationshipType('SOME_RELATIONSHIP'),
new RelationshipEdge('startProperty', Uuid::class, 'uuid'),
new RelationshipEdge('endProperty', Uuid::class, 'uuid'),
Map::of('string', Type::class)
('created', new DateType)
);
use function Innmind\Neo4j\ONM\bootstrap;
use Innmind\Neo4j\DBAL\Connection;
use Innmind\Immutable\Set;
$services = bootstrap(
/* instance of Connection */,
Set::of(Entity::class, $image, $relationship)
);
$manager = $services['manager'];
$images = $manager->repository(Image::class);
$rels = $manager->repository(SomeRelationship::class);
$image1 = new Image($manager->identities()->new(Uuid::class));
$image2 = new Image($manager->identities()->new(Uuid::class));
$rel = new SomeRelationship(
$manager->identities()->new(Uuid::class),
$image1->uuid(),
$image2->uuid()
);
$rels->add($rel);
$images
->add($image1)
->add($image2);
$manager->flush();
$images->remove($image1);
$manager->flush(); //throw an exception at the database level