Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 210cb0a

Browse files
author
Valentinas Bartusevičius
committed
XML metadata factories
1 parent 9a84804 commit 210cb0a

30 files changed

+1122
-54
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"autoload": {
3232
"psr-4": {
3333
"GraphAware\\Neo4j\\OGM\\": "src/"
34-
}
34+
},
35+
"files": ["src/Mapping/Neo4jOGMAnnotations.php"]
3536
},
3637
"autoload-dev": {
3738
"psr-4": {

graphaware-mapping.xsd

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<xs:schema attributeFormDefault="unqualified"
3+
elementFormDefault="qualified"
4+
targetNamespace="http://graphaware.com/schemas/ogm/graphaware-mapping"
5+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
6+
xmlns:ogm="http://graphaware.com/schemas/ogm/graphaware-mapping">
7+
<xs:element name="graphaware-mapping" type="ogm:graphaware-mappingType"/>
8+
<xs:complexType name="idType">
9+
<xs:simpleContent>
10+
<xs:extension base="xs:string">
11+
<xs:attribute type="xs:string" name="name" use="required"/>
12+
</xs:extension>
13+
</xs:simpleContent>
14+
</xs:complexType>
15+
<xs:complexType name="propertyType" mixed="true">
16+
<xs:sequence>
17+
<xs:element type="ogm:labelType" name="label" minOccurs="0"/>
18+
</xs:sequence>
19+
<xs:attribute type="xs:string" name="name" use="required"/>
20+
<xs:attribute type="ogm:property-type-types" name="type" use="required"/>
21+
<xs:attribute type="xs:boolean" name="nullable" use="optional" default="true"/>
22+
</xs:complexType>
23+
<xs:simpleType name="property-type-types">
24+
<xs:restriction base="xs:token">
25+
<xs:enumeration value="string"/>
26+
<xs:enumeration value="boolean"/>
27+
<xs:enumeration value="array"/>
28+
<xs:enumeration value="int"/>
29+
<xs:enumeration value="float"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
<xs:complexType name="relationshipType" mixed="true">
33+
<xs:sequence>
34+
<xs:element type="xs:string" name="lazy" minOccurs="0"/>
35+
<xs:element type="ogm:order-byType" name="order-by" minOccurs="0"/>
36+
</xs:sequence>
37+
<xs:attribute type="xs:string" name="name" use="required"/>
38+
<xs:attribute type="xs:string" name="type" use="required"/>
39+
<xs:attribute type="ogm:relationship-directions" name="direction" use="required"/>
40+
<xs:attribute type="xs:string" name="target-entity" use="required"/>
41+
<xs:attribute type="xs:string" name="collection" use="optional"/>
42+
<xs:attribute type="xs:string" name="mapped-by" use="optional"/>
43+
</xs:complexType>
44+
<xs:simpleType name="relationship-directions">
45+
<xs:restriction base="xs:token">
46+
<xs:enumeration value="OUTGOING"/>
47+
<xs:enumeration value="INCOMING"/>
48+
<xs:enumeration value="BOTH"/>
49+
</xs:restriction>
50+
</xs:simpleType>
51+
<xs:complexType name="relationshipEntityType" mixed="true">
52+
<xs:sequence>
53+
<xs:element type="ogm:idType" name="id" minOccurs="1" maxOccurs="1"/>
54+
<xs:element type="ogm:start-nodeType" name="start-node" minOccurs="1" maxOccurs="1"/>
55+
<xs:element type="ogm:end-nodeType" name="end-node" minOccurs="1" maxOccurs="1"/>
56+
<xs:element type="ogm:propertyType" name="property" minOccurs="0"/>
57+
</xs:sequence>
58+
<xs:attribute type="xs:string" name="type" use="required"/>
59+
<xs:attribute type="xs:string" name="entity" use="required"/>
60+
<xs:attribute type="ogm:relationship-entity-directions" name="direction" use="optional"/>
61+
</xs:complexType>
62+
<xs:simpleType name="relationship-entity-directions">
63+
<xs:restriction base="xs:token">
64+
<xs:enumeration value="OUTGOING"/>
65+
<xs:enumeration value="INCOMING"/>
66+
</xs:restriction>
67+
</xs:simpleType>
68+
<xs:complexType name="nodeEntityType">
69+
<xs:sequence>
70+
<xs:element type="ogm:idType" name="id" minOccurs="1" maxOccurs="1"/>
71+
<xs:element type="ogm:propertyType" name="property" maxOccurs="unbounded" minOccurs="0"/>
72+
<xs:element type="ogm:relationshipType" name="relationship" minOccurs="0" maxOccurs="unbounded"/>
73+
</xs:sequence>
74+
<xs:attribute type="xs:string" name="label" use="required"/>
75+
<xs:attribute type="xs:string" name="entity" use="required"/>
76+
<xs:attribute type="xs:string" name="repository-class" use="optional"/>
77+
</xs:complexType>
78+
<xs:complexType name="labelType">
79+
<xs:simpleContent>
80+
<xs:extension base="xs:string">
81+
<xs:attribute type="xs:string" name="name" use="required"/>
82+
</xs:extension>
83+
</xs:simpleContent>
84+
</xs:complexType>
85+
<xs:complexType name="order-byType">
86+
<xs:simpleContent>
87+
<xs:extension base="xs:string">
88+
<xs:attribute type="xs:string" name="property" use="required"/>
89+
<xs:attribute type="ogm:order-by-direction" name="order" use="required"/>
90+
</xs:extension>
91+
</xs:simpleContent>
92+
</xs:complexType>
93+
<xs:simpleType name="order-by-direction">
94+
<xs:restriction base="xs:token">
95+
<xs:enumeration value="ASC"/>
96+
<xs:enumeration value="DESC"/>
97+
</xs:restriction>
98+
</xs:simpleType>
99+
<xs:complexType name="start-nodeType">
100+
<xs:simpleContent>
101+
<xs:extension base="xs:string">
102+
<xs:attribute type="xs:string" name="name" use="required"/>
103+
<xs:attribute type="xs:string" name="target-entity" use="required"/>
104+
</xs:extension>
105+
</xs:simpleContent>
106+
</xs:complexType>
107+
<xs:complexType name="end-nodeType">
108+
<xs:simpleContent>
109+
<xs:extension base="xs:string">
110+
<xs:attribute type="xs:string" name="name" use="required"/>
111+
<xs:attribute type="xs:string" name="target-entity" use="required"/>
112+
</xs:extension>
113+
</xs:simpleContent>
114+
</xs:complexType>
115+
<xs:complexType name="graphaware-mappingType">
116+
<xs:sequence>
117+
<xs:choice>
118+
<xs:element type="ogm:nodeEntityType" name="node" maxOccurs="unbounded" minOccurs="0"/>
119+
<xs:element type="ogm:relationshipEntityType" name="relationship" maxOccurs="unbounded" minOccurs="0"/>
120+
</xs:choice>
121+
</xs:sequence>
122+
</xs:complexType>
123+
</xs:schema>

src/Annotations/Property.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class Property
3030
*/
3131
public $key;
3232

33-
/*
33+
/**
3434
* @var bool
3535
*/
3636
public $nullable;

src/EntityManager.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
namespace GraphAware\Neo4j\OGM;
1313

14+
use Doctrine\Common\Annotations\AnnotationReader;
15+
use Doctrine\Common\Annotations\FileCacheReader;
1416
use Doctrine\Common\EventManager;
1517
use Doctrine\Common\Persistence\ObjectManager;
1618
use GraphAware\Neo4j\Client\ClientBuilder;
1719
use GraphAware\Neo4j\Client\ClientInterface;
1820
use GraphAware\Neo4j\OGM\Exception\MappingException;
19-
use GraphAware\Neo4j\OGM\Mapping\AnnotationDriver;
20-
use GraphAware\Neo4j\OGM\Metadata\Factory\GraphEntityMetadataFactory;
21+
use GraphAware\Neo4j\OGM\Metadata\Factory\Annotation\AnnotationGraphEntityMetadataFactory;
22+
use GraphAware\Neo4j\OGM\Metadata\Factory\GraphEntityMetadataFactoryInterface;
2123
use GraphAware\Neo4j\OGM\Metadata\GraphEntityMetadata;
2224
use GraphAware\Neo4j\OGM\Metadata\QueryResultMapper;
2325
use GraphAware\Neo4j\OGM\Metadata\RelationshipEntityMetadata;
@@ -27,23 +29,20 @@
2729
class EntityManager implements ObjectManager
2830
{
2931
/**
30-
* @var \GraphAware\Neo4j\OGM\UnitOfWork
32+
* @var UnitOfWork
3133
*/
3234
protected $uow;
3335

3436
/**
35-
* @var \GraphAware\Neo4j\Client\ClientInterface
37+
* @var ClientInterface
3638
*/
3739
protected $databaseDriver;
3840

3941
/**
40-
* @var \GraphAware\Neo4j\OGM\Repository\BaseRepository[]
42+
* @var BaseRepository[]
4143
*/
4244
protected $repositories = [];
4345

44-
/** @var \GraphAware\Neo4j\OGM\Mapping\AnnotationDriver */
45-
protected $annotationDriver;
46-
4746
/**
4847
* @var QueryResultMapper[]
4948
*/
@@ -55,7 +54,7 @@ class EntityManager implements ObjectManager
5554
protected $loadedMetadata = [];
5655

5756
/**
58-
* @var \GraphAware\Neo4j\OGM\Metadata\Factory\GraphEntityMetadataFactory
57+
* @var AnnotationGraphEntityMetadataFactory
5958
*/
6059
protected $metadataFactory;
6160

@@ -95,13 +94,21 @@ public static function buildWithHost($host)
9594
return new self($client);
9695
}
9796

98-
public function __construct(ClientInterface $databaseDriver, $cacheDirectory = null, EventManager $eventManager = null)
99-
{
100-
$this->annotationDriver = new AnnotationDriver($cacheDirectory);
97+
public function __construct(
98+
ClientInterface $databaseDriver,
99+
$cacheDirectory = null,
100+
EventManager $eventManager = null,
101+
GraphEntityMetadataFactoryInterface $metadataFactory = null
102+
) {
101103
$this->eventManager = $eventManager ?: new EventManager();
102104
$this->uow = new UnitOfWork($this);
103105
$this->databaseDriver = $databaseDriver;
104-
$this->metadataFactory = new GraphEntityMetadataFactory($this->annotationDriver->getReader());
106+
107+
if ($metadataFactory === null) {
108+
$reader = new FileCacheReader(new AnnotationReader(), $cacheDirectory, $debug = true);
109+
$metadataFactory = new AnnotationGraphEntityMetadataFactory($reader);
110+
}
111+
$this->metadataFactory = $metadataFactory;
105112
}
106113

107114
/**
@@ -184,14 +191,6 @@ public function getEventManager()
184191
return $this->eventManager;
185192
}
186193

187-
/**
188-
* @return \GraphAware\Neo4j\OGM\Mapping\AnnotationDriver
189-
*/
190-
public function getAnnotationDriver()
191-
{
192-
return $this->annotationDriver;
193-
}
194-
195194
public function persist($entity)
196195
{
197196
if (!is_object($entity)) {
@@ -207,15 +206,15 @@ public function flush()
207206
}
208207

209208
/**
210-
* @return \GraphAware\Neo4j\OGM\UnitOfWork
209+
* @return UnitOfWork
211210
*/
212211
public function getUnitOfWork()
213212
{
214213
return $this->uow;
215214
}
216215

217216
/**
218-
* @return \GraphAware\Neo4j\Client\Client
217+
* @return \GraphAware\Neo4j\Client\ClientInterface
219218
*/
220219
public function getDatabaseDriver()
221220
{
@@ -225,7 +224,7 @@ public function getDatabaseDriver()
225224
public function getResultMappingMetadata($class)
226225
{
227226
if (!array_key_exists($class, $this->resultMappers)) {
228-
$this->resultMappers[$class] = $this->annotationDriver->readQueryResult($class);
227+
$this->resultMappers[$class] = $this->metadataFactory->createQueryResultMapper($class);
229228
foreach ($this->resultMappers[$class]->getFields() as $field) {
230229
if ($field->isEntity()) {
231230
$targetFQDN = ClassUtils::getFullClassName($field->getTarget(), $class);
@@ -275,7 +274,7 @@ public function getRelationshipEntityMetadata($class)
275274
/**
276275
* @param string $class
277276
*
278-
* @return \GraphAware\Neo4j\OGM\Repository\BaseRepository
277+
* @return BaseRepository
279278
*/
280279
public function getRepository($class)
281280
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4j\OGM\Exception;
4+
5+
class MetadataFactoryException extends \Exception
6+
{
7+
}

src/Metadata/EntityPropertyMetadata.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public function setValue($object, $value)
7373
$this->reflectionProperty->setValue($object, $value);
7474
}
7575

76+
/**
77+
* @return PropertyAnnotationMetadata
78+
*/
79+
public function getPropertyAnnotationMetadata()
80+
{
81+
return $this->propertyAnnotationMetadata;
82+
}
83+
7684
/**
7785
* @param object $object
7886
*

0 commit comments

Comments
 (0)