Skip to content

Commit

Permalink
Replaced Indents
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammaye committed Nov 28, 2013
1 parent ac12ffd commit 2b84129
Show file tree
Hide file tree
Showing 6 changed files with 560 additions and 556 deletions.
128 changes: 64 additions & 64 deletions EMongoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EMongoClient extends CApplicationComponent{
/**
* The name of the database
* @var string
*/
*/
public $db;

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ class EMongoClient extends CApplicationComponent{
/**
* The Legacy read preference. DO NOT USE IF YOU ARE ON VERSION 1.3+
* @var boolean
*/
*/
public $setSlaveOkay = false;

/**
Expand Down Expand Up @@ -89,7 +89,7 @@ class EMongoClient extends CApplicationComponent{
/**
* The default action is to find a getX whereby X is the $k param
* you input. The secondary function, if not getter found, is to get a collection
*/
*/
public function __get($k){
$getter='get'.$k;
if(method_exists($this,$getter))
Expand All @@ -99,13 +99,13 @@ public function __get($k){

/**
* Will call a function on the database or error out stating that the function does not exist
* @param string $name
* @param array $parameters
* @return mixed
*/
public function __call($name,$parameters = array()){
* @param string $name
* @param array $parameters
* @return mixed
*/
public function __call($name,$parameters = array()){
if(!method_exists($this->getDB(), $name))
return null;
return null;
return call_user_func_array(array($this->getDB(), $name), $parameters);
}

Expand Down Expand Up @@ -206,8 +206,8 @@ public function close(){
public function aggregate($collection, $pipelines){
if(version_compare(phpversion('mongo'), '1.3.0', '<')){
return $this->getDB()->command(array(
'aggregate' => $collection,
'pipeline' => $pipelines
'aggregate' => $collection,
'pipeline' => $pipelines
));
}
return $this->getDB()->$collection->aggregate($pipelines);
Expand Down Expand Up @@ -239,8 +239,8 @@ public function selectCollection($name){
*/
function setDocumentCache($o){
if(
$this->getDocumentCache(get_class($o))===array() && // Run reflection and cache it if not already there
(get_class($o) != 'EMongoDocument' && get_class($o) != 'EMongoModel') /* We can't cache the model */
$this->getDocumentCache(get_class($o))===array() && // Run reflection and cache it if not already there
(get_class($o) != 'EMongoDocument' && get_class($o) != 'EMongoModel') /* We can't cache the model */
){

$_meta = array();
Expand All @@ -255,8 +255,8 @@ function setDocumentCache($o){

$docBlock = $prop->getDocComment();
$field_meta = array(
'name' => $prop->getName(),
'virtual' => $prop->isProtected() || preg_match('/@virtual/i', $docBlock) <= 0 ? false : true
'name' => $prop->getName(),
'virtual' => $prop->isProtected() || preg_match('/@virtual/i', $docBlock) <= 0 ? false : true
);

// Lets fetch the data type for this field
Expand All @@ -281,7 +281,7 @@ public function getFieldCache($name, $include_virtual = false){
$fields = array();

foreach($doc as $name => $opts)
if($include_virtual || !$opts['virtual']) $fields[] = $name;
if($include_virtual || !$opts['virtual']) $fields[] = $name;
return $fields;
}

Expand All @@ -300,11 +300,11 @@ public function getDocumentCache($name){
*/
public function getDefaultWriteConcern(){
if(!version_compare(phpversion('mongo'), '1.3.0', '<'))
return array('w' => $this->w, 'j' => $this->j);
if($this->w == 1)
return array('safe' => true);
if($this->w > 0)
return array('safe' => $this->w);
return array('w' => $this->w, 'j' => $this->j);
if($this->w == 1)
return array('safe' => true);
if($this->w > 0)
return array('safe' => $this->w);
return array();
}

Expand All @@ -316,21 +316,21 @@ public function getDefaultWriteConcern(){
*/
public function createMongoIdFromTimestamp($yourTimestamp)
{
static $inc = 0;
static $inc = 0;

$ts = pack( 'N', $yourTimestamp );
$m = substr( md5( gethostname()), 0, 3 );
$pid = pack( 'n', getmypid() );
$trail = substr( pack( 'N', $inc++ ), 1, 3);
$ts = pack( 'N', $yourTimestamp );
$m = substr( md5( gethostname()), 0, 3 );
$pid = pack( 'n', getmypid() );
$trail = substr( pack( 'N', $inc++ ), 1, 3);

$bin = sprintf("%s%s%s%s", $ts, $m, $pid, $trail);
$bin = sprintf("%s%s%s%s", $ts, $m, $pid, $trail);

$id = '';
for ($i = 0; $i < 12; $i++ )
{
$id .= sprintf("%02X", ord($bin[$i]));
}
return new MongoID($id);
$id = '';
for ($i = 0; $i < 12; $i++ )
{
$id .= sprintf("%02X", ord($bin[$i]));
}
return new MongoID($id);
}

/**
Expand All @@ -352,37 +352,37 @@ public function setSlaveOkay($bool){
return $this->getConnection()->setSlaveOkay($bool);
}

/**
* @return array the first element indicates the number of query statements executed,
* and the second element the total time spent in query execution.
*/
public function getStats()
{
$logger=Yii::getLogger();
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.findOne');
$count=count($timings);
$time=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.insert');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.find');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.deleteByPk');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.updateByPk');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.updateAll');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.deleteAll');
$count+=count($timings);
$time+=array_sum($timings);

return array($count,$time);
}
/**
* @return array the first element indicates the number of query statements executed,
* and the second element the total time spent in query execution.
*/
public function getStats()
{
$logger=Yii::getLogger();
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.findOne');
$count=count($timings);
$time=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.insert');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.find');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.deleteByPk');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.updateByPk');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.updateAll');
$count+=count($timings);
$time+=array_sum($timings);
$timings=$logger->getProfilingResults(null,'extensions.MongoYii.EMongoDocument.deleteAll');
$count+=count($timings);
$time+=array_sum($timings);

return array($count,$time);
}
}

/**
Expand Down
42 changes: 21 additions & 21 deletions EMongoCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EMongoCriteria extends CComponent {

/**
* Holds information for what should be projected from the cursor
* into active models. The reason for this obscure name is because this
* into active models. The reason for this obscure name is because this
* is what it is called in MongoDB, basically it is SELECT though.
* @var array
*/
Expand All @@ -40,7 +40,7 @@ class EMongoCriteria extends CComponent {
/**
* Constructor.
* @param array $data - criteria initial property values (indexed by property name)
*/
*/
public function __construct($data = array()){
foreach($data as $name => $value)
$this->$name = $value;
Expand All @@ -63,7 +63,7 @@ public function setCondition(array $condition=array()) {
public function getCondition() {
return $this->_condition;
}

/**
* Sets the sort
* @param array $sort
Expand All @@ -72,7 +72,7 @@ public function getCondition() {
public function setSort(array $sort) {
$this->_sort = CMap::mergeArray($sort, $this->_sort);
return $this;
}
}

/**
* Gets the sort
Expand All @@ -90,16 +90,16 @@ public function getSort() {
public function setSkip($skip) {
$this->_skip = (int)$skip;
return $this;
}
}

/**
* Gets the skip
* @return int
*/
public function getSkip() {
return $this->_skip;
}

/**
* Sets the limit
* @param int $limit
Expand All @@ -109,7 +109,7 @@ public function setLimit($limit) {
$this->_limit = (int)$limit;
return $this;
}


/**
* Gets the limit
Expand All @@ -118,7 +118,7 @@ public function setLimit($limit) {
public function getLimit() {
return $this->_limit;
}

/**
* Sets the projection (SELECT in MongoDB Lingo) of the criteria
* @param array $document - The document specification for projection
Expand All @@ -127,7 +127,7 @@ public function getLimit() {
public function setProject($document){
$this->_project = $document;
return $this;
}
}

/**
* This means that the getters and setters for projection will be access like:
Expand All @@ -137,21 +137,21 @@ public function setProject($document){
public function getProject(){
return $this->_project;
}

/**
* An alias for those too used to select
* @see EMongoCriteria::setProject()
* @param array $document
* @return EMongoCriteria
*/
public function setSelect($document){
return $this->setProject($document);
* @param array $document
* @return EMongoCriteria
*/
public function setSelect($document){
return $this->setProject($document);
}

/**
* An alias for those too used to select
* @see EMongoCriteria::getProject()
* @return array
* @return array
*/
public function getSelect(){
return $this->getProject();
Expand Down Expand Up @@ -200,9 +200,9 @@ public function compare($column, $value = null, $partialMatch = false) {
$value = new MongoRegex("/$value/i");
else {
if(
!is_bool($value) && !is_array($value) && preg_match('/^([0-9]|[1-9]{1}\d+)$/' /* Will only match real integers, unsigned */, $value) > 0
&& ( (PHP_INT_MAX > 2147483647 && (string)$value < '9223372036854775807') /* If it is a 64 bit system and the value is under the long max */
|| (string)$value < '2147483647' /* value is under 32bit limit */)
!is_bool($value) && !is_array($value) && preg_match('/^([0-9]|[1-9]{1}\d+)$/' /* Will only match real integers, unsigned */, $value) > 0
&& ( (PHP_INT_MAX > 2147483647 && (string)$value < '9223372036854775807') /* If it is a 64 bit system and the value is under the long max */
|| (string)$value < '2147483647' /* value is under 32bit limit */)
)
$value = (int)$value;
}
Expand Down
Loading

0 comments on commit 2b84129

Please sign in to comment.