From 6d231dbe98a50a906b7e67d5544f23c4dc34ac0c Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Mon, 4 Apr 2011 10:37:21 +0200 Subject: [PATCH 1/7] renamed path to id --- lib/Doctrine/ODM/PHPCR/DocumentManager.php | 26 +++---- lib/Doctrine/ODM/PHPCR/DocumentRepository.php | 20 ++--- ...hGenerator.php => AssignedIdGenerator.php} | 4 +- lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php | 4 +- ...enerator.php => RepositoryIdGenerator.php} | 6 +- .../ODM/PHPCR/Id/RepositoryIdInterface.php | 12 +++ .../ODM/PHPCR/Mapping/ClassMetadataInfo.php | 24 ++---- .../PHPCR/Mapping/Driver/AnnotationDriver.php | 4 +- .../Mapping/Driver/DoctrineAnnotations.php | 6 +- .../ODM/PHPCR/Mapping/Driver/XmlDriver.php | 15 ++-- .../ODM/PHPCR/Mapping/Driver/YamlDriver.php | 15 ++-- ...lection.php => PersistentIdCollection.php} | 14 ++-- lib/Doctrine/ODM/PHPCR/UnitOfWork.php | 74 +++++++++---------- tests/Doctrine/Tests/Models/CMS/CmsUser.php | 4 +- .../ODM/PHPCR/Functional/BasicCrudTest.php | 29 ++++---- .../Functional/DocumentRepositoryTest.php | 8 +- .../ODM/PHPCR/Functional/EventManagerTest.php | 2 +- .../ODM/PHPCR/Functional/PropertyNameTest.php | 6 +- .../ODM/PHPCR/Functional/ReferenceTest.php | 2 +- .../ODM/PHPCR/Functional/VersioningTest.php | 6 +- .../Mapping/AbstractMappingDriverTest.php | 4 +- .../Tests/ODM/PHPCR/UnitOfWorkTest.php | 18 ++--- 22 files changed, 147 insertions(+), 156 deletions(-) rename lib/Doctrine/ODM/PHPCR/Id/{AssignedPathGenerator.php => AssignedIdGenerator.php} (80%) rename lib/Doctrine/ODM/PHPCR/Id/{RepositoryPathGenerator.php => RepositoryIdGenerator.php} (79%) create mode 100644 lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php rename lib/Doctrine/ODM/PHPCR/{PersistentPathCollection.php => PersistentIdCollection.php} (80%) diff --git a/lib/Doctrine/ODM/PHPCR/DocumentManager.php b/lib/Doctrine/ODM/PHPCR/DocumentManager.php index 8264bd158..72e90eaf6 100644 --- a/lib/Doctrine/ODM/PHPCR/DocumentManager.php +++ b/lib/Doctrine/ODM/PHPCR/DocumentManager.php @@ -128,24 +128,24 @@ public function getClassMetadata($class) * Will return null if the document wasn't found. * * @param string $documentName - * @param string $path + * @param string $id * @return object */ - public function find($documentName, $path) + public function find($documentName, $id) { - return $this->getRepository($documentName)->find($path); + return $this->getRepository($documentName)->find($id); } /** - * Finds many documents by path. + * Finds many documents by id. * * @param string $documentName - * @param array $paths + * @param array $ids * @return object */ - public function findMany($documentName, array $paths) + public function findMany($documentName, array $ids) { - return $this->getRepository($documentName)->findMany($paths); + return $this->getRepository($documentName)->findMany($ids); } /** @@ -188,22 +188,22 @@ public function refresh($document) } /** - * Gets a reference to the entity identified by the given type and path + * Gets a reference to the entity identified by the given type and id * without actually loading it, if the entity is not yet loaded. * * @param string $documentName The name of the entity type. - * @param mixed $path The entity path. + * @param string $id The entity id. * @return object The entity reference. */ - public function getReference($documentName, $path) + public function getReference($documentName, $id) { // Check identity map first, if its already in there just return it. - if ($document = $this->unitOfWork->tryGetByPath($path)) { + if ($document = $this->unitOfWork->tryGetById($id)) { return $document; } $class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\')); - $document = $this->proxyFactory->getProxy($class->name, $path); - $this->unitOfWork->registerManaged($document, $path, null); + $document = $this->proxyFactory->getProxy($class->name, $id); + $this->unitOfWork->registerManaged($document, $id, null); return $document; } diff --git a/lib/Doctrine/ODM/PHPCR/DocumentRepository.php b/lib/Doctrine/ODM/PHPCR/DocumentRepository.php index 1d1fd70dd..30cc130a0 100644 --- a/lib/Doctrine/ODM/PHPCR/DocumentRepository.php +++ b/lib/Doctrine/ODM/PHPCR/DocumentRepository.php @@ -79,17 +79,17 @@ public function createDocument($uow, $documentName, $node, array &$hints = array } /** - * Find a single document by its path + * Find a single document by its id * - * @param string $path document path + * @param string $id document id * @return object $document */ - public function find($path) + public function find($id) { $uow = $this->dm->getUnitOfWork(); try { - $node = $this->dm->getPhpcrSession()->getNode($path); + $node = $this->dm->getPhpcrSession()->getNode($id); } catch (\PHPCR\PathNotFoundException $e) { return null; } @@ -99,19 +99,19 @@ public function find($path) } /** - * Find many document by path + * Find many document by id * - * @param array $paths document paths + * @param array $ids document ids * @return array of document objects */ - public function findMany(array $paths) + public function findMany(array $ids) { $uow = $this->dm->getUnitOfWork(); $documents = array(); - foreach ($paths as $path) { + foreach ($ids as $id) { // TODO: catch exception and return null when not found? - $node = $this->dm->getPhpcrSession()->getNode($path); + $node = $this->dm->getPhpcrSession()->getNode($id); $hints = array(); $documents[] = $this->createDocument($uow, $this->documentName, $node, $hints); } @@ -176,7 +176,7 @@ public function refresh($document) // TODO: call session->refresh(true) before fetching the node once Jackalope implements it $uow = $this->dm->getUnitOfWork(); - $node = $this->dm->getPhpcrSession()->getNode($uow->getDocumentPath($document)); + $node = $this->dm->getPhpcrSession()->getNode($uow->getDocumentId($document)); $hints = array('refresh' => true); $this->createDocument($uow, $this->documentName, $node, $hints); diff --git a/lib/Doctrine/ODM/PHPCR/Id/AssignedPathGenerator.php b/lib/Doctrine/ODM/PHPCR/Id/AssignedIdGenerator.php similarity index 80% rename from lib/Doctrine/ODM/PHPCR/Id/AssignedPathGenerator.php rename to lib/Doctrine/ODM/PHPCR/Id/AssignedIdGenerator.php index fa7156dd3..b7d516e58 100644 --- a/lib/Doctrine/ODM/PHPCR/Id/AssignedPathGenerator.php +++ b/lib/Doctrine/ODM/PHPCR/Id/AssignedIdGenerator.php @@ -5,7 +5,7 @@ use Doctrine\ODM\PHPCR\DocumentManager; use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; -class AssignedPathGenerator extends IdGenerator +class AssignedIdGenerator extends IdGenerator { /** * @param object $document @@ -15,7 +15,7 @@ class AssignedPathGenerator extends IdGenerator */ public function generate($document, ClassMetadata $cm, DocumentManager $dm) { - $id = $cm->getFieldValue($document, $cm->path); + $id = $cm->getFieldValue($document, $cm->identifier); if (!$id) { throw new \Exception("no id"); } diff --git a/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php b/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php index 4120134fd..0dd128774 100644 --- a/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php +++ b/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php @@ -24,10 +24,10 @@ static public function create($generatorType) { switch ($generatorType) { case ClassMetadata::GENERATOR_TYPE_NONE: - $instance = new AssignedPathGenerator(); + $instance = new AssignedIdGenerator(); break; case ClassMetadata::GENERATOR_TYPE_REPOSITORY: - $instance = new RepositoryPathGenerator(); + $instance = new RepositoryIdGenerator(); break; default: throw \Exception("ID Generator does not exist!"); diff --git a/lib/Doctrine/ODM/PHPCR/Id/RepositoryPathGenerator.php b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php similarity index 79% rename from lib/Doctrine/ODM/PHPCR/Id/RepositoryPathGenerator.php rename to lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php index 990505527..82a469a6d 100644 --- a/lib/Doctrine/ODM/PHPCR/Id/RepositoryPathGenerator.php +++ b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php @@ -5,7 +5,7 @@ use Doctrine\ODM\PHPCR\DocumentManager; use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; -class RepositoryPathGenerator extends IdGenerator +class RepositoryIdGenerator extends IdGenerator { /** * @param object $document @@ -16,12 +16,12 @@ class RepositoryPathGenerator extends IdGenerator public function generate($document, ClassMetadata $cm, DocumentManager $dm) { $repository = $dm->getRepository($cm->class); - if (!($repository instanceof RepositoryPathInterface)) { + if (!($repository instanceof RepositoryIdInterface)) { throw new \Exception("no id"); } // TODO: should we have some default implementation (parent path + some md5/object id)? - $id = $repository->generatePath($document); + $id = $repository->generateId($document); if (!$id) { throw new \Exception("no id"); } diff --git a/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php new file mode 100644 index 000000000..7aae10c10 --- /dev/null +++ b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php @@ -0,0 +1,12 @@ +mapPath($mapping); $this->setIdentifier($mapping['fieldName']); if (isset($mapping['strategy'])) { $this->idGenerator = constant('Doctrine\ODM\PHPCR\Mapping\ClassMetadata::GENERATOR_TYPE_' . strtoupper($mapping['strategy'])); @@ -486,13 +478,6 @@ public function mapField(array $mapping) $this->fieldMappings[$mapping['fieldName']] = $mapping; } - public function mapPath(array $mapping) - { - $this->validateAndCompleteFieldMapping($mapping, false); - - $this->path = $mapping['fieldName']; - } - public function mapNode(array $mapping) { $this->validateAndCompleteFieldMapping($mapping, false); @@ -584,7 +569,7 @@ public function setIdentifierValue($document, $id) */ public function getIdentifierValue($document) { - return (string) $this->reflFields[$this->identifier]->getValue($document); + return (string) $this->getFieldValue($document, $this->identifier); } /** @@ -607,7 +592,11 @@ public function setFieldValue($document, $field, $value) */ public function getFieldValue($document, $field) { - return $this->reflFields[$field]->getValue($document); + if (isset($this->reflFields[$field])) { + return $this->reflFields[$field]->getValue($document); + } + + return null; } /** @@ -662,7 +651,6 @@ public function __sleep() $serialized = array( 'fieldMappings', 'identifier', - 'path', 'node', 'nodeType', 'alias', diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php index cfcfec0f8..42599d497 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php @@ -134,9 +134,9 @@ public function loadMetadataForClass($className, ClassMetadata $class) if ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Property) { $mapping = array_merge($mapping, (array) $fieldAnnot); $class->mapField($mapping); - } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Path) { + } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Id) { $mapping = array_merge($mapping, (array) $fieldAnnot); - $class->mapPath($mapping); + $class->mapField($mapping); } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Node) { $mapping = array_merge($mapping, (array) $fieldAnnot); $class->mapNode($mapping); diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php index 28c14942f..c45995d4e 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php @@ -13,8 +13,9 @@ final class Document extends Annotation } final class MappedSuperclass extends Annotation {} -final class Path extends Annotation +final class Id extends Annotation { + public $id = true; } final class Node extends Annotation { @@ -25,9 +26,8 @@ class Property extends Annotation public $type = 'undefined'; public $multivalue = false; } -final class Id extends Property +final class Uuid extends Property { - public $id = true; public $name = 'jcr:uuid'; public $type = 'string'; } diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php index 0c9110883..3ee2f54fc 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php @@ -78,12 +78,12 @@ public function loadMetadataForClass($className, ClassMetadata $class) $mapping[$key] = ('true' === $mapping[$key]) ? true : false; } } - $this->addPropertyMapping($class, $mapping); + $this->addFieldMapping($class, $mapping); } } - if (isset($xmlRoot->path)) { - $mapping = array('fieldName' => (string) $xmlRoot->path->attributes()->name); - $this->addPathMapping($class, $mapping); + if (isset($xmlRoot->id)) { + $mapping = array('fieldName' => (string) $xmlRoot->id->attributes()->name, 'id' => true); + $this->addFieldMapping($class, $mapping); } if (isset($xmlRoot->node)) { $mapping = array('fieldName' => (string) $xmlRoot->node->attributes()->name); @@ -108,16 +108,11 @@ public function loadMetadataForClass($className, ClassMetadata $class) } - private function addPropertyMapping(ClassMetadata $class, $mapping) + private function addFieldMapping(ClassMetadata $class, $mapping) { $class->mapField($mapping); } - private function addPathMapping(ClassMetadata $class, $mapping) - { - $class->mapPath($mapping); - } - private function addNodeMapping(ClassMetadata $class, $mapping) { $class->mapNode($mapping); diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php index abe8b9e0c..239795287 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php @@ -76,12 +76,12 @@ public function loadMetadataForClass($className, ClassMetadata $class) if (!isset($mapping['fieldName'])) { $mapping['fieldName'] = $fieldName; } - $this->addPropertyMapping($class, $mapping); + $this->addFieldMapping($class, $mapping); } } - if (isset($element['path'])) { - $mapping = array('fieldName' => $element['path']); - $this->addPathMapping($class, $mapping); + if (isset($element['id'])) { + $mapping = array('fieldName' => $element['id'], 'id' => true); + $this->addFieldMapping($class, $mapping); } if (isset($element['node'])) { $mapping = array('fieldName' => $element['node']); @@ -107,16 +107,11 @@ public function loadMetadataForClass($className, ClassMetadata $class) } - private function addPropertyMapping(ClassMetadata $class, $mapping) + private function addFieldMapping(ClassMetadata $class, $mapping) { $class->mapField($mapping); } - private function addPathMapping(ClassMetadata $class, $mapping) - { - $class->mapPath($mapping); - } - private function addNodeMapping(ClassMetadata $class, $mapping) { $class->mapNode($mapping); diff --git a/lib/Doctrine/ODM/PHPCR/PersistentPathCollection.php b/lib/Doctrine/ODM/PHPCR/PersistentIdCollection.php similarity index 80% rename from lib/Doctrine/ODM/PHPCR/PersistentPathCollection.php rename to lib/Doctrine/ODM/PHPCR/PersistentIdCollection.php index 7d9f4f4d7..6a6871b0b 100644 --- a/lib/Doctrine/ODM/PHPCR/PersistentPathCollection.php +++ b/lib/Doctrine/ODM/PHPCR/PersistentIdCollection.php @@ -13,20 +13,20 @@ * @author Jordi Boggiano * @author Pascal Helfenstein */ -class PersistentPathCollection extends PersistentCollection +class PersistentIdCollection extends PersistentCollection { private $documentName; private $dm; - private $paths; + private $ids; public $isInitialized = false; - public function __construct(Collection $collection, $documentName, DocumentManager $dm, $paths) + public function __construct(Collection $collection, $documentName, DocumentManager $dm, $ids) { $this->col = $collection; $this->documentName = $documentName; $this->dm = $dm; - $this->paths = $paths; - $this->isInitialized = (count($paths) == 0); + $this->ids = $ids; + $this->isInitialized = (count($ids) == 0); } protected function load() @@ -37,7 +37,7 @@ protected function load() $elements = $this->col->toArray(); $repository = $this->dm->getRepository($this->documentName); - $objects = $repository->findMany($this->paths); + $objects = $repository->findMany($this->ids); foreach ($objects as $object) { $this->col->add($object); } @@ -46,4 +46,4 @@ protected function load() } } } -} \ No newline at end of file +} diff --git a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php index c4cb31557..a19673ab6 100644 --- a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php +++ b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php @@ -57,7 +57,7 @@ class UnitOfWork /** * @var array */ - private $documentPaths = array(); + private $documentIds = array(); /** * @var array @@ -201,15 +201,15 @@ public function createDocument($documentName, $node, array &$hints = array()) // } } - if ($class->path) { - $documentState[$class->path] = $node->getPath(); - } if ($class->node) { $documentState[$class->node] = $node; } if ($class->versionField) { $documentState[$class->versionField] = $node->getProperty('jcr:baseVersion')->getNativeValue(); } + if ($class->identifier) { + $documentState[$class->identifier] = $node->getPath(); + } // initialize inverse side collections foreach ($class->associationsMappings as $assocName => $assocOptions) { @@ -239,7 +239,7 @@ public function createDocument($documentName, $node, array &$hints = array()) $oid = spl_object_hash($document); $this->documentState[$oid] = self::STATE_MANAGED; - $this->documentPaths[$oid] = $id; + $this->documentIds[$oid] = $id; $overrideLocalValues = true; } @@ -282,7 +282,7 @@ public function getOriginalData($document) * Schedule insertion of this document and cascade if neccessary. * * @param object $document - * @param string $path + * @param string $id */ public function scheduleInsert($document) { @@ -491,9 +491,9 @@ public function getDocumentChangeSet($document) */ public function persistNew($class, $document) { - $path = $this->getIdGenerator($class->idGenerator)->generate($document, $class, $this->dm); + $id = $this->getIdGenerator($class->idGenerator)->generate($document, $class, $this->dm); - $this->registerManaged($document, $path, null); + $this->registerManaged($document, $id, null); if (isset($class->lifecycleCallbacks[Event::prePersist])) { $class->invokeLifecycleCallbacks(Event::prePersist, $document); @@ -540,17 +540,17 @@ public function flush() $this->evm->dispatchEvent(Event::prePersist, new Events\LifecycleEventArgs($document, $this->dm)); $this->computeChangeSet($class, $document); // TODO: prevent association computations in this case? } - $path = $this->documentPaths[$oid]; - $parentNode = $session->getNode(dirname($path) === '\\' ? '/' : dirname($path)); - $node = $parentNode->addNode(basename($path), $class->nodeType); + $id = $this->documentIds[$oid]; + $parentNode = $session->getNode(dirname($id) === '\\' ? '/' : dirname($id)); + $node = $parentNode->addNode(basename($id), $class->nodeType); if ($class->isVersioned) { $node->addMixin("mix:versionable"); } $this->nodesMap[$oid] = $node; - if ($class->path) { - $class->reflFields[$class->path]->setValue($document, $path); + if ($class->identifier) { + $class->reflFields[$class->identifier]->setValue($document, $id); } if ($class->node) { $class->reflFields[$class->node]->setValue($document, $node); @@ -601,7 +601,7 @@ public function flush() } else if (isset($class->associationsMappings[$fieldName]) && $useDoctrineMetadata) { if ($class->associationsMappings[$fieldName]['type'] & ClassMetadata::TO_ONE) { if (\is_object($fieldValue)) { - $data['doctrine_metadata']['associations'][$fieldName] = $this->getDocumentPath($fieldValue); + $data['doctrine_metadata']['associations'][$fieldName] = $this->getDocumentId($fieldValue); } else { $data['doctrine_metadata']['associations'][$fieldName] = null; } @@ -611,7 +611,7 @@ public function flush() $ids = array(); if (is_array($fieldValue) || $fieldValue instanceof \Doctrine\Common\Collections\Collection) { foreach ($fieldValue as $relatedObject) { - $ids[] = $this->getDocumentPath($relatedObject); + $ids[] = $this->getDocumentId($relatedObject); } } @@ -686,13 +686,13 @@ protected function handlePostFlushEvents() } /** - * Checkin operation - Save all current changes and then check in the Node by path. + * Checkin operation - Save all current changes and then check in the Node by id. * * @return void */ public function checkIn($object) { - $path = $this->documentPaths[spl_object_hash($object)]; + $path = $this->documentIds[spl_object_hash($object)]; $this->flush(); $session = $this->dm->getPhpcrSession(); $node = $session->getNode($path); @@ -708,7 +708,7 @@ public function checkIn($object) */ public function checkOut($object) { - $path = $this->documentPaths[spl_object_hash($object)]; + $path = $this->documentIds[spl_object_hash($object)]; $this->flush(); $session = $this->dm->getPhpcrSession(); $node = $session->getNode($path); @@ -724,7 +724,7 @@ public function checkOut($object) */ public function restore($version, $object, $removeExisting) { - $path = $this->documentPaths[spl_object_hash($object)]; + $path = $this->documentIds[spl_object_hash($object)]; $this->flush(); $session = $this->dm->getPhpcrSession(); $vm = $session->getWorkspace()->getVersionManager(); @@ -739,7 +739,7 @@ public function restore($version, $object, $removeExisting) */ public function getPredecessors($document) { - $path = $this->documentPaths[spl_object_hash($document)]; + $path = $this->documentIds[spl_object_hash($document)]; $session = $this->dm->getPhpcrSession(); $node = $session->getNode($path, 'Version\Version'); return $node->getPredecessors(); @@ -758,9 +758,9 @@ public function removeFromIdentityMap($document) { $oid = spl_object_hash($document); - if (isset($this->identityMap[$this->documentPaths[$oid]])) { - unset($this->identityMap[$this->documentPaths[$oid]], - $this->documentPaths[$oid], + if (isset($this->identityMap[$this->documentIds[$oid]])) { + unset($this->identityMap[$this->documentIds[$oid]], + $this->documentIds[$oid], $this->documentRevisions[$oid], $this->documentState[$oid]); @@ -776,31 +776,31 @@ public function removeFromIdentityMap($document) */ public function contains($document) { - return isset($this->documentPaths[spl_object_hash($document)]); + return isset($this->documentIds[spl_object_hash($document)]); } - public function registerManaged($document, $path, $revision) + public function registerManaged($document, $id, $revision) { $oid = spl_object_hash($document); $this->documentState[$oid] = self::STATE_MANAGED; - $this->documentPaths[$oid] = $path; + $this->documentIds[$oid] = $id; $this->documentRevisions[$oid] = $revision; - $this->identityMap[$path] = $document; + $this->identityMap[$id] = $document; } /** - * Tries to find an entity with the given path in the identity map of + * Tries to find an entity with the given id in the identity map of * this UnitOfWork. * - * @param mixed $path The entity path to look for. + * @param mixed $id The entity id to look for. * @param string $rootClassName The name of the root class of the mapped entity hierarchy. - * @return mixed Returns the entity with the specified path if it exists in + * @return mixed Returns the entity with the specified id if it exists in * this UnitOfWork, FALSE otherwise. */ - public function tryGetByPath($path) + public function tryGetById($id) { - if (isset($this->identityMap[$path])) { - return $this->identityMap[$path]; + if (isset($this->identityMap[$id])) { + return $this->identityMap[$id]; } return false; } @@ -821,13 +821,13 @@ public function getDocumentRevision($document) return null; } - public function getDocumentPath($document) + public function getDocumentId($document) { $oid = spl_object_hash($document); - if (isset($this->documentPaths[$oid])) { - return $this->documentPaths[$oid]; + if (isset($this->documentIds[$oid])) { + return $this->documentIds[$oid]; } else { - throw new PHPCRException("Document is not managed and has no path."); + throw new PHPCRException("Document is not managed and has no id."); } } } diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index 824309eee..420e01599 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -11,8 +11,8 @@ class CmsUser { // /** @Id */ // public $id; - /** @Path */ - public $path; + /** @Id */ + public $id; /** @Node */ public $node; /** @String(name="status") */ diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php index 56f1430bb..408eb29db 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php @@ -34,7 +34,8 @@ public function testFind() $user = $this->dm->find($this->type, '/functional/user'); $this->assertInstanceOf($this->type, $user); - $this->assertEquals('/functional/user', $user->path); + $this->assertEquals('/functional/user', $user->id); + $this->assertEquals('lsmith', $user->username); $this->assertEquals(array(3, 1, 2), $user->numbers->toArray()); } @@ -44,7 +45,7 @@ public function testInsert() $user = new User(); $user->username = "test"; $user->numbers = array(1, 2, 3); - $user->path = '/functional/test'; + $user->id = '/functional/test'; $this->dm->persist($user); $this->dm->flush(); @@ -61,7 +62,7 @@ public function testMultivaluePropertyWithOnlyOneValueUpdatedToMultiValue() { $user = new User(); $user->numbers = array(1); - $user->path = '/functional/test'; + $user->id = '/functional/test'; $this->dm->persist($user); $this->dm->flush(); @@ -110,7 +111,7 @@ public function testUpdate1() $user = new User(); $user->username = "test"; $user->numbers = array(1, 2, 3); - $user->path = '/functional/user2'; + $user->id = '/functional/user2'; $this->dm->persist($user); $this->dm->flush(); @@ -119,7 +120,7 @@ public function testUpdate1() $userNew = $this->dm->find($this->type, '/functional/user2'); $userNew->username = "test2"; $userNew->numbers = array(4, 5, 6); - $userNew->path = '/functional/user2'; + $userNew->id = '/functional/user2'; $this->dm->persist($userNew); $this->dm->flush(); @@ -152,11 +153,11 @@ public function testInsertUpdateMultiple() $user2 = new User(); $user2->username = "test2"; - $user2->path = '/functional/user2222'; + $user2->id = '/functional/user2222'; $user3 = new User(); $user3->username = "test3"; - $user3->path = '/functional/user3333'; + $user3->id = '/functional/user3333'; $this->dm->persist($user2); $this->dm->persist($user3); @@ -167,11 +168,11 @@ public function testInsertUpdateMultiple() $pUser2 = $this->dm->find($this->type, '/functional/user2222'); $pUser3 = $this->dm->find($this->type, '/functional/user3333'); - $this->assertEquals('/functional/user', $pUser1->path); + $this->assertEquals('/functional/user', $pUser1->id); $this->assertEquals('new-name', $pUser1->username); - $this->assertEquals('/functional/user2222', $pUser2->path); + $this->assertEquals('/functional/user2222', $pUser2->id); $this->assertEquals('test2', $pUser2->username); - $this->assertEquals('/functional/user3333', $pUser3->path); + $this->assertEquals('/functional/user3333', $pUser3->id); $this->assertEquals('test3', $pUser3->username); } @@ -244,8 +245,8 @@ public function testKeepTrackOfUnmappedData() */ class User { - /** @Path */ - public $path; + /** @Id */ + public $id; /** @Node */ public $node; /** @String(name="username") */ @@ -259,8 +260,8 @@ class User */ class User2 { - /** @Path */ - public $path; + /** @Id */ + public $id; /** @String(name="username") */ public $username; } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/DocumentRepositoryTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/DocumentRepositoryTest.php index 4c35f4a41..44ac9af1d 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/DocumentRepositoryTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/DocumentRepositoryTest.php @@ -28,26 +28,26 @@ public function testLoadMany() $user1->username = "beberlei"; $user1->status = "active"; $user1->name = "Benjamin"; - $user1->path = '/functional/user1'; + $user1->id = '/functional/user1'; $user2 = new \Doctrine\Tests\Models\CMS\CmsUser(); $user2->username = "lsmith"; $user2->status = "active"; $user2->name = "Lukas"; - $user2->path = '/functional/user2'; + $user2->id = '/functional/user2'; $this->dm = $this->createDocumentManager(); $this->dm->persist($user1); $this->dm->persist($user2); $this->dm->flush(); - $users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->path, $user2->path)); + $users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id)); $this->assertSame($user1, $users[0]); $this->assertSame($user2, $users[1]); $this->dm->clear(); - $users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->path, $user2->path)); + $users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id)); $this->assertEquals($user1->username, $users[0]->username); $this->assertEquals($user2->username, $users[1]->username); } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php index f696cbeb7..69c8e2618 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php @@ -23,7 +23,7 @@ public function testTriggerEvents() $user->name = "beberlei"; $user->username = "beberlei"; $user->status = "active"; - $user->path = '/functional/userx'; + $user->id = '/functional/userx'; $this->dm->persist($user); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/PropertyNameTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/PropertyNameTest.php index 5a40242a8..28487660d 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/PropertyNameTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/PropertyNameTest.php @@ -26,7 +26,7 @@ public function setUp() public function testPropertyname() { $doc = new TestObj(); - $doc->path = '/functional/pn'; + $doc->id = '/functional/pn'; $doc->name = 'Testname'; $doc->othername = 'Testothername'; @@ -51,8 +51,8 @@ public function testPropertyname() */ class TestObj { - /** @Path */ - public $path; + /** @Id */ + public $id; /** @Node */ public $node; /** @String */ diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferenceTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferenceTest.php index 1004aed59..0e41721fd 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferenceTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferenceTest.php @@ -48,7 +48,7 @@ public function testLazyLoadReference() $user->username = "beberlei"; $user->name = "Benjamin"; $user->status = "active"; - $user->path = '/functional/benjamin'; + $user->id = '/functional/benjamin'; $dm = $this->createDocumentManager(); $dm->persist($user); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/VersioningTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/VersioningTest.php index e9e137c90..31b6d15f3 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/VersioningTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/VersioningTest.php @@ -66,8 +66,8 @@ public function testRestore() */ class VersionTestObj { - /** @Path */ - public $path; + /** @Id */ + public $id; /** @Node */ public $node; /** @@ -79,4 +79,4 @@ class VersionTestObj public $username; /** @Int(name="numbers", multivalue=true) */ public $numbers; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/AbstractMappingDriverTest.php index a5b682365..58cd6eded 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/AbstractMappingDriverTest.php @@ -29,8 +29,8 @@ public function testLoadMapping() */ public function testFieldMappings($class) { - $this->assertEquals(3, count($class->fieldMappings)); -// $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertEquals(4, count($class->fieldMappings)); + $this->assertTrue(isset($class->fieldMappings['id'])); $this->assertTrue(isset($class->fieldMappings['name'])); $this->assertTrue(isset($class->fieldMappings['username'])); $this->assertTrue(isset($class->fieldMappings['status'])); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/UnitOfWorkTest.php b/tests/Doctrine/Tests/ODM/PHPCR/UnitOfWorkTest.php index af8c84203..6fbd43fc8 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/UnitOfWorkTest.php @@ -25,7 +25,7 @@ public function setUp() $this->uow = new UnitOfWork($this->dm); $metadata = new ClassMetadata($this->type); - $metadata->mapField(array('fieldName' => 'path', 'id' => true)); + $metadata->mapField(array('fieldName' => 'id', 'id' => true)); $metadata->mapField(array('fieldName' => 'username', 'type' => 'string')); $cmf = $this->dm->getMetadataFactory(); @@ -36,7 +36,7 @@ public function setUp() $this->objectManager = $this->getMock('Jackalope\ObjectManager', array(), array($this->factory), '', false); } - protected function createNode($path, $username) + protected function createNode($id, $username) { $nodeData = array( 'jcr:primaryType' => "Name", @@ -45,7 +45,7 @@ protected function createNode($path, $username) 'username' => $username, ); - return new Node($this->factory, $nodeData, $path, $this->session, $this->objectManager); + return new Node($this->factory, $nodeData, $id, $this->session, $this->objectManager); } public function testCreateDocument() @@ -55,9 +55,9 @@ public function testCreateDocument() $this->assertInstanceOf($this->type, $user); $this->assertEquals('foo', $user->username); $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->uow->getDocumentState($user)); - $this->assertEquals('/somepath', $this->uow->getDocumentPath($user)); + $this->assertEquals('/somepath', $this->uow->getDocumentId($user)); - $this->assertEquals(array('path' => '/somepath', 'username' => 'foo'), $this->uow->getOriginalData($user)); + $this->assertEquals(array('id' => '/somepath', 'username' => 'foo'), $this->uow->getOriginalData($user)); } public function testCreateDocument_UseIdentityMap() @@ -72,7 +72,7 @@ public function testTryGetById() { $user1 = $this->uow->createDocument($this->type, $this->createNode('/somepath', 'foo')); - $user2 = $this->uow->tryGetByPath('/somepath', $this->type); + $user2 = $this->uow->tryGetById('/somepath', $this->type); $this->assertSame($user1, $user2); } @@ -85,7 +85,7 @@ public function testScheduleInsertion() { $object = new UoWUser(); $object->username = "bar"; - $object->path = '/somepath'; + $object->id = '/somepath'; $this->uow->scheduleInsert($object); } @@ -99,7 +99,7 @@ public function testScheduleInsertCancelsScheduleRemove() { $object = new UoWUser(); $object->username = "bar"; - $object->path = '/somepath'; + $object->id = '/somepath'; $this->uow->scheduleRemove($object); @@ -113,6 +113,6 @@ public function testScheduleInsertCancelsScheduleRemove() class UoWUser { - public $path; + public $id; public $username; } From 730fd034b53baa2d382fffc4b11e69d66d06ae32 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 5 Apr 2011 01:19:49 +0200 Subject: [PATCH 2/7] renamed id generator "none" to "assigned" --- lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php | 2 +- lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php b/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php index 0dd128774..7e60df1e2 100644 --- a/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php +++ b/lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php @@ -23,7 +23,7 @@ abstract class IdGenerator static public function create($generatorType) { switch ($generatorType) { - case ClassMetadata::GENERATOR_TYPE_NONE: + case ClassMetadata::GENERATOR_TYPE_ASSIGNED: $instance = new AssignedIdGenerator(); break; case ClassMetadata::GENERATOR_TYPE_REPOSITORY: diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php index a5e6de007..629a009e7 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php @@ -62,14 +62,14 @@ class ClassMetadataInfo implements ClassMetadata * NONE means Doctrine will not generate any id for us and you are responsible for manually * assigning an id. */ - const GENERATOR_TYPE_NONE = 2; + const GENERATOR_TYPE_ASSIGNED = 2; /** * READ-ONLY: The ID generator used for generating IDs for this class. * * @var AbstractIdGenerator */ - public $idGenerator = self::GENERATOR_TYPE_NONE; + public $idGenerator = self::GENERATOR_TYPE_ASSIGNED; /** * READ-ONLY: The field name of the document identifier. From 849b126422f1210efdc9d76169c3d7714549f9e7 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 5 Apr 2011 01:20:51 +0200 Subject: [PATCH 3/7] tweaked annotations for id and uuid --- .../ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php index c45995d4e..b76228ce1 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php @@ -11,11 +11,8 @@ final class Document extends Annotation public $repositoryClass; public $isVersioned; } -final class MappedSuperclass extends Annotation {} - -final class Id extends Annotation +final class MappedSuperclass extends Annotation { - public $id = true; } final class Node extends Annotation { @@ -26,6 +23,12 @@ class Property extends Annotation public $type = 'undefined'; public $multivalue = false; } +final class Id extends Property +{ + public $id = true; + public $type = 'string'; + public $strategy = 'assigned'; +} final class Uuid extends Property { public $name = 'jcr:uuid'; From 974399e3f1ac5a18876dcb77b98627052701761c Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 5 Apr 2011 01:21:03 +0200 Subject: [PATCH 4/7] added test for strategy mapping --- .../Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataTest.php index 96d30b802..0a32e486a 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataTest.php @@ -21,7 +21,7 @@ public function testClassName() */ public function testMapFieldWithId($cm) { - $cm->mapField(array('fieldName' => 'id', 'id' => true)); + $cm->mapField(array('fieldName' => 'id', 'id' => true, 'strategy' => 'repository')); $this->assertTrue(isset($cm->fieldMappings['id'])); $this->assertEquals( @@ -32,12 +32,14 @@ public function testMapFieldWithId($cm) 'isInverseSide' => null, 'isOwningSide' => true, 'fieldName' => 'id', - 'multivalue' => false + 'multivalue' => false, + 'strategy' => 'repository', ) , $cm->fieldMappings['id'] ); $this->assertEquals('id', $cm->identifier); + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_REPOSITORY, $cm->idGenerator); return $cm; } From 708df8823264e2d6b49d838bb2ced64c4dd08e3e Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 12 Apr 2011 10:57:30 +0200 Subject: [PATCH 5/7] fixed RepositoryIdGenerator --- lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php | 6 +++--- lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php index 82a469a6d..4115c0f67 100644 --- a/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php +++ b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdGenerator.php @@ -15,15 +15,15 @@ class RepositoryIdGenerator extends IdGenerator */ public function generate($document, ClassMetadata $cm, DocumentManager $dm) { - $repository = $dm->getRepository($cm->class); + $repository = $dm->getRepository($cm->name); if (!($repository instanceof RepositoryIdInterface)) { - throw new \Exception("no id"); + throw new \Exception("Repository does not implement RepositoryIdInterface, could not generate id"); } // TODO: should we have some default implementation (parent path + some md5/object id)? $id = $repository->generateId($document); if (!$id) { - throw new \Exception("no id"); + throw new \Exception("Repository did not generate an id"); } return $id; } diff --git a/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php index 7aae10c10..37320c409 100644 --- a/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php +++ b/lib/Doctrine/ODM/PHPCR/Id/RepositoryIdInterface.php @@ -5,6 +5,8 @@ interface RepositoryIdInterface { /** + * Generate a document id + * * @param object $document * @return string */ From 1fbbb7d99672cb327d3342b66587474c4295c983 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 12 Apr 2011 13:30:17 +0200 Subject: [PATCH 6/7] removed no longer used interface --- .../ODM/PHPCR/Id/RepositoryPathInterface.php | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 lib/Doctrine/ODM/PHPCR/Id/RepositoryPathInterface.php diff --git a/lib/Doctrine/ODM/PHPCR/Id/RepositoryPathInterface.php b/lib/Doctrine/ODM/PHPCR/Id/RepositoryPathInterface.php deleted file mode 100644 index 10a376baf..000000000 --- a/lib/Doctrine/ODM/PHPCR/Id/RepositoryPathInterface.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Tue, 12 Apr 2011 15:11:44 +0200 Subject: [PATCH 7/7] added functional test for the repository id generator --- .../ODM/PHPCR/Functional/BasicCrudTest.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php index 408eb29db..5ba06cbe1 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ODM\PHPCR\Functional; +use Doctrine\ODM\PHPCR\Id\RepositoryIdInterface, + Doctrine\ODM\PHPCR\DocumentRepository; + /** * @group functional */ @@ -58,6 +61,21 @@ public function testInsert() $this->assertEquals($user->numbers->toArray(), $userNew->numbers->toArray()); } + public function testInsertWithCustomIdStrategy() + { + $user = new User3(); + $user->username = "test3"; + + $this->dm->persist($user); + $this->dm->flush(); + $this->dm->clear(); + + $userNew = $this->dm->find('Doctrine\Tests\ODM\PHPCR\Functional\User3', '/functional/test3'); + + $this->assertNotNull($userNew, "Have to hydrate user object!"); + $this->assertEquals($user->username, $userNew->username); + } + public function testMultivaluePropertyWithOnlyOneValueUpdatedToMultiValue() { $user = new User(); @@ -265,3 +283,28 @@ class User2 /** @String(name="username") */ public $username; } + +/** + * @Document(repositoryClass="Doctrine\Tests\ODM\PHPCR\Functional\User3Repository", alias="user3") + */ +class User3 +{ + /** @Id(strategy="repository") */ + public $id; + /** @String(name="username") */ + public $username; +} + +class User3Repository extends DocumentRepository implements RepositoryIdInterface +{ + /** + * Generate a document id + * + * @param object $document + * @return string + */ + public function generateId($document) + { + return 'functional/'.$document->username; + } +}