- Ethna_Plugin::import という,プラグインソースをincludeするための,staticメソッドを追加.
- すべてのPluginの基底となる抽象クラス,Ethna_Plugin_Abstractを追加
-- 既存のプラグインの親クラスを,Ethna_Plugin_Abstract を継承するように変更
+-- Plugin に設定を受け渡す方法を変更したため,etcのskelを変更
+--- それに伴い,Ethna_Plugin_Cachemanager_Memcacheの設定方法を変更
*** bug fix
$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
$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;
}
*
* @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;
*
* @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;
/*
function Ethna_Plugin_Cachemanager(&$controller)
{
- $this->controller =& $controller;
- $this->backend =& $this->controller->getBackend();
- $this->config =& $this->controller->getConfig();
+ parent::Ethna_Plugin_Abstract($controller);
}
*/
$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,
+ // // ),
+ // // ),
+ // //),
+ //),
),
);
?>
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());
}
}
?>
--- /dev/null
+<?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']);
+ }
+}
+?>