public
Created

  • Download Gist
test.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
<?php
 
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
 
 
$vendorDir = __DIR__.'/lib/vendor';
 
require_once $vendorDir.'/jackalope/lib/phpcr-utils/lib/vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php';
$classLoader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
$classLoader->register();
 
$classLoader->registerNamespaces(array(
'Doctrine\ODM' => dirname($vendorDir),
'Doctrine\Common' => $vendorDir.'/doctrine-common/lib',
'Symfony' => array($vendorDir, $vendorDir.'/jackalope/lib/phpcr-utils/lib/vendor'),
'PHPCR' => array($vendorDir.'/jackalope/lib/phpcr/src', $vendorDir.'/jackalope/lib/phpcr-utils/src'),
));
 
 
$classLoader->registerNamespaces(array(
'Jackalope'=> $vendorDir.'/jackalope/src',
));
 
 
 
$extraCommands[] = new \Jackalope\Tools\Console\Command\JackrabbitCommand();
 
$params = array(
'jackalope.jackrabbit_uri' => 'http://localhost:8081/server/',
);
 
$workspace = 'default';
$user = 'admin';
$pass = 'admin';
 
/* bootstrapping the repository implementation. for jackalope, do this: */
$repository = \Jackalope\RepositoryFactoryJackrabbit::getRepository($params);
$credentials = new \PHPCR\SimpleCredentials($user, $pass);
$session = $repository->login($credentials, $workspace);
 
 
/* prepare the doctrine configuration */
$config = new \Doctrine\ODM\PHPCR\Configuration();
 
 
 
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$driver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver($reader, array('/opt/git/phpr-odm/'));
 
require("./lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php");
 
$config->setMetadataDriverImpl($driver);
 
$config->setProxyDir('/tmp');
$config->setProxyNamespace('PHPCRProxies');
$config->setAutoGenerateProxyClasses(true);
 
$dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session, $config);
 
 
$newUser = $dm->find('MyDocument','/timmy2');
 
if (!$newUser) {
$newUser = new MyDocument();
$newUser->title = 'Timmy';
$newUser->content = 'foo@example.com';
$newUser->path = '/timmy2';
$newArticle = new Article();
$newArticle->path = "/article6";
$newArticle->title = 'Article 1';
$newUser->addArticle($newArticle);
$newArticle = new Article();
$newArticle->path = "/article8";
$newArticle->title = 'Article 2';
$newUser->addArticle($newArticle);
$dm->persist($newUser);
$dm->flush();
}
 
 
 
/**
* @PHPCRODM\Document
*/
class MyDocument
{
/**
* @PHPCRODM\Id()
*/
public $path;
/**
* @PHPCRODM\String()
*/
public $title;
 
/**
* @PHPCRODM\String()
*/
public $content;
/**
* articles
* @var array
* @PHPCRODM\ReferenceMany(targetDocument="Article")
*/
private $articles;
public function addArticle(Article $article)
{
$this->articles[] = $article;
}
}
 
/**
* @PHPCRODM\Document( referenceable=true)
*/
class Article
{
/**
* @PHPCRODM\Id()
*/
public $path;
/**
* @PHPCRODM\String()
*/
public $title;
 
/**
* @PHPCRODM\String()
*/
public $content;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.