OSDN Git Service

Abstract にあわせて,Cachemanager_Memcacheの実装に変更
authorSotaro KARASAWA <sotaro.k@gmail.com>
Wed, 8 Jul 2009 08:48:42 +0000 (17:48 +0900)
committerSotaro KARASAWA <sotaro.k@gmail.com>
Wed, 8 Jul 2009 08:48:42 +0000 (17:48 +0900)
 - config の値の取得,デフォルトのconfigの値の設定方法に変更
 - etc.ini.php の skel を変更

CHANGES
class/Plugin/Abstract.php
class/Plugin/Cachemanager.php
skel/etc.ini.php
test/Plugin/Abstract/Ethna_Plugin_Abstract_Test.php
test/Plugin/Cachemanager/Ethna_Plugin_Cachemanager_Memcache_Test.php [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index b8479f2..19cfffc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -14,6 +14,8 @@
 - Ethna_Plugin::import という,プラグインソースをincludeするための,staticメソッドを追加.
 - すべてのPluginの基底となる抽象クラス,Ethna_Plugin_Abstractを追加
 -- 既存のプラグインの親クラスを,Ethna_Plugin_Abstract を継承するように変更
+-- Plugin に設定を受け渡す方法を変更したため,etcのskelを変更
+--- それに伴い,Ethna_Plugin_Cachemanager_Memcacheの設定方法を変更
 
 *** bug fix
 
index 8cc1ab4..d14ad21 100644 (file)
@@ -67,17 +67,15 @@ class Ethna_Plugin_Abstract
 
         $this->action_form =& $controller->getActionForm();
         $this->af =& $this->action_form;
-        //
-        $this->type = $type;
-        $this->name = $name;
+
 
         // if constractor called without parameter $type or $name, auto detect type and name of self.
         if ($this->type === null) {
-            $this->type = $this->_detectType();
+            $this->type = $this->_detectType($type);
         }
 
         if ($this->name === null) {
-            $this->name = $this->_detectName();
+            $this->name = $this->_detectName($name);
         }
 
         // load plugin hook
@@ -128,7 +126,12 @@ class Ethna_Plugin_Abstract
             $this->config = $this->config_default;
         }
         else {
-            $this->config = array_merge($this->config_default, $plugin_config[$this->type]);
+            if ($this->name === null) {
+                $this->config = array_merge($this->config_default, $plugin_config[$this->type]);
+            }
+            else {
+                $this->config = array_merge($this->config_default, $plugin_config[$this->type][$this->name]);
+            }
         }
         return true;
     }
@@ -138,11 +141,15 @@ class Ethna_Plugin_Abstract
      *
      *  @access protected
      */
-    function _detectType()
+    function _detectType($type = null)
     {
+        if ($type !== null) {
+            return strtolower($type);
+        }
+
         $type = array_shift(explode("_", str_replace("Ethna_Plugin_", "",  get_class($this))));
         if ($type !== "") {
-            return $type;
+            return strtolower($type);
         }
         else {
             return null;
@@ -154,11 +161,15 @@ class Ethna_Plugin_Abstract
      *
      *  @access protected
      */
-    function _detectName()
+    function _detectName($name = null)
     {
+        if ($name !== null) {
+            return strtolower($name);
+        }
+
         $name = explode("_", str_replace("Ethna_Plugin_", "", get_class($this)));
         if (count($name) === 2) {
-            return $name[1];
+            return strtolower($name[1]);
         }
         else {
             return null;
index b2b5f37..fbe22ab 100644 (file)
@@ -39,9 +39,7 @@ class Ethna_Plugin_Cachemanager extends Ethna_Plugin_Abstract
     /*
     function Ethna_Plugin_Cachemanager(&$controller)
     {
-        $this->controller =& $controller;
-        $this->backend =& $this->controller->getBackend();
-        $this->config =& $this->controller->getConfig();
+        parent::Ethna_Plugin_Abstract($controller);
     }
     */
 
index e4bdc9d..de10b9f 100644 (file)
@@ -68,30 +68,34 @@ $config = array(
 $config['plugin'] = array(
     // plugin config
     //'type' => array(
+    //    'name' => array(
+    //    ),
     //),
 
     // memcache
     // sample-1: single (or default) memcache
-    'memcache' => array(
-        // 'host' => 'localhost',
-        // 'port' => 11211,
-        // 'use_pconnect' => false,
-        // 'retry' => 3,
-        // 'timeout' => 3,
+    'cachemanager' => array(
+        //'memcache' => array(
+        //     'host' => 'localhost',
+        //     'port' => 11211,
+        //     'use_pconnect' => false,
+        //     'retry' => 3,
+        //     'timeout' => 3,
 
-        // sample-2: multiple memcache servers (distributing w/ namespace and ids)
-        'info' => array(
-           'namespace1' => array(
-               0 => array(
-                   'host' => 'cache1.example.com',
-                   'port' => 11211,
-               ),
-               1 => array(
-                   'host' => 'cache2.example.com',
-                   'port' => 11211,
-               ),
-           ),
-        ),
+        //    // sample-2: multiple memcache servers (distributing w/ namespace and ids)
+        //    //'info' => array(
+        //    //   'namespace1' => array(
+        //    //       0 => array(
+        //    //           'host' => 'cache1.example.com',
+        //    //           'port' => 11211,
+        //    //       ),
+        //    //       1 => array(
+        //    //           'host' => 'cache2.example.com',
+        //    //           'port' => 11211,
+        //    //       ),
+        //    //   ),
+        //    //),
+        //),
     ),
 );
 ?>
index 0727412..1794d48 100644 (file)
@@ -28,11 +28,11 @@ class Ethna_Plugin_Abstract_Test extends Ethna_UnitTestBase
 
     function testDetectTypeAndName()
     {
-        $this->assertEqual('Abstract', $this->abstract->getType());
+        $this->assertEqual('abstract', $this->abstract->getType());
         $this->assertEqual(null, $this->abstract->getName());
 
-        $this->assertEqual('Logwriter', $this->lw->getType());
-        $this->assertEqual('Echo', $this->lw->getName());
+        $this->assertEqual('logwriter', $this->lw->getType());
+        $this->assertEqual('echo', $this->lw->getName());
     }
 }
 ?>
diff --git a/test/Plugin/Cachemanager/Ethna_Plugin_Cachemanager_Memcache_Test.php b/test/Plugin/Cachemanager/Ethna_Plugin_Cachemanager_Memcache_Test.php
new file mode 100644 (file)
index 0000000..c900573
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ *  Ethna_Plugin_Cachemanager_Memcache_Test.php
+ */
+
+/**
+ *  Ethna_Plugin_Cachemanager_Memcache クラスのテストケース
+ *
+ *  @access public
+ */
+class Ethna_Plugin_Cachemanager_Memcache_Test extends Ethna_UnitTestBase
+{
+
+    var $cm;
+
+    function setUp()
+    {
+        $ctl =& Ethna_Controller::getInstance();
+        $plugin =& $ctl->getPlugin();
+
+        $config = $ctl->getConfig();
+
+        $config->set('plugin',
+            array('cachemanager' => 
+                array('memcache' => array(
+                     'host' => 'localhost',
+                     'port' => 11211,
+                     'use_pconnect' => false,
+                     'retry' => 4,
+                     'timeout' => 5,
+
+                    //sample-2: multiple memcache servers (distributing w/ namespace and ids)
+                    'info' => array(
+                       'namespace1' => array(
+                           0 => array(
+                               'host' => 'cache1.example.com',
+                               'port' => 11211,
+                           ),
+                           1 => array(
+                               'host' => 'cache2.example.com',
+                               'port' => 11211,
+                           ),
+                       ),
+                    ),
+                )
+            )
+        ));
+
+        $this->cm = $plugin->getPlugin('Cachemanager', 'Memcache');
+    }
+
+    function testMemcacheConfig()
+    {
+        $config = $this->cm->config;
+
+        $this->assertTrue(11211, $config['port']);
+        $this->assertTrue('localhost', $config['host']);
+        $this->assertTrue(4, $config['retry']);
+        $this->assertTrue(5, $config['timeout']);
+    }
+}
+?>