- (very) basic CRUD is implemented
- metadata reading implemented for annotations
- there is a symfony2 bundle available in symfony core.
- fix the tests that fail
- figure out how we can do relations in a sane way
- The type of the document is stored in each repository node (stored as _doctrine_alias for the moment)
-
Define one of those mapping drivers
// Annotation driver $reader = new \Doctrine\Common\Annotations\AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\ODM\PHPCR\Mapping\\'); // This line defines the jcr namespace, so you can annotate with @jcr:Property for example instead of just @Property $reader->setAnnotationNamespaceAlias('Doctrine\ODM\PHPCR\Mapping\\', 'jcr'); $driver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver($reader, array('/path/to/your/document/classes')); // Xml driver $driver = new \Doctrine\ODM\PHPCR\Mapping\Driver\XmlDriver(array('/path/to/your/mapping/files')); // Yaml driver $driver = new \Doctrine\ODM\PHPCR\Mapping\Driver\YamlDriver(array('/path/to/your/mapping/files'));
-
Initialize a Jackalope session
$repository = new \Jackalope\Repository('http://localhost:8080/server'); $credentials = new \PHPCR\SimpleCredentials('user', 'pass'); $session = $repository->login($credentials, 'your_workspace');
-
Initialize the DocumentManager
$config = new \Doctrine\ODM\PHPCR\Configuration(); $config->setMetadataDriverImpl($driver); $config->setPhpcrSession($session); $dm = new \Doctrine\ODM\PHPCR\DocumentManager($config);
-
Example usage
// fetching a document by path $user = $dm->getRepository('Namespace\For\Document\User')->find('/bob'); // create a new document $newUser = new \Namespace\For\Document\User(); $newUser->username = 'Timmy'; $newUser->email = '[email protected]'; $dm->persist($newUser, '/timmy'); // store all changes, insertions, etc. $dm->flush();
You write your own document classes that will be mapped to and from the phpcr database by doctrine. The documents are usually simple
<?php
namespace Acme\SampleBundle\Document;
/**
* @phpcr:Document(alias="mydocument")
*/
class MyDocument
{
/**
* @phpcr:String()
*/
public $title;
/**
* @phpcr:String()
*/
public $content;
}
Available annotations are
@Path: | The phpcr path to this node. |
@Node: | The phpcr NodeInterface instance for direct access. |
@Id: | The unique id of this node. (only allowed if node is referenceable). |
@Version: | The version of this node, for versioned nodes. |
@Property: | Any property of the node, without specified type. |
@Boolean, @Int, @Long, @Float, @String, @Date, @Binary, @ArrayField: | Typed property |
TODO: References and child / embed annotations.