Doctrine\ODM\MongoDB\DocumentManager::create PHP Method

create() public static method

Creates a new Document that operates on the given Mongo connection and uses the given Configuration.
public static create ( Connection $conn = null, Configuration $config = null, Doctrine\Common\EventManager $eventManager = null ) : DocumentManager
$conn Doctrine\MongoDB\Connection
$config Configuration
$eventManager Doctrine\Common\EventManager
return DocumentManager
    public static function create(Connection $conn = null, Configuration $config = null, EventManager $eventManager = null)
    {
        return new static($conn, $config, $eventManager);
    }

Usage Example

 public function setUp()
 {
     $config = new Configuration();
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('Proxies');
     $reader = new AnnotationReader();
     $reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
     $this->dm = DocumentManager::create(new Mongo(), $config);
     $currencies = array('USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125);
     foreach ($currencies as $name => &$multiplier) {
         $multiplier = new Currency($name, $multiplier);
         $this->dm->persist($multiplier);
     }
     $product = new ConfigurableProduct('T-Shirt');
     $product->addOption(new Option('small', new Money(12.99, $currencies['USD']), new StockItem('T-shirt Size S', new Money(9.99, $currencies['USD']), 15)));
     $product->addOption(new Option('medium', new Money(14.99, $currencies['USD']), new StockItem('T-shirt Size M', new Money(11.99, $currencies['USD']), 15)));
     $product->addOption(new Option('large', new Money(17.99, $currencies['USD']), new StockItem('T-shirt Size L', new Money(13.99, $currencies['USD']), 15)));
     $this->dm->persist($product);
     $this->dm->flush();
     foreach ($currencies as $currency) {
         $this->dm->detach($currency);
     }
     $this->dm->detach($product);
     unset($currencies, $product);
 }
All Usage Examples Of Doctrine\ODM\MongoDB\DocumentManager::create