function getConnection($cache = false) { static $first; $conf = new \ActiveMongo2\Configuration(__DIR__ . "/tmp/mapper.php"); $conf->addModelPath(__DIR__ . '/docs')->development(); if (!empty($_SERVER["NAMESPACE"])) { if (!$first) { print "Using namespace {$_SERVER['NAMESPACE']}\n"; } $conf->SetNamespace($_SERVER["NAMESPACE"]); } if (!$first) { $mongo = new MongoClient(); $mongo->selectDB('activemongo2_tests')->drop(); $mongo->selectDB('activemongo2_tests_foobar')->drop(); $config = new ActiveMongo2\Configuration(); unlink($config->getLoader()); } if (empty($_SERVER["NAMESPACE"])) { $zconn = new \ActiveMongo2\Client(new MongoClient(), 'activemongo2_tests', __DIR__ . '/docs'); } else { $zconn = new \ActiveMongo2\Connection($conf, new MongoClient(), 'activemongo2_tests'); } $zconn->AddConnection('foobar', new MongoClient(), 'activemongo2_tests_foobar', 'zzzz'); if ($cache) { $zconn->setCacheStorage(new \ActiveMongo2\Cache\Storage\Memory()); } $first = true; return $zconn; }
/** * @Cli("db:create_index", "Create indexes in activemongo2") * @Arg("docdir", REQUIRED, "Directory where activemongo2 classes are defined") * @Arg("db", REQUIRED, "Database name") */ function create_index($input, $output) { $args = $input->getArguments(); if (!is_dir($args['docdir'])) { throw new \RuntimeException("{$args['docdir']} is not not a directory"); } $conf = new \ActiveMongo2\Configuration(tempnam(sys_get_temp_dir(), "activemongo2")); $conf->addModelPath($args['docdir'])->development(); $mongo = new \MongoClient(); $zconn = new \ActiveMongo2\Connection($conf, $mongo, $args['db']); $zconn->ensureIndex(); $output->writeLn("creating were created"); }
<?php require __DIR__ . "/../vendor/autoload.php"; $conf = new \ActiveMongo2\Configuration(__DIR__ . "/tmp/foo.php"); $conf->addModelPath(__DIR__ . '/docs')->development(); $mongo = new MongoClient(); $zconn = new \ActiveMongo2\Connection($conf, $mongo, 'activemongo2_tests'); $zconn->worker();