Skip to content

Commit

Permalink
Added logging to MongoCursor::sort().
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed Sep 15, 2010
1 parent 54582f5 commit 524c5ae
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/Doctrine/ODM/MongoDB/MongoCursor.php
Expand Up @@ -47,6 +47,9 @@ class MongoCursor implements \Iterator, \Countable
/** Whether or not to try and hydrate the returned data */
private $hydrate = true;

/** A callable for logging statements. */
private $loggerCallable;

/**
* Create a new MongoCursor which wraps around a given PHP MongoCursor.
*
Expand All @@ -62,6 +65,23 @@ public function __construct(DocumentManager $dm, Hydrator $hydrator, ClassMetada
$this->hydrator = $hydrator;
$this->class = $class;
$this->mongoCursor = $mongoCursor;
$this->loggerCallable = $this->dm->getConfiguration()->getLoggerCallable();
}

/**
* Log something using the configured logger callable.
*
* @param array $log The array of data to log.
*/
public function log(array $log)
{
if ( ! $this->loggerCallable) {
return;
}
$log['class'] = $this->class->name;
$log['db'] = $this->class->db;
$log['collection'] = $this->class->collection;
call_user_func_array($this->loggerCallable, array($log));
}

/**
Expand Down Expand Up @@ -137,6 +157,21 @@ public function count()
return $this->mongoCursor->count();
}

/** @override */
public function sort($fields)
{
if ($this->loggerCallable) {
$this->log(array(
'sort' => true,
'fields' => $fields,
));
}

$this->mongoCursor->sort($fields);

return $this;
}

/**
* Returns an array by converting the iterator to an array.
*
Expand Down

0 comments on commit 524c5ae

Please sign in to comment.