Skip to content
26 changes: 13 additions & 13 deletions lib/Doctrine/ODM/PHPCR/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions lib/Doctrine/ODM/PHPCR/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ODM/PHPCR/Id/IdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ abstract class IdGenerator
static public function create($generatorType)
{
switch ($generatorType) {
case ClassMetadata::GENERATOR_TYPE_NONE:
$instance = new AssignedPathGenerator();
case ClassMetadata::GENERATOR_TYPE_ASSIGNED:
$instance = new AssignedIdGenerator();
break;
case ClassMetadata::GENERATOR_TYPE_REPOSITORY:
$instance = new RepositoryPathGenerator();
$instance = new RepositoryIdGenerator();
break;
default:
throw \Exception("ID Generator does not exist!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,15 +15,15 @@ class RepositoryPathGenerator extends IdGenerator
*/
public function generate($document, ClassMetadata $cm, DocumentManager $dm)
{
$repository = $dm->getRepository($cm->class);
if (!($repository instanceof RepositoryPathInterface)) {
throw new \Exception("no id");
$repository = $dm->getRepository($cm->name);
if (!($repository instanceof RepositoryIdInterface)) {
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->generatePath($document);
$id = $repository->generateId($document);
if (!$id) {
throw new \Exception("no id");
throw new \Exception("Repository did not generate an id");
}
return $id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Doctrine\ODM\PHPCR\Id;

interface RepositoryPathInterface
interface RepositoryIdInterface
{
/**
* Generate a document id
*
* @param object $document
* @return string
*/
function generatePath($document);
function generateId($document);
}
28 changes: 8 additions & 20 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -103,13 +103,6 @@ class ClassMetadataInfo implements ClassMetadata
*/
public $nodeType;

/**
* READ-ONLY: The field name of the path
*
* @var string
*/
public $path;

/**
* READ-ONLY: The field name of the node
*
Expand Down Expand Up @@ -440,7 +433,6 @@ public function mapField(array $mapping)
{
if (isset($mapping['id']) && $mapping['id'] === true) {
$mapping['type'] = 'string';
$this->mapPath($mapping);
$this->setIdentifier($mapping['fieldName']);
if (isset($mapping['strategy'])) {
$this->idGenerator = constant('Doctrine\ODM\PHPCR\Mapping\ClassMetadata::GENERATOR_TYPE_' . strtoupper($mapping['strategy']));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -662,7 +651,6 @@ public function __sleep()
$serialized = array(
'fieldMappings',
'identifier',
'path',
'node',
'nodeType',
'alias',
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/DoctrineAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ final class Document extends Annotation
public $repositoryClass;
public $isVersioned;
}
final class MappedSuperclass extends Annotation {}

final class Path extends Annotation
final class MappedSuperclass extends Annotation
{
}
final class Node extends Annotation
Expand All @@ -28,6 +26,11 @@ class Property extends Annotation
final class Id extends Property
{
public $id = true;
public $type = 'string';
public $strategy = 'assigned';
}
final class Uuid extends Property
{
public $name = 'jcr:uuid';
public $type = 'string';
}
Expand Down
15 changes: 5 additions & 10 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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);
Expand Down
Loading