Browse files

Added basic usage instructions

  • Loading branch information...
1 parent 6951250 commit a9c8cf709b7392c45a94a68b8b8b4545042171cf @Seldaek Seldaek committed Dec 9, 2010
Showing with 46 additions and 0 deletions.
  1. +46 −0 README.markdown
View
46 README.markdown
@@ -18,3 +18,49 @@ Notes
-----
* The type of the document is stored in each node (stored as _doctrine_alias for the moment)
+
+Getting Started
+---------------
+
+ 1. 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'));
+
+ 2. Initialize a Jackalope session
+
+ $repository = new \Jackalope\Repository('http://localhost:8080/server');
+ $credentials = new \PHPCR\SimpleCredentials('user', 'pass');
+ $session = $repository->login($credentials, 'your_workspace');
+
+ 3. Initialize the DocumentManager
+
+ $config = new \Doctrine\ODM\PHPCR\Configuration();
+ $config->setMetadataDriverImpl($driver);
+ $config->setPhpcrSession($session);
+
+ $dm = new \Doctrine\ODM\PHPCR\DocumentManager($config);
+
+ 4. 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 = 'foo@example.com';
+ $dm->persist($newUser, '/timmy');
+
+ // store all changes, insertions, etc.
+ $dm->flush();

0 comments on commit a9c8cf7

Please sign in to comment.