本文整理汇总了PHP中MongoDBRef类的典型用法代码示例。如果您正苦于以下问题:PHP MongoDBRef类的具体用法?PHP MongoDBRef怎么用?PHP MongoDBRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MongoDBRef类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: testCreate
public function testCreate()
{
$collection = "d";
$id = 123;
$db = "phpunit_temp";
$ref = MongoDBRef::create($collection, $id);
$this->assertEquals("d", $ref['$ref'], json_encode($ref));
$this->assertEquals(123, $ref['$id'], json_encode($ref));
$this->assertArrayNotHasKey('$db', $ref, json_encode($ref));
$ref = MongoDBRef::create($collection, $id, $db);
$this->assertEquals("d", $ref['$ref'], json_encode($ref));
$this->assertEquals(123, $ref['$id'], json_encode($ref));
$this->assertEquals("phpunit_temp", $ref['$db'], json_encode($ref));
// test converting to strings
$ref = MongoDBRef::create(1, 2, 3);
$this->assertEquals("1", $ref['$ref'], json_encode($ref));
$this->assertEquals(2, $ref['$id'], json_encode($ref));
$this->assertEquals("3", $ref['$db'], json_encode($ref));
// more for tracking this behavior than condoning it...
$one = 1;
$two = 2;
$three = 3;
$ref = MongoDBRef::create(1, 2, 3);
$this->assertEquals("1", $one);
$this->assertEquals(2, $two);
$this->assertEquals("3", $three);
}
开发者ID:petewarden,项目名称:mongo-php-driver,代码行数:27,代码来源:MongoDBRefTest.php
示例2: InsertCollection
public function InsertCollection($obj, $id)
{
//Insert obj values into Collection
if (!is_null($obj) || !is_null($this->Collect)) {
$this->Collect->remove();
}
if (!is_null($id)) {
$obj['_id'] = $id;
}
echo $obj["Thing"];
$Recipe = $obj["Recipe"];
$RecipeCollection = $this->dbObj->selectCollection("RecipeTest");
$RecipeCollection->Insert($Recipe);
//echo $Recipe['_id'].'\n';
$RecipeRef = MongoDBRef::create($RecipeCollection->getName(), $Recipe['_id']);
$CreativeWork = $obj["CreativeWork"];
$CreativeWork["RecipeReference"] = $RecipeRef;
$CreativeWorkCollection = $this->dbObj->selectCollection("CreativeWorkTest");
$CreativeWorkCollection->Insert($CreativeWork);
//echo $CreativeWork['_id'];
$CreativeWrokRef = MongoDBRef::create($CreativeWorkCollection->getName(), $CreativeWork['_id']);
$thing = $obj["Thing"];
$thing["CreativeWorkRef"] = $CreativeWrokRef;
$thingCollection = $this->dbObj->selectCollection("Thingtest");
$thingCollection->Insert($thing);
//Back ref
$recipeback = $this->dbObj->RecipeTest;
$RecipeResult = $recipeback->findOne(array("ingredients" => "suth"));
echo 'Result' . $RecipeResult['_id'];
print_r($RecipeResult);
$CWback = $this->dbObj->CreativeWorkTest;
//$CWbackResult = MongoDBRef::get($CWback->db, $RecipeResult['_id']);
$CWbackResult = $CWback->findOne(array("about" => "test1"));
print_r($CWbackResult);
}
开发者ID:nmp36,项目名称:FinalRecipeProject,代码行数:35,代码来源:DBLayer.php
示例3: testShouldReturnLazyLoadingCursor
public function testShouldReturnLazyLoadingCursor()
{
$parentCategory = new Category();
$parentCategory->setName('Parent category');
$parentCategory->setDesc('Parent category');
$parentCategory->save();
for ($i = 0; $i < 10; $i++) {
$category = new Category();
$category->setName('Category ' . $i);
$category->setDesc('Category ' . $i . ' desc');
$category->setCategory($parentCategory);
$category->save();
}
Category::enableLazyLoading();
$categories = Category::find([['category' => ['$ne' => null]]]);
$this->assertInstanceOf('\\Vegas\\Odm\\Collection\\LazyLoadingCursor', $categories);
foreach ($categories as $category) {
$this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category);
$this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category->getCategory());
}
$categories = Category::find([['category' => ['$ne' => null]]]);
$this->assertInstanceOf('\\Vegas\\Odm\\Collection\\LazyLoadingCursor', $categories);
foreach ($categories as $category) {
$this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category);
$reflectionClass = new \ReflectionClass(get_class($category));
$categoryProperty = $reflectionClass->getProperty('category');
$categoryProperty->setAccessible(true);
$this->assertTrue(\MongoDBRef::isRef($categoryProperty->getValue($category)));
}
}
开发者ID:vegas-cmf,项目名称:odm,代码行数:30,代码来源:LazyLoadingCursorTest.php
示例4: isRef
/**
* Returns true if the value passed appears to be a Mongo database reference
*
* @param mixed $obj
* @return boolean
**/
static function isRef($value)
{
if (!is_array($value)) {
return false;
}
return MongoDBRef::isRef($value);
}
开发者ID:kulobone,项目名称:mongodb,代码行数:13,代码来源:Db.php
示例5: update
/**
* method to convert plans names into their refs
* triggered before save the rate entity for edit
*
* @param Mongodloid collection $collection
* @param array $data
*
* @return void
* @todo move to model
*/
public function update($data)
{
if (isset($data['rates'])) {
$plansColl = Billrun_Factory::db()->plansCollection();
$currentDate = new MongoDate();
$rates = $data['rates'];
//convert plans
foreach ($rates as &$rate) {
if (isset($rate['plans'])) {
$sourcePlans = (array) $rate['plans'];
// this is array of strings (retreive from client)
$newRefPlans = array();
// this will be the new array of DBRefs
unset($rate['plans']);
foreach ($sourcePlans as &$plan) {
if (MongoDBRef::isRef($plan)) {
$newRefPlans[] = $plan;
} else {
$planEntity = $plansColl->query('name', $plan)->lessEq('from', $currentDate)->greaterEq('to', $currentDate)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref'))->current();
$newRefPlans[] = $planEntity->createRef($plansColl);
}
}
$rate['plans'] = $newRefPlans;
}
}
$data['rates'] = $rates;
}
return parent::update($data);
}
开发者ID:ngchie,项目名称:system,代码行数:39,代码来源:Rates.php
示例6: getReference
public function getReference()
{
$collection = collection::forClass($this->_className)->select();
if (null != $this->_model) {
$this->_model->save();
}
$id = $this->getId();
return \MongoDBRef::create($collection->getName(), $id, (string) $collection->db);
}
开发者ID:ExceptVL,项目名称:kanon-mongo,代码行数:9,代码来源:reference.php
示例7: testRef
public function testRef()
{
ini_set("mongo.cmd", ":");
$this->object->insert(array("_id" => 123, "hello" => "world"));
$this->object->insert(array("_id" => 456, "ref" => array(":ref" => "bar", ":id" => 123)));
$ref = $this->object->findOne(array("_id" => 456));
$obj = MongoDBRef::get($this->object->db, $ref["ref"]);
$this->assertNotNull($obj);
$this->assertEquals("world", $obj["hello"], json_encode($obj));
}
开发者ID:rjonker,项目名称:mongo-php-driver,代码行数:10,代码来源:CmdSymbolTest.php
示例8: __construct
function __construct(Glutton $glutton, $data = null, AxonCollection $parent = null, $position = null)
{
$this->_glutton = $glutton;
if (\MongoDBRef::isRef($data)) {
$this->_reference = Reader::simplifyReference($data);
$data = array_diff_key($data, $this->_reference);
}
$this->_elements = $data;
$this->_parent = $parent;
$this->_position = $position;
}
开发者ID:ephrin,项目名称:mongo-glutton,代码行数:11,代码来源:AxonCollection.php
示例9: import
/**
* Import an account.
*
* @param string $username The username to use.
* @param string $password The password to use.
*/
public function import($username, $password)
{
$data = $this->get($username);
$this->db->remove(array('username' => $this->clean($username)));
$users = new users(ConnectionFactory::get('mongo'));
$id = $users->create($username, $password, $data['email'], $data['hideEmail'], $this->groups[$data['mgroup']], true);
$newRef = MongoDBRef::create('users', $id);
$oldRef = MongoDBRef::create('unimportedUsers', $data['_id']);
$this->mongo->news->update(array('user' => $oldRef), array('$set' => array('user' => $newRef)));
$this->mongo->articles->update(array('user' => $oldRef), array('$set' => array('user' => $newRef)));
self::ApcPurge('get', $data['_id']);
}
开发者ID:Zandemmer,项目名称:HackThisSite-Old,代码行数:18,代码来源:reclaims.php
示例10: populateDb
public function populateDb()
{
$this->_users = array('bob' => array('_id' => new MongoId('4c04516a1f5f5e21361e3ab0'), '_type' => array('My_ShantyMongo_Teacher', 'My_ShantyMongo_User'), 'name' => array('first' => 'Bob', 'last' => 'Jones'), 'addresses' => array(array('street' => '19 Hill St', 'suburb' => 'Brisbane', 'state' => 'QLD', 'postcode' => '4000', 'country' => 'Australia'), array('street' => '742 Evergreen Terrace', 'suburb' => 'Springfield', 'state' => 'Nevada', 'postcode' => '89002', 'country' => 'USA')), 'friends' => array(MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), MongoDBRef::create('user', new MongoId('4c0451791f5f5e21361e3ab2')), MongoDBRef::create('user', new MongoId('broken reference'))), 'faculty' => 'Maths', 'email' => '[email protected]', 'sex' => 'M', 'partner' => MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), 'bestFriend' => MongoDBRef::create('user', new MongoId('4c0451791f5f5e21361e3ab2'))), 'cherry' => array('_id' => new MongoId('4c04516f1f5f5e21361e3ab1'), '_type' => array('My_ShantyMongo_Student', 'My_ShantyMongo_User'), 'name' => array('first' => 'Cherry', 'last' => 'Jones'), 'email' => '[email protected]', 'sex' => 'F', 'concession' => true), 'roger' => array('_id' => new MongoId('4c0451791f5f5e21361e3ab2'), '_type' => array('My_ShantyMongo_ArtStudent', 'My_ShantyMongo_Student', 'My_ShantyMongo_User'), 'name' => array('first' => 'Roger', 'last' => 'Smith'), 'email' => '[email protected]', 'sex' => 'M', 'concession' => false));
$this->_userCollection = $this->_connection->selectDb(TESTS_SHANTY_MONGO_DB)->selectCollection('user');
foreach ($this->_users as $user) {
$this->_userCollection->insert($user, true);
}
$this->_articles = array('regular' => array('_id' => new MongoId('4c04516f1f5f5e21361e3ac1'), 'title' => 'How to use Shanty Mongo', 'author' => MongoDBRef::create('user', new MongoId('4c04516a1f5f5e21361e3ab0')), 'editor' => MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), 'contributors' => array(MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), MongoDBRef::create('user', new MongoId('4c0451791f5f5e21361e3ab2'))), 'relatedArticles' => array(MongoDBRef::create('article', new MongoId('4c04516f1f5f5e21361e3ac2'))), 'tags' => array('awesome', 'howto', 'mongodb')), 'broken' => array('_id' => new MongoId('4c04516f1f5f5e21361e3ac2'), 'title' => 'How to use Bend Space and Time', 'author' => MongoDBRef::create('user', new MongoId('broken_reference')), 'tags' => array('physics', 'hard', 'cool')));
$this->_articleCollection = $this->_connection->selectDb(TESTS_SHANTY_MONGO_DB)->selectCollection('article');
foreach ($this->_articles as $article) {
$this->_articleCollection->insert($article, true);
}
}
开发者ID:rafeca,项目名称:Shanty-Mongo,代码行数:13,代码来源:TestSetup.php
示例11: _val
/**
* Transform the value in a MongoDBRef if needed
* @param $attr
* @param $value
* @return mixed
*/
protected function _val($attr, $value)
{
$reference = \Rocketr\Schema\Reference::get($this->get_collection_name(), $attr);
$collection = \Rocketr\Schema\HasCollection::get($this->get_collection_name(), $attr);
if ($reference xor $collection) {
$ref_attr = \Rocketr\Schema\Map::on($this->get_collection_name(), $attr);
$_id = is_array($value) && isset($value[$ref_attr]) || is_object($value) && $value->{$ref_attr} ? is_array($value) ? $value[$ref_attr] : $value->{$ref_attr} : $value;
$target = $reference ? $reference : $collection;
$_id = $ref_attr == '_id' && \MongoId::isValid($_id) ? new \MongoId($_id) : $_id;
return \MongoDBRef::create($target, $_id);
} else {
return $value;
}
}
开发者ID:alex-robert,项目名称:knot,代码行数:20,代码来源:Writr.php
示例12: duplicate_rates
/**
* for every rate who has ref to original plan add ref to new plan
* @param type $source_id
* @param type $new_id
*/
public function duplicate_rates($source_id, $new_id)
{
$rates_col = Billrun_Factory::db()->ratesCollection();
$source_ref = MongoDBRef::create("plans", $source_id);
$dest_ref = MongoDBRef::create("plans", $new_id);
$usage_types = Billrun_Factory::config()->getConfigValue('admin_panel.line_usages');
foreach ($usage_types as $type => $string) {
$attribute = "rates." . $type . ".plans";
$query = array($attribute => $source_ref);
$update = array('$push' => array($attribute => $dest_ref));
$params = array("multiple" => 1);
$rates_col->update($query, $update, $params);
}
}
开发者ID:ngchie,项目名称:system,代码行数:19,代码来源:Plans.php
示例13: setReference
public function setReference($name, Base $object = null) {
if (!in_array($name, static::$_references)) {
throw new Exception("Document doesn't reference {$name}");
}
$this->_referenced[$name] = $object;
if ($object === null) {
$this->_data[$name] = null;
} else {
$class = get_class($object);
$this->_data[$name] = \MongoDBRef::create($class::collection()->getName(), $object->mongoId());
}
$this->_flagAttributeAsModified($name);
}
开发者ID:raymondjavaxx,项目名称:mongo_model,代码行数:16,代码来源:Base.php
示例14: testExtendedDBRef
public function testExtendedDBRef()
{
$targetCollection = $this->getCollection('simpleTarget');
$targetId = new \MongoId();
$extends = [];
list($ref, $sourceDocument) = $this->createReferencedDocument($extends, true);
//extending by embedding some data
$ref['data'] = $sourceDocument['data'];
$targetDocument = ['_id' => $targetId, 'ref' => $ref, 'text' => 'amasource'];
$targetCollection->save($targetDocument);
$targetDocumentFromDB = $targetCollection->findOne(['_id' => $targetId]);
$this->assertTrue(\MongoDBRef::isRef($targetDocumentFromDB['ref']));
$sourceDocumentFromDB = $this->getSourceCollection()->getDBRef($targetDocumentFromDB['ref']);
$this->assertEquals($sourceDocument, $sourceDocumentFromDB);
$this->assertEquals($sourceDocumentFromDB['data'], $targetDocumentFromDB['ref']['data']);
}
开发者ID:ephrin,项目名称:mongo-glutton,代码行数:16,代码来源:NativeReferencesTest.php
示例15: readRef
/**
* Returns corresponding object indicated by MongoDBRef
*
* @param $fieldName
* @return mixed
* @throws InvalidReferenceException
*/
public function readRef($fieldName)
{
$oRef = $this->readNestedAttribute($fieldName);
if (!\MongoDBRef::isRef($oRef)) {
throw new InvalidReferenceException();
}
if (isset($this->dbRefs) && isset($this->dbRefs[$fieldName])) {
$modelInstance = $this->instantiateModel($this->dbRefs[$fieldName]);
} else {
if ($this->getDI()->has('mongoMapper')) {
$modelInstance = $this->getDI()->get('mongoMapper')->resolveModel($oRef['$ref']);
} else {
return $oRef;
}
}
return forward_static_call(array($modelInstance, 'findById'), $oRef['$id']);
}
开发者ID:arius86,项目名称:core,代码行数:24,代码来源:RefResolverTrait.php
示例16: createReferencedDocument
public function createReferencedDocument($sourceDocument = null, $refIsFull = true)
{
$sourceCollection = $this->getSourceCollection();
$sourceId = new \MongoId();
$identity = ['_id' => $sourceId, 'data' => md5(rand(0, time()))];
if (is_array($sourceDocument)) {
$sourceDocument = array_merge($sourceDocument, $identity);
} else {
$sourceDocument = $identity;
}
$sourceCollection->save($sourceDocument);
if ($refIsFull) {
return [\MongoDBRef::create($sourceCollection->getName(), $sourceId, $sourceCollection->db), $sourceDocument];
} else {
return [\MongoDBRef::create($sourceCollection->getName(), $sourceId), $sourceDocument];
}
}
开发者ID:ephrin,项目名称:mongo-glutton,代码行数:17,代码来源:GluttonBase.php
示例17: testDeferencing
/**
* @depends testReferences
*/
public function testDeferencing()
{
$d = new Model1();
$d->where('a', 'barfoo');
foreach ($d as $doc) {
$this->assertTrue(isset($doc->next));
$this->assertTrue(MongoDBRef::isRef($doc->next));
$this->assertTrue(MongoDBRef::isRef($doc->nested[0]));
$this->assertTrue(MongoDBRef::isRef($doc->nested[1]));
$this->assertTrue(MongoDBRef::isRef($doc->query));
/* Check dynamic references properties */
$this->assertTrue(is_array($doc->query['dynamic']));
$this->assertTrue(count($doc->query['dynamic']) > 0);
/* Deference */
$doc->doDeferencing();
/* Test deferenced values */
$this->assertTrue($doc->next instanceof Model1);
$this->assertTrue($doc->nested[0] instanceof Model1);
$this->assertTrue($doc->nested[1] instanceof Model1);
$this->assertTrue(is_array($doc->query));
$this->assertTrue($doc->query[0] instanceof Model1);
/* Testing mongodb refs */
$this->assertTrue(is_array($doc->mdbref));
foreach ($doc->mdbref as $property => $value) {
if ($property == '_id') {
$this->assertEquals($value, $doc->next->getID());
continue;
} else {
$this->assertEquals($value, $doc->next->{$property});
continue;
}
$this->assertTrue(FALSE);
}
/* Testing Iteration in defered documents */
/* They should fail because they are cloned */
/* instances of a real document */
try {
$doc->next->next();
$this->assertTrue(FALSE);
} catch (ActiveMongo_Exception $e) {
$this->assertTrue(TRUE);
}
}
}
开发者ID:284099857,项目名称:ActiveMongo,代码行数:47,代码来源:ReferencesTest.php
示例18: walk
public function walk($record)
{
if (!$this->started) {
$this->clear();
$this->started = true;
} else {
throw new \RuntimeException('Reader was already started. To run new scan please invoke clear() method');
}
if (is_array($record)) {
if (\MongoDBRef::isRef($record)) {
$this->references['*'] = self::simplifyReference($record);
}
array_walk($record, $this);
} elseif (is_object($record)) {
$this->walk_object($record);
} else {
throw new \InvalidArgumentException('Record for scan must be an object or an array');
}
}
开发者ID:ephrin,项目名称:mongo-glutton,代码行数:19,代码来源:Reader.php
示例19: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
if (file_exists('tests/classic.jpg')) {
unlink('tests/classic.jpg');
}
$db = $this->sharedFixture->selectDB('phpunit');
$grid = $db->getGridFS('_files', '_chunks');
$grid->drop();
$files = $db->selectCollection('_files');
$chunks = $db->selectCollection('_chunks');
$chunk4 = array('cn' => 4, 'data' => new MongoBinData('xyz'));
$chunks->insert($chunk4);
$chunk3 = array('cn' => 3, 'data' => new MongoBinData('rst'), 'next' => MongoDBRef::create($chunks->getName(), $chunk4['_id']));
$chunks->insert($chunk3);
$chunk2 = array('cn' => 2, 'data' => new MongoBinData('lmno'), 'next' => MongoDBRef::create($chunks->getName(), $chunk3['_id']));
$chunks->insert($chunk2);
$chunk1 = array('cn' => 1, 'data' => new MongoBinData('abc'), 'next' => MongoDBRef::create($chunks->getName(), $chunk2['_id']));
$chunks->insert($chunk1);
$files->insert(array("filename" => "classic.jpg", "contentType" => "image/jpeg", "length" => 4, "chunkSize" => 4, "next" => MongoDBRef::create($chunks->getName(), $chunk1['_id'])));
$file = $grid->findOne();
$this->object = new MongoGridFSFileClassic($file);
$this->object->start = memory_get_usage(true);
}
开发者ID:petewarden,项目名称:mongo-php-driver,代码行数:29,代码来源:MongoGridFSClassicTest.php
示例20: getRef
/**
* method to load Mongo DB reference object
*
* @param MongoDBRef $ref the reference object
*
* @return array
*/
public function getRef($ref)
{
if (!MongoDBRef::isRef($ref)) {
return;
}
if (!$ref['$id'] instanceof MongoId) {
$ref['$id'] = new MongoId($ref['$id']);
}
return new Mongodloid_Entity($this->_collection->getDBRef($ref));
}
开发者ID:kalburgimanjunath,项目名称:system,代码行数:17,代码来源:Collection.php
注:本文中的MongoDBRef类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论