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


PHP JSON::arr方法代码示例

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


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

示例1: count

 /**
  * Countable: count
  *
  * Count the results from the current query: pass FALSE for "all" results (disregard limit/skip)<br/>
  * Count results of a separate query: pass an array or JSON string of query parameters
  *
  * @param  mixed $query
  * @throws Exception
  * @return int
  */
 public function count($query = TRUE)
 {
     if (is_bool($query)) {
         // Profile count operation for cursor
         if ($this->db()->profiling) {
             $bm = $this->db()->profiler_start("Mongo_Database::{$this->db}", $this->inspect() . ".count(" . JSON::str($query) . ")");
         }
         $this->_cursor or $this->load(TRUE);
         $count = $this->_cursor->count($query);
     } else {
         if (is_string($query) && $query[0] == "{") {
             $query = JSON::arr($query);
             if ($query === NULL) {
                 throw new Exception('Unable to parse query from JSON string.');
             }
         }
         $query_trans = array();
         foreach ($query as $field => $value) {
             $query_trans[$this->get_field_name($field)] = $value;
         }
         $query = $query_trans;
         // Profile count operation for collection
         if ($this->db()->profiling) {
             $bm = $this->db()->profiler_start("Mongo_Database::{$this->db}", "db.{$this->name}.count(" . ($query ? JSON::str($query) : '') . ")");
         }
         $count = $this->collection()->count($query);
     }
     // End profiling count
     if (isset($bm)) {
         $this->db()->profiler_stop($bm);
     }
     if (is_array($count)) {
         throw new MongoException(json_encode($count));
     }
     return $count;
 }
开发者ID:andygoo,项目名称:mongodb-php-odm,代码行数:46,代码来源:collection.php

示例2: load

 /**
  * Load the document from the database. The first parameter may be one of:
  *
  *  a falsey value - the object data will be used to construct the query
  *  a JSON string - will be parsed and used for the query
  *  an non-array value - the query will be assumed to be for an _id of this value
  *  an array - the array will be used for the query
  *
  * @param   array  specify additional criteria
  * @param   array  specify the fields to return
  * @return  boolean  TRUE if the load succeeded
  */
 public function load($criteria = array(), array $fields = array())
 {
     // Use of json for querying is allowed
     if (is_string($criteria) && $criteria[0] == "{") {
         $criteria = JSON::arr($criteria);
     } else {
         if ($criteria && !is_array($criteria)) {
             $criteria = array('_id' => $criteria);
         } else {
             if (isset($this->_object['_id'])) {
                 $criteria = array('_id' => $this->_object['_id']);
             } else {
                 if (isset($criteria['id'])) {
                     $criteria = array('_id' => $criteria['id']);
                 } else {
                     if (!$criteria) {
                         $criteria = $this->_object;
                     }
                 }
             }
         }
     }
     if (!$criteria) {
         throw new MongoException('Cannot find ' . get_class($this) . ' without _id or other search criteria.');
     }
     // Cast query values to the appropriate types and translate aliases
     $new = array();
     foreach ($criteria as $key => $value) {
         $key = $this->get_field_name($key);
         $new[$key] = $this->_cast($key, $value);
     }
     $criteria = $new;
     // Translate field aliases
     $fields = array_map(array($this, 'get_field_name'), $fields);
     $values = $this->collection()->__call('findOne', array($criteria, $fields));
     // Only clear the object if necessary
     if ($this->_loaded !== NULL || $this->_changed || $this->_operations) {
         $this->clear();
     }
     $this->load_values($values, TRUE);
     return $this->_loaded;
 }
开发者ID:enormego,项目名称:EightPHP,代码行数:54,代码来源:document.php


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