当前位置: 首页>>代码示例>>PHP>>正文


PHP MongoDBRef::get方法代码示例

本文整理汇总了PHP中MongoDBRef::get方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoDBRef::get方法的具体用法?PHP MongoDBRef::get怎么用?PHP MongoDBRef::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDBRef的用法示例。


在下文中一共展示了MongoDBRef::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 public function validate($contentId, $text, $creating = true)
 {
     $valid = false;
     foreach ($this->commentableCollections as $collection) {
         $ref = MongoDBRef::create($collection, $this->_toMongoId($contentId));
         $result = MongoDBRef::get($this->mongo, $ref);
         if ($result != null) {
             $valid = true;
             break;
         }
     }
     if (!$valid) {
         return 'Invalid content id.';
     }
     $ref = MongoDBRef::create('users', Session::getVar('_id'));
     $text = substr($this->clean(preg_replace('/\\s{6,}/', "\n\n", preg_replace('/[[:blank:]]+/', ' ', $text))), 0, 1000);
     if (empty($text)) {
         return 'Invalid comment.';
     }
     $entry = array('contentId' => (string) $contentId, 'date' => time(), 'text' => $text, 'user' => $ref, 'ghosted' => false);
     if (!$creating) {
         unset($entry['contentId'], $entry['date'], $entry['user'], $entry['ghosted']);
     }
     self::ApcPurge('getForId', $contentId);
     return $entry;
 }
开发者ID:Zandemmer,项目名称:HackThisSite-Old,代码行数:26,代码来源:comments.php

示例2: resolveNotes

 private function resolveNotes($user)
 {
     if (empty($user['notes'])) {
         return $user;
     }
     foreach ($user['notes'] as $k => $note) {
         $user['notes'][$k]['user'] = MongoDBRef::get($this->mongo, $user['notes'][$k]['user']);
     }
     return $user;
 }
开发者ID:Zandemmer,项目名称:HackThisSite-Old,代码行数:10,代码来源:users.php

示例3: 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

示例4: testGet

 public function testGet()
 {
     $this->object->db->selectCollection("d")->insert(array("_id" => 123, "greeting" => "hi"));
     $this->sharedFixture->selectCollection("phpunit_temp", "d")->insert(array("_id" => 123, "greeting" => "bye"));
     $x = MongoDBRef::get($this->object->db, array('$ref' => "d", '$id' => 123));
     $this->assertNotNull($x);
     $this->assertEquals("hi", $x['greeting'], json_encode($x));
     $x = MongoDBRef::get($this->object->db, array('$ref' => "d", '$id' => 123, '$db' => 'phpunit_temp'));
     $this->assertNotNull($x);
     $this->assertEquals("bye", $x['greeting'], json_encode($x));
 }
开发者ID:petewarden,项目名称:mongo-php-driver,代码行数:11,代码来源:MongoDBRefTest.php

示例5: testGetDBRef

 public function testGetDBRef()
 {
     $db = $this->sharedFixture->selectDB("foo");
     $c = $db->selectCollection("bar");
     $obj = array("uid" => 0);
     $c->insert($obj);
     $ref = $c->createDBRef($obj);
     $mem = memory_get_usage(true);
     for ($i = 0; $i < 10000; $i++) {
         MongoDBRef::get($db, $ref);
     }
     $this->assertEquals($mem, memory_get_usage(true));
 }
开发者ID:petewarden,项目名称:mongo-php-driver,代码行数:13,代码来源:MongoMemTest.php

示例6: testGet

 public function testGet()
 {
     $this->object->db->d->insert(array("_id" => 123, "greeting" => "hi"));
     $m = new Mongo();
     $c = $m->phpunit_temp->d;
     $c->drop();
     $c->insert(array("_id" => 123, "greeting" => "bye"), true);
     $x = MongoDBRef::get($this->object->db, array('$ref' => "d", '$id' => 123));
     $this->assertNotNull($x);
     $this->assertEquals("hi", $x['greeting'], json_encode($x));
     $x = MongoDBRef::get($this->object->db, array('$ref' => "d", '$id' => 123, '$db' => 'phpunit_temp'));
     $this->assertNotNull($x);
     $this->assertEquals("bye", $x['greeting'], json_encode($x));
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:14,代码来源:MongoDBRefTest.php

示例7: populateReference

 /**
  * @param mixed $reference Reference to populate
  * @param null|string $cname Class of model to populate. If not specified, populates data on current model
  * @return EMongoModel
  */
 public function populateReference($reference, $cname = null)
 {
     $row = MongoDBRef::get(self::$db->getDB(), $reference);
     $o = is_null($cname) ? $this : $cname::model();
     return $o->populateRecord($row);
 }
开发者ID:pvassiliou,项目名称:MongoYii,代码行数:11,代码来源:EMongoModel.php

示例8: doDeferencing

 /**
  *  Perform a deferencing in the current document, if there is
  *  any reference.
  *
  *  ActiveMongo will do its best to group references queries as much 
  *  as possible, in order to perform as less request as possible.
  *
  *  ActiveMongo doesn't rely on MongoDB references, but it can support 
  *  it, but it is prefered to use our referencing.
  *
  *  @experimental
  */
 final function doDeferencing($refs = array())
 {
     /* Get current document */
     $document = get_document_vars($this);
     if (count($refs) == 0) {
         /* Inspect the whole document */
         $this->getDocumentReferences($document, $refs);
     }
     $db = $this->_getConnection();
     /* Gather information about ActiveMongo Objects
      * that we need to create
      */
     $classes = array();
     foreach ($refs as $ref) {
         if (!isset($ref['ref']['class'])) {
             /* Support MongoDBRef, we do our best to be compatible {{{ */
             /* MongoDB 'normal' reference */
             $obj = MongoDBRef::get($db, $ref['ref']);
             /* Offset the current document to the right spot */
             /* Very inefficient, never use it, instead use ActiveMongo References */
             $this->_deferencingRestoreProperty($document, $ref['key'], $obj);
             /* Dirty hack, override our current document 
              * property with the value itself, in order to
              * avoid replace a MongoDB reference by its content
              */
             $this->_deferencingRestoreProperty($this->_current, $ref['key'], $obj);
             /* }}} */
         } else {
             if (isset($ref['ref']['dynamic'])) {
                 /* ActiveMongo Dynamic Reference */
                 /* Create ActiveMongo object */
                 $req = $this->_deferencingCreateObject($ref['ref']['class']);
                 /* Restore saved query */
                 $req->_deferencingQuery($ref['ref']['dynamic']);
                 $results = array();
                 /* Add the result set */
                 foreach ($req as $result) {
                     $results[] = clone $result;
                 }
                 /* add  information about the current reference */
                 foreach ($ref['ref'] as $key => $value) {
                     $results[$key] = $value;
                 }
                 $this->_deferencingRestoreProperty($document, $ref['key'], $results);
             } else {
                 /* ActiveMongo Reference FTW! */
                 $classes[$ref['ref']['class']][] = $ref;
             }
         }
     }
     /* {{{ Create needed objects to query MongoDB and replace
      * our references by its objects documents. 
      */
     foreach ($classes as $class => $refs) {
         $req = $this->_deferencingCreateObject($class);
         /* Load list of IDs */
         $ids = array();
         foreach ($refs as $ref) {
             $ids[] = $ref['ref']['$id'];
         }
         /* Search to MongoDB once for all IDs found */
         $req->find($ids);
         /* Replace our references by its objects */
         foreach ($refs as $ref) {
             $id = $ref['ref']['$id'];
             $place = $ref['key'];
             foreach ($req as $item) {
                 if ($item->getID() == $id) {
                     $this->_deferencingRestoreProperty($document, $place, clone $req);
                 }
             }
             unset($obj);
         }
         /* Release request, remember we
          * safely cloned it,
          */
         unset($req);
     }
     // }}}
     /* Replace the current document by the new deferenced objects */
     foreach ($document as $key => $value) {
         $this->{$key} = $value;
     }
 }
开发者ID:284099857,项目名称:ActiveMongo,代码行数:96,代码来源:ActiveMongo.php

示例9: resolveUser

 /**
  * Resolves user references.
  * 
  * @param array &$user User reference.
  */
 public function resolveUser(&$user)
 {
     if (isset($user['$id']) && !$user['$id']) {
         $user = array('username' => 'Anonymous');
     } else {
         if (is_string($user)) {
             $user = array('username' => $user);
         } else {
             $user = MongoDBRef::get($this->mongo, $user);
         }
     }
     if (empty($user)) {
         $user = array('username' => 'Unknown');
     }
 }
开发者ID:Zandemmer,项目名称:HackThisSite-Old,代码行数:20,代码来源:basemodel.php

示例10: get_dbref

 /**
  * Get database reference
  *
  * Get mongo object from database reference using MongoDBRef
  *
  * <code>
  * $this->mongo_db->get_dbref($object);
  * </code>
  *
  * @param object $object A dbref object
  *
  * @access public
  * @return array|object
  */
 public function get_dbref($object)
 {
     if (empty($object) || !isset($object)) {
         $this->_show_error('To use MongoDBRef::get() ala get_dbref() you must pass a valid reference object', 500);
     }
     return MongoDBRef::get($this->_dbhandle, $object);
 }
开发者ID:NaszvadiG,项目名称:cim-xa,代码行数:21,代码来源:Mongo_db.php

示例11: getDBRef

 /**
  * Fetches the document pointed to by a database reference
  *
  * @link http://www.php.net/manual/en/mongodb.getdbref.php
  * @param array $ref A database reference.
  * @return array Returns the document pointed to by the reference.
  */
 public function getDBRef(array $ref)
 {
     return MongoDBRef::get($this, $ref);
 }
开发者ID:alcaeus,项目名称:mongo-php-adapter,代码行数:11,代码来源:MongoDB.php

示例12: testGetWithInvalidRef

 public function testGetWithInvalidRef()
 {
     $db = $this->getDatabase();
     $this->assertNull(\MongoDBRef::get($db, []));
 }
开发者ID:alcaeus,项目名称:mongo-php-adapter,代码行数:5,代码来源:MongoDBRefTest.php

示例13: loadAssociation

 protected function loadAssociation($kind, $attrName, array $options)
 {
     if (!isset($options['className'])) {
         $remoteClass = $this->resolveAssociationClass($attrName);
     } else {
         $remoteClass = $options['className'];
     }
     $infl = self::services()->get('inflector');
     $foreignKey = $infl->singularize(static::tableName()) . '_id';
     switch ($kind) {
         case 'hasMany':
             if (isset($this->attributes[$attrName]) && is_array($this->attributes[$attrName])) {
                 /**
                  * If the attribute is present and it is an array, it is assumed
                  * it's an array of references.
                  * Missing records are ignored.
                  */
                 $assoc = new \Rails\ActiveRecord\Collection();
                 foreach ($this->attributes[$attrName] as $ref) {
                     if ($record = $remoteClass::where(['_id' => (int) $ref['$id']])->first()) {
                         $assoc[] = $record;
                     }
                 }
             } else {
                 /**
                  * Fetch the models from the associated collection.
                  * Note that the documents must have a {referenced_table_name}_id
                  * key (like "user_id") holding a reference to this record.
                  */
                 $assoc = $remoteClass::where([$infl->singularize(static::tableName()) . '.$id' => $this->id()]);
             }
             break;
         case 'belongsTo':
             if (!isset($this->attributes[$attrName])) {
                 return null;
             } elseif (!is_array($this->attributes[$attrName])) {
                 throw new Exception\InvalidArgumentException(sprintf("Belongs-to attribute value %s::\$%s must be MongoDBRef (array), %s passed", get_called_class(), $attrName, gettype($attrName)));
             }
             $refData = \MongoDBRef::get(static::connection()->database(), $this->attributes[$attrName]);
             if ($refData) {
                 $assoc = new $remoteClass($refData);
                 $assoc->isNewRecord = false;
             }
             break;
     }
     return $assoc;
 }
开发者ID:railsphp,项目名称:nosql,代码行数:47,代码来源:Base.php

示例14: get_dbref

 /**
  *	--------------------------------------------------------------------------------
  *	Get Database Reference
  *	--------------------------------------------------------------------------------
  *
  *	Get mongo object from database reference using MongoDBRef
  *
  *	@usage : $this->mongo_db->get_dbref($object);
  */
 public function get_dbref($obj)
 {
     if (empty($obj) or !isset($obj)) {
         show_error('To use MongoDBRef::get() ala get_dbref() you must pass a valid reference object', 500);
     }
     if ($this->CI->config->item('mongo_return') == 'object') {
         return (object) MongoDBRef::get($this->db, $obj);
     } else {
         return (array) MongoDBRef::get($this->db, $obj);
     }
 }
开发者ID:bigjoevtrj,项目名称:codeigniter-bootstrap,代码行数:20,代码来源:Mongo_db.php

示例15: getProperty

 /**
  * Get a property
  * 
  * @param mixed $property
  */
 public function getProperty($index = null)
 {
     $new = is_null($index);
     // If property exists and initialised then return it
     if (!$new && array_key_exists($index, $this->_data)) {
         return $this->_data[$index];
     }
     // Make sure we are not trying to create a document that is supposed to be saved as a reference
     if ($new && $this->hasRequirement(static::DYNAMIC_INDEX, 'AsReference')) {
         require_once 'Shanty/Mongo/Exception.php';
         throw new Shanty_Mongo_Exception("Can not create a new document from documentset where document must be saved as a reference");
     }
     if (!$new) {
         // Fetch clean data for this property if it exists
         if (array_key_exists($index, $this->_cleanData)) {
             $data = $this->_cleanData[$index];
         } else {
             return null;
         }
     } else {
         $data = array();
     }
     // If property is a reference to another document then fetch the reference document
     if (MongoDBRef::isRef($data)) {
         $collection = $data['$ref'];
         $data = MongoDBRef::get($this->_getMongoDB(false), $data);
         // If this is a broken reference then no point keeping it for later
         if (!$data) {
             $this->_data[$index] = null;
             return $this->_data[$index];
         }
         $reference = true;
     } else {
         $reference = false;
         $collection = $this->getConfigAttribute('collection');
     }
     $config = array();
     $config['new'] = $new;
     $config['requirementModifiers'] = $this->getRequirements(self::DYNAMIC_INDEX . '.');
     $config['parentIsDocumentSet'] = true;
     $config['connectionGroup'] = $this->getConfigAttribute('connectionGroup');
     $config['db'] = $this->getConfigAttribute('db');
     $config['collection'] = $collection;
     $config['parent'] = $this;
     // keep track of hierarchy
     if (!$reference) {
         // If this is a new array element. We will $push to the array when saving
         if ($new) {
             $path = $this->getPathToDocument();
         } else {
             $path = $this->getPathToProperty($index);
         }
         $config['pathToDocument'] = $path;
         $config['criteria'] = $this->getCriteria();
         $config['hasId'] = $this->hasRequirement(self::DYNAMIC_INDEX, 'hasId');
     }
     // get the document class
     $documentClass = $this->hasRequirement(self::DYNAMIC_INDEX, 'Document');
     if (isset($data['_type']) && !empty($data['_type'][0])) {
         $documentClass = $data['_type'][0];
     }
     $document = new $documentClass($data, $config);
     // if this document was a reference then remember that
     if ($reference) {
         $this->_references->attach($document);
     }
     // If this is not a new document cache it
     if (!$new) {
         $this->_data[$index] = $document;
     }
     return $document;
 }
开发者ID:rremigius,项目名称:Shanty-Mongo,代码行数:77,代码来源:DocumentSet.php


注:本文中的MongoDBRef::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。