Source for file Ethna_Plugin.php
Documentation is available at Ethna_Plugin.php
// vim: foldmethod=marker
* @author ICHII Takashi <ichii386@schweetheart.jp>
* @author Kazuhiro Hosoi <hosoi@gree.co.jp>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @author ICHII Takashi <ichii386@schweetheart.jp>
* @author Kazuhiro Hosoi <hosoi@gree.co.jp>
/** @var object Ethna_Controller コントローラオブジェクト */
/** @var object Ethna_Controller コントローラオブジェクト($controllerの省略形) */
/** @var object Ethna_Logger ログオブジェクト */
/** @var array プラグインのオブジェクト(インスタンス)を保存する配列 */
var $obj_registry =
array();
/** @var array プラグインのクラス名、ソースファイル名を保存する配列 */
var $src_registry =
array();
/** @var array 検索対象となるプラグインのアプリケーションIDのリスト */
* @param object Ethna_Controller $controller コントローラオブジェクト
$this->controller =
& $controller;
$this->ctl =
& $this->controller;
if (isset
($this->controller->plugin_search_appids)
&&
is_array($this->controller->plugin_search_appids)) {
$this->appid_list =
& $this->controller->plugin_search_appids;
$this->appid_list =
array($this->controller->getAppId(), 'Ethna');
* LogWriterはpluginなので、pluginインスタンス作成時点では
* @param object Ethna_Logger $logger ログオブジェクト
if ($this->logger ===
null &&
is_object($logger)) {
$this->logger =
& $logger;
* @param string $type プラグインの種類
* @param string $name プラグインの名前
* @return object プラグインのインスタンス
return $this->_getPlugin($type, $name);
* ある種類 ($type) のプラグイン ($name) の全リストを取得
* @param string $type プラグインの種類
* @return array プラグインオブジェクトの配列
if (isset
($this->src_registry[$type]) ==
false) {
foreach ($this->src_registry[$type] as $name =>
$value) {
$plugin_list[$name] =
& $this->getPlugin($type, $name);
// {{{ obj_registry のアクセサ
* @param string $type プラグインの種類
* @param string $name プラグインの名前
* @return object プラグインのインスタンス
function &_getPlugin($type, $name)
if (isset
($this->obj_registry[$type]) ==
false) {
$this->obj_registry[$type] =
array();
// プラグインの親クラスを(存在すれば)読み込み
foreach ($this->appid_list as $appid) {
$this->_includePluginSrc($class, $dir, $file, true);
$this->_loadPlugin($type, $name);
if (is_null($this->obj_registry[$type][$name])) {
return $this->obj_registry[$type][$name];
* プラグインをincludeしてnewし,レジストリに登録
* @param string $type プラグインの種類
* @param string $name プラグインの名前
function _loadPlugin($type, $name)
$plugin_src =
$this->_getPluginSrc($type, $name);
$this->obj_registry[$type][$name] =
null;
list
($plugin_class, $plugin_dir, $plugin_file) =
$plugin_src;
$r =
& $this->_includePluginSrc($plugin_class, $plugin_dir, $plugin_file);
$this->obj_registry[$type][$name] =
null;
$instance =
& new $plugin_class($this->controller, $type, $name);
$this->logger->log(LOG_WARNING, 'plugin [%s::%s] instantiation failed', $type, $name);
$this->obj_registry[$type][$name] =
null;
$this->obj_registry[$type][$name] =
& $instance;
* @param string $type プラグインの種類
* @param string $name プラグインの名前
function _unloadPlugin($type, $name)
unset
($this->obj_registry[$type][$name]);
// {{{ src_registry のアクセサ
* プラグインのソースファイル名とクラス名をレジストリから取得
* @param string $type プラグインの種類
* @param string $name プラグインの名前
* @return array ソースファイル名とクラス名からなる配列
function _getPluginSrc($type, $name)
if (isset
($this->src_registry[$type]) ==
false) {
$this->src_registry[$type] =
array();
$this->_searchPluginSrc($type, $name);
return $this->src_registry[$type][$name];
* プラグインのクラス名、ディレクトリ、ファイル名を決定
* @param string $type プラグインの種類
* @param string $name プラグインの名前 (nullのときは親クラス)
* @param string $appid アプリケーションID
* @return array プラグインのクラス名、ディレクトリ、ファイル名の配列
* @todo class factoryのnaming ruleと整合させる
$class =
"Ethna_Plugin_{$type}";
$class =
"Ethna_Plugin_{$type}_{$name}";
$ext =
$this->controller->getExt('php');
$class =
"{
$appid}_Plugin_{
$type}";
$ext =
$this->controller->getExt('php');
$dir =
$this->controller->getDirectory('plugin') .
"/{$type}";
$class =
"{
$appid}_Plugin_{
$type}_{
$name}";
$file =
"{
$class}.{
$ext}";
return array($class, $dir, $file);
* @param string $class クラス名
* @param string $dir ディレクトリ名
* @param string $file ファイル名
* @param bool $parent 親クラスかどうかのフラグ
* @return true|Ethna_Error
function &_includePluginSrc($class, $dir, $file, $parent =
false)
$file =
$dir .
'/' .
$file;
$this->logger->log(LOG_DEBUG, 'plugin class [%s] is defined', $class);
* アプリケーション, Ethna の順でプラグインのソースを検索する
* @param string $type プラグインの種類
* @param string $name プラグインの名前
function _searchPluginSrc($type, $name)
// コントローラで指定されたアプリケーションIDの順に検索
foreach ($this->appid_list as $appid) {
if (isset
($this->src_registry[$type]) ==
false) {
$this->src_registry[$type] =
array();
$this->src_registry[$type][$name] =
array($class, null, null);
$this->logger->log(LOG_DEBUG, 'plugin file is found in search: [%s]',
if (isset
($this->src_registry[$type]) ==
false) {
$this->src_registry[$type] =
array();
$this->src_registry[$type][$name] =
array($class, $dir, $file);
// 見つからなかった場合 (nullで記憶しておく)
$this->logger->log(LOG_WARNING, 'plugin file for [type=%s, name=%s] is not found in search', $type, $name);
$this->src_registry[$type][$name] =
null;
* プラグインの種類 ($type) をすべて検索する
while (($type_dir =
readdir($dh)) !==
false) {
if ($type_dir{0} !=
'.' &&
is_dir("{
$dir}/{
$type_dir}")) {
$type_list[$type_dir] =
0;
* 指定された $type のプラグイン (のソース) をすべて検索する
* @param string $type プラグインの種類
// 後で見付かったもので上書きするので $this->appid_list の逆順とする
// クラス名として許可された文字であればOKとする
// アンダーバーを拒む理由はないし、命名規約からも禁止されていない
// @see http://ethna.jp/ethna-document-dev_guide-plugin.html
// @see http://www.php.net/manual/en/language.variables.php
list
($class_regexp, $dir, $file_regexp) =
$this->getPluginNaming($type, '([a-zA-Z0-9_\x7f-\xff]+)', $appid);
$this->logger->log(LOG_DEBUG, 'cannot open plugin directory: [%s]', $dir);
$this->logger->log(LOG_DEBUG, 'plugin directory opened: [%s]', $dir);
while (($file =
readdir($dh)) !==
false) {
if (preg_match('#^'.
$file_regexp.
'$#', $file, $matches)
$name_list[$matches[1]] =
true;
$this->_searchPluginSrc($type, $name);
// {{{ static な include メソッド
* Ethna 本体付属のプラグインのソースを include する
* @param string $type プラグインの種類
* @param string $name プラグインの名前
* @param string $type プラグインの種類
* @param string $name プラグインの名前
* @param string $appid アプリケーションID
$plugin =
& $ctl->getPlugin();
$appid =
$ctl->getAppId();
list
($class, $dir, $file) =
$plugin->getPluginNaming($type, $name, $appid);
$plugin->_includePluginSrc($class, $dir, $file);
Documentation generated on Fri, 11 Nov 2011 04:00:02 +0900 by phpDocumentor 1.4.3