Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Forked from vaurat/gist:6070898
Last active December 20, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/6078317 to your computer and use it in GitHub Desktop.
Save Ocramius/6078317 to your computer and use it in GitHub Desktop.
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ODM\MongoDB\DocumentManager;
/* @var $loader \Composer\Autoload\ClassLoader */
$loader = require __DIR__.'/vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
AnnotationDriver::registerAnnotationClasses();
require_once __DIR__ . '/Parent.php';
require_once __DIR__ . '/Son.php';
require_once __DIR__ . '/Daughter.php';
$driver = new AnnotationDriver(new AnnotationReader(), array(__DIR__));
// @todo instantiate $connection
// @todo instantiate $configuration (with provided metadata driver)
$dm = DocumentManager::create($connection, $configuration);
var_dump($dm->getMetadataFactory()->getAllMetadata());
{
"require": {
"doctrine/mongodb-odm": "1.0.0-BETA9@BETA"
}
}
<?php
namespace my\Bundle\Document\Childs;
use my\Bundle\Document\Parent as Parent;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document
*/
class Daughter extends Parent
{
// ...
}
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: class_parents(): Class my\Bundle\Document\Childs\Parent
does not exist and could not be loaded in /var/www/cogitosum/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 40
<?php
namespace my\GCBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document (collection="Individual")
* @ODM\InheritanceType("SINGLE_COLLECTION")
* @ODM\DiscriminatorField(fieldName="discr")
* @ODM\DiscriminatorMap({
* "Son" = "my\Bundle\Document\Childs\Son",
* "Daughter" = "my\Bundle\Document\Childs\Daughter"
* })
*/
abstract class Parent
{
// ...
}
#/bin/sh
curl -s https://getcomposer.org/installer | php
php composer.phar install
php Bootstrap.php
<?php
namespace my\Bundle\Document\Childs;
use my\Bundle\Document\Parent as Parent;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document
*/
class Son extends Parent
{
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment