Skip to content

Instantly share code, notes, and snippets.

@cirpo
Created July 4, 2010 09:28
Show Gist options
  • Save cirpo/463297 to your computer and use it in GitHub Desktop.
Save cirpo/463297 to your computer and use it in GitHub Desktop.
<?php
require '../doctrine2/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
use Documents\User;
use Documents\Project;
use Documents\Manager;
use Doctrine\Common\ClassLoader,
Doctrine\Common\Annotations\AnnotationReader,
Doctrine\ODM\MongoDB\DocumentManager,
Doctrine\ODM\MongoDB\Mongo,
Doctrine\ODM\MongoDB\Configuration,
Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
// ODM Classes
$classLoader = new ClassLoader('Doctrine\ODM', '../mongodb-odm/lib');
$classLoader->register();
// Common Classes
$classLoader = new ClassLoader('Doctrine\Common', '../doctrine2/lib/vendor/doctrine-common/lib');
$classLoader->register();
// Document classes
$classLoader = new ClassLoader('Documents', '../mongodb-odm/tests');
$classLoader->register();
$config = new Configuration();
$config->setProxyDir(__DIR__ .'foo/here');
echo __DIR__ .'/pippo/here';
$config->setProxyNamespace('Proxies');
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
$dm = DocumentManager::create(new Mongo(), $config);
$user = new User();
$user->setUsername('jack');
$dm->persist($user);
$dm->flush();
$user = $dm->find('User', array('username' => 'jack '));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment