Просмотр исходного кода

Implement MongoLog.

Add a warning to known issues.
Olivier Lechevalier 10 лет назад
Родитель
Сommit
36e75e6981
3 измененных файлов с 84 добавлено и 17 удалено
  1. 7 1
      README.md
  2. 52 16
      lib/Mongo/MongoLog.php
  3. 25 0
      tests/Alcaeus/MongoDbAdapter/MongoLogTest.php

+ 7 - 1
README.md

@@ -1,6 +1,6 @@
 # Mongo PHP Adapter
 
-The Mongo PHP Adapter is a userland library designed to act as an adapter 
+The Mongo PHP Adapter is a userland library designed to act as an adapter
 between applications relying on ext-mongo and the new driver (ext-mongodb).
 
 It provides the API of ext-mongo built on top of mongo-php-library, thus being
@@ -39,6 +39,12 @@ root:
  - The Mongo class is deprecated and was not implemented in this library. If you
  are still using it please update your code to use the new classes.
 
+## MongoLog
+
+ - The [MongoLog](http://php.net/manual/en/class.mongolog.php) class does not
+ log anything because the underlying driver does not offer a method to retrieve
+ this data.
+
 ## MongoClient
 
  - The [MongoClient::connect](https://php.net/manual/de/mongoclient.connect.php)

+ 52 - 16
lib/Mongo/MongoLog.php

@@ -13,7 +13,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-class MongoLog {
+class MongoLog
+{
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.none
      */
@@ -22,49 +23,68 @@ class MongoLog {
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.all
      */
-    const ALL = 0;
+    const ALL = 31;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.warning
      */
-    const WARNING = 0;
+    const WARNING = 1;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.info
      */
-    const INFO = 0;
+    const INFO = 2;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.fine
      */
-    const FINE = 0;
+    const FINE = 4;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.rs
      */
-    const RS = 0;
+    const RS = 1;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.pool
      */
-    const POOL = 0;
+    const POOL = 1;
+
+    /**
+     * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.con
+     */
+    const CON = 2;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.io
      */
-    const IO = 0;
+    const IO = 4;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.server
      */
-    const SERVER = 0;
+    const SERVER = 8;
 
     /**
      * @link http://php.net/manual/en/class.mongolog.php#mongolog.constants.parse
      */
-    const PARSE = 0;
+    const PARSE = 16;
 
-    const CON = 2;
+
+    private static $callback;
+    private static $level;
+    private static $module;
+
+    /**
+     * (PECL mongo >= 1.3.0)
+     * Gets the previously set callback function
+     *
+     * @return callable|null
+     */
+    public static function getCallback()
+    {
+        return self::$callback;
+    }
 
     /**
      * (PECL mongo &gt;= 1.3.0)<br/>
@@ -99,7 +119,11 @@ class MongoLog {
      * <ul>
      * @return boolean Returns <b>TRUE</b> on success or <b>FALSE</b> on failure.
      */
-    public static function setCallback ( callable $log_function ) {}
+    public static function setCallback(callable $log_function )
+    {
+        self::$callback = $log_function;
+        return true;
+    }
 
     /**
      * This function can be used to set how verbose logging should be and the types of
@@ -111,7 +135,10 @@ class MongoLog {
      * @param int $level The levels you would like to log
      * @return void
      */
-    public static function setLevel($level) {}
+    public static function setLevel($level)
+    {
+        self::$level = $level;
+    }
 
     /**
      * This can be used to see the log level. Use the constants described in the
@@ -121,7 +148,10 @@ class MongoLog {
      * @static
      * @return int Returns the current level
      */
-    public static function getLevel() {}
+    public static function getLevel()
+    {
+        return self::$level;
+    }
 
     /**
      * This function can be used to set which parts of the driver's functionality
@@ -133,7 +163,10 @@ class MongoLog {
      * @param int $module The module(s) you would like to log
      * @return void
      */
-    public static function setModule($module) {}
+    public static function setModule($module)
+    {
+        self::$module = $module;
+    }
 
     /**
      * This function can be used to see which parts of the driver's functionality are
@@ -144,5 +177,8 @@ class MongoLog {
      * @static
      * @return int Returns the modules currently being logged
      */
-    public static function getModule() {}
+    public static function getModule()
+    {
+        return self::$module;
+    }
 }

+ 25 - 0
tests/Alcaeus/MongoDbAdapter/MongoLogTest.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace Alcaeus\MongoDbAdapter\Tests;
+
+class MongoLogTest extends \PHPUnit_Framework_Testcase
+{
+    public function testSetCallback()
+    {
+        $foo = function() {};
+        $this->assertTrue(\MongoLog::setCallback($foo));
+        $this->assertSame($foo, \MongoLog::getCallback());
+    }
+
+    public function testLevel()
+    {
+        \MongoLog::setLevel(2);
+        $this->assertSame(2, \MongoLog::getLevel(2));
+    }
+
+    public function testModule()
+    {
+        \MongoLog::setModule(2);
+        $this->assertSame(2, \MongoLog::getModule(2));
+    }
+}