/**
     * Creates a new Document that operates on the given Mongo connection
     * and uses the given Configuration.
     *
     * @param Doctrine\MongoDB\Connection $conn
     * @param Doctrine\ODM\MongoDB\Configuration $config
     * @param Doctrine\Common\EventManager $eventManager
     */
    protected function __construct(Connection $conn = null, Configuration $config = null, EventManager $eventManager = null)
    {
        $this->config = $config ?: new Configuration();
        $this->eventManager = $eventManager ?: new EventManager();
        $this->cmd = $this->config->getMongoCmd();
        $this->connection = $conn ?: new Connection(null, array(), $this->config, $this->eventManager);

        $metadataFactoryClassName = $this->config->getClassMetadataFactoryName();
        $this->metadataFactory = new $metadataFactoryClassName();
        $this->metadataFactory->setDocumentManager($this);
        $this->metadataFactory->setConfiguration($this->config);
        if ($cacheDriver = $this->config->getMetadataCacheImpl()) {
            $this->metadataFactory->setCacheDriver($cacheDriver);
        }

        $hydratorDir = $this->config->getHydratorDir();
        $hydratorNs = $this->config->getHydratorNamespace();
        $this->hydratorFactory = new HydratorFactory(
          $this,
          $this->eventManager,
          $hydratorDir,
          $hydratorNs,
          $this->config->getAutoGenerateHydratorClasses(),
          $this->config->getMongoCmd()
        );

        $this->unitOfWork = new UnitOfWork($this, $this->eventManager, $this->hydratorFactory, $this->cmd);
        $this->hydratorFactory->setUnitOfWork($this->unitOfWork);
        $this->schemaManager = new SchemaManager($this, $this->metadataFactory);
        $this->proxyFactory = new ProxyFactory($this,
                $this->config->getProxyDir(),
                $this->config->getProxyNamespace(),
                $this->config->getAutoGenerateProxyClasses()
        );
    }
 /**
  * Creates a new Document that operates on the given Mongo connection
  * and uses the given Configuration.
  *
  * @param Doctrine\ODM\MongoDB\Mongo $mongo
  * @param Doctrine\ODM\MongoDB\Configuration $config
  * @param Doctrine\Common\EventManager $eventManager
  */
 protected function __construct(Mongo $mongo, Configuration $config = null, EventManager $eventManager = null)
 {
     $this->_mongo = $mongo;
     $this->_config = $config ? $config : new Configuration();
     $this->_eventManager = $eventManager ? $eventManager : new EventManager();
     $this->_hydrator = new Hydrator($this);
     $this->_metadataFactory = new ClassMetadataFactory($this);
     if ($cacheDriver = $this->_config->getMetadataCacheImpl()) {
         $this->_metadataFactory->setCacheDriver($cacheDriver);
     }
     $this->_unitOfWork = new UnitOfWork($this);
     $this->_proxyFactory = new ProxyFactory($this, $config->getProxyDir(), $config->getProxyNamespace(), $config->getAutoGenerateProxyClasses());
 }
 /**
  * Creates a new Document that operates on the given Mongo connection
  * and uses the given Configuration.
  *
  * @param Doctrine\ODM\MongoDB\Mongo $mongo
  * @param Doctrine\ODM\MongoDB\Configuration $config
  * @param Doctrine\Common\EventManager $eventManager
  */
 protected function __construct(Mongo $mongo = null, Configuration $config = null, EventManager $eventManager = null)
 {
     if (is_string($mongo) || $mongo instanceof \Mongo) {
         $mongo = new Mongo($mongo);
     }
     $this->mongo = $mongo ? $mongo : new Mongo();
     $this->config = $config ? $config : new Configuration();
     $this->eventManager = $eventManager ? $eventManager : new EventManager();
     $this->hydrator = new Hydrator($this);
     $this->metadataFactory = new ClassMetadataFactory($this);
     if ($cacheDriver = $this->config->getMetadataCacheImpl()) {
         $this->metadataFactory->setCacheDriver($cacheDriver);
     }
     $this->queryParser = new Parser($this);
     $this->unitOfWork = new UnitOfWork($this);
     $this->proxyFactory = new ProxyFactory($this, $this->config->getProxyDir(), $this->config->getProxyNamespace(), $this->config->getAutoGenerateProxyClasses());
 }