Source for file Ethna_InfoManager.php
Documentation is available at Ethna_InfoManager.php
// vim: foldmethod=marker  
 *  @author     Masaki Fujimoto <fujimoto@php.net>  
 *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License  
 *  @author     Masaki Fujimoto <fujimoto@php.net>  
    /** @var    object  Ethna_Controller    コントローラオブジェクト */  
    /** @var    object  Ethna_ClassFactory  クラスファクトリオブジェクト */  
    /** @var    array   アクションスクリプト解析結果キャッシュファイル */  
    var $cache_class_list_file;  
    /** @var    array   アクションスクリプト解析結果キャッシュ */  
    /** @var    array   [属性]DBタイプ一覧 */  
    var $db_type_list = 
array(  
        DB_TYPE_RW      => 
array('name' => 
'DB_TYPE_RW'),  
        DB_TYPE_RO      => 
array('name' => 
'DB_TYPE_RO'),  
        DB_TYPE_MISC    => 
array('name' => 
'DB_TYPE_MISC'),  
    /** @var    array   [属性]フォーム型一覧 */  
    /** @var    array   [属性]変数型一覧 */  
     *  Ethna_InfoManagerのコンストラクタ  
     *  @param  object  Ethna_Backend   &$backend   Ethna_Backendオブジェクト  
        $this->form_type_list = 
array(  
        $this->var_type_list = 
array(  
        $this->cache_class_list_file = 
sprintf('%s/ethna_info_class_list',  
         && 
filesize($this->cache_class_list_file) > 
0) { 
            $fp = 
fopen($this->cache_class_list_file, 'r');  
        $class_list = 
$this->_analyzeActionList();  
        list
($manifest_action_list, $manifest_class_list) = 
$this->_getActionList_Manifest($class_list); 
        $implicit_action_list = 
$this->_getActionList_Implicit($class_list, $manifest_action_list, $manifest_class_list);  
        $r = 
array_merge($manifest_action_list, $implicit_action_list);  
        $r = 
$this->_addActionList($r);  
        $forward_list = 
$this->_analyzeForwardList();  
        $manifest_forward_list = 
$this->_getForwardList_Manifest();  
        $implicit_forward_list = 
$this->_getForwardList_Implicit($forward_list, $manifest_forward_list);  
        $r = 
array_merge($manifest_forward_list, $implicit_forward_list);  
     *  ディレクトリ以下のアクションスクリプトを解析する  
     *  @param  string  $action_dir     解析対象のディレクトリ  
     *  @return array   アクションクラス定義一覧  
    function _analyzeActionList($action_dir = 
null)  
        $child_dir_list = 
array();  
        $ext = 
$this->ctl->getExt('php');  
        while (($file = 
readdir($dh)) !== 
false) {  
            if ($file == 
"." || 
$file == 
"..") {  
            $file = 
$action_dir . 
$file;  
                $child_dir_list[] = 
$file;  
            $key = 
substr($file, $prefix_len);  
            if ($this->cache_class_list[$key]['.mtime'] >= 
filemtime($file)) {  
                $class_list = 
$this->cache_class_list[$key];  
                $class_list = 
$this->_analyzeActionScript($file);  
            if (is_null($class_list) == 
false) {  
        foreach ($child_dir_list as $child_dir) {  
            $tmp = 
$this->_analyzeActionList($child_dir . 
"/");  
            $fp = 
fopen($this->cache_class_list_file, 'w');  
     *  @param  string  $script ファイル名  
     *  @return array   アクションクラス定義一覧  
    function _analyzeActionScript($script)  
        $fp = 
fopen($script, 'r');  
        while (feof($fp) == 
false) {  
            $source .= 
fgets($fp, 8192);  
        for ($i = 
0; $i < 
count($token_list); $i++
) {  
            $token = 
$token_list[$i];  
                } else if ($token == 
'}') {  
                    if ($state == 
'T_PREPARE' || 
$state == 
'T_PERFORM') {  
                        if ($nest == 
$method_nest) {  
                            $state = 
'T_ACTION_CLASS';  
            if ($token[0] == 
T_CLASS) {  
                $class_name = 
$token_list[$i][1];       // should be T_STRING  
                if ($this->_isSubclassOf($class_name, 'Ethna_ActionClass')) {  
                    $state = 
'T_ACTION_CLASS';  
                    $class_list[$current] = 
array('type' => 
'action_class');  
                } else if ($this->_isSubclassOf($class_name, 'Ethna_ActionForm')) {  
                    $state = 
'T_ACTION_FORM';  
                    $class_list[$current] = 
array('type' => 
'action_form');  
            } else if ($token[0] == 
T_COMMENT && 
strncmp($token[1], "/**", 3) == 
0 && 
is_array($token_list[$i+
2]) && 
$token_list[$i+
2][0] == 
T_CLASS) {  
            } else if ($state == 
'T_ACTION_CLASS' && 
$token[0] == 
T_FUNCTION) {  
                $method_name = 
$token_list[$i][1];  
                } else if (strcasecmp($method_name, 'perform') == 
0) {  
            } else if (($state == 
'T_PREPARE' || 
$state == 
'T_PERFORM') && 
$token[0] == 
T_RETURN) {  
                while ($token_list[$i+
$n] !== 
";") {  
                    $s .= 
is_string($token_list[$i+
$n]) ? 
$token_list[$i+
$n] : 
$token_list[$i+
$n][1];  
                $key = 
$state == 
'T_PREPARE' ? 
'prepare' : 
'perform';  
                $class_list[$current]['return'][$key][] = 
$s;  
        if (count($class_list) == 
0) {  
     *  指定されたクラス名を継承しているかどうかを返す  
     *  @param  string  $class_name     チェック対象のクラス名  
     *  @param  string  $parent_name    親クラス名  
     *  @return bool    true:継承している false:いない  
    function _isSubclassOf($class_name, $parent_name)  
     *  コントローラに明示的に定義されているアクション一覧を取得する  
     *  @param  array   定義されているクラス一覧  
     *  @return array   array(アクション一覧, クラス一覧)  
    function _getActionList_Manifest($class_list)  
        $manifest_action_list = 
array();  
        $manifest_class_list = 
array();  
        foreach ($this->ctl->action as $action_name => 
$action) {  
            if ($action_name == 
'__ethna_info__') {  
            $action = 
$this->ctl->_getAction($action_name);  
            // _analyzeActionList()で取得したクラス定義データから対応関係を取得  
            foreach ($class_list as $file => 
$elts) {  
                foreach ($elts as $class_name => 
$def) {  
                    if ($def['type'] == 
'action_class' && 
strcasecmp($class_name, $action['class_name']) == 
0) {  
                        $elt['action_class'] = 
$class_name;  
                        $elt['action_class_file'] = 
$file;  
                        $elt['action_class_info'] = 
$def;  
                    } else if ($def['type'] == 
'action_form' && 
strcasecmp($class_name, $action['form_name']) == 
0) {  
                        $elt['action_form'] = 
$class_name;  
                        $elt['action_form_file'] = 
$file;  
                        $elt['action_form_info'] = 
$def;  
            if (isset
($elt['action_class']) == 
false) {  
                $elt['action_class'] = 
$action['class_name'];  
                    $elt['action_class_info'] = 
array('undef' => 
true);  
            if (isset
($elt['action_form']) == 
false && 
$action['form_name'] != 
'Ethna_ActionForm') {  
                $elt['action_form'] = 
$action['form_name'];  
                    $elt['action_form_info'] = 
array('undef' => 
true);  
            $manifest_action_list[$action_name] = 
$elt;  
            $manifest_class_list[] = 
strtolower($elt['action_class']);  
        return array($manifest_action_list, $manifest_class_list);  
     *  @param  array   $class_list             定義されているクラス一覧  
     *  @param  array   $manifest_action_list   明示的に定義済みのアクション一覧  
     *  @param  array   $manifest_class_list    明示的に定義済みのクラス一覧  
     *  @return array   array:アクション一覧  
    function _getActionList_Implicit($class_list, $manifest_action_list, $manifest_class_list)  
        $implicit_action_list = 
array();  
        foreach ($class_list as $file => 
$elts) {  
            foreach ($elts as $class_name => 
$def) {  
                if ($def['type'] == 
'action_class') {  
                    $implicit_action_list[$action_name]['action_class'] = 
$class_name;  
                    $implicit_action_list[$action_name]['action_class_file'] = 
$file;  
                    $implicit_action_list[$action_name]['action_class_info'] = 
$def;  
                } else if ($def['type'] == 
'action_form') {  
                    $implicit_action_list[$action_name]['action_form'] = 
$class_name;  
                    $implicit_action_list[$action_name]['action_form_file'] = 
$file;  
                    $implicit_action_list[$action_name]['action_form_info'] = 
$def;  
        return $implicit_action_list;  
     *  @param  array   $action_list    取得したアクション一覧  
     *  @return array   修正後のアクション一覧  
    function _addActionList($action_list)  
        foreach ($action_list as $action_name => 
$action) {  
            $form_name = 
$action['action_form'];  
            $af =
& new $form_name($this->ctl);  
            foreach ($af->getDef() as $name => 
$def) {  
                $form[$name]['required'] = 
$def['required'] ? 
'true' : 
'false';  
                foreach (array('name', 'max', 'min', 'regexp', 'custom') as $key) {  
                    $form[$name][$key] = 
$def[$key];  
                $form[$name]['filter'] = 
str_replace(",", "\n", $def['filter']);  
                $form[$name]['form_type'] = 
$this->getAttrName('form_type', $def['form_type']);  
                $form[$name]['type_is_array'] = 
is_array($def['type']);  
                                     ? 
$def['type'][0] : 
$def['type']); 
            $action['action_form_info']['form'] = 
$form;  
            $action_list[$action_name] = 
$action;  
     *  @param  string  $action_dir     解析対象のディレクトリ  
    function _analyzeForwardList($template_dir = 
null)  
        $child_dir_list = 
array();  
        $ext = 
$this->ctl->getExt('tpl');  
        while (($file = 
readdir($dh)) !== 
false) {  
            if ($file == 
"." || 
$file == 
"..") {  
            $file = 
$template_dir . 
'/' . 
$file;  
                $child_dir_list[] = 
$file;  
            $tpl = 
substr($file, $prefix_len);  
        foreach ($child_dir_list as $child_dir) {  
            $tmp = 
$this->_analyzeForwardList($child_dir);  
     *  コントローラに明示的に定義されている遷移先一覧を取得する  
    function _getForwardList_Manifest()  
        $manifest_forward_list = 
array();  
        foreach ($this->ctl->forward as $forward_name => 
$forward) {  
            if ($forward_name == 
'__ethna_info__') {  
            $elt['template_file'] = 
$this->ctl->_getForwardPath($forward_name);  
                $elt['template_file_info'] = 
array('undef' => 
true);  
            if ($elt['view_class'] == 
'Ethna_ViewClass') {  
                $elt['view_class'] = 
null;  
                $elt['view_class_info'] = 
array('undef' => 
true);  
            if (isset
($forward['view_path']) && 
$forward['view_path']) {  
                $elt['view_path'] = 
$forward['view_path'];  
            } else if ($this->_isSubclassOf($elt['view_class'], 'Ethna_ViewClass')) {  
                foreach ($this->cache_class_list as $file => 
$elts) {  
                    foreach ($elts as $name => 
$def) {  
                            $elt['view_class_file'] = 
$file;  
            $manifest_forward_list[$forward_name] = 
$elt;  
        return $manifest_forward_list;  
     *  @param  array   $forward_list           定義されている遷移名一覧  
     *  @param  array   $manifest_forward_list  明示的に定義済みのビュー一覧  
     *  @return array   array:ビュー一覧  
    function _getForwardList_Implicit($forward_list, $manifest_forward_list)  
        $implicit_forward_list = 
array();  
        $manifest_forward_name_list = 
array_keys($manifest_forward_list);  
        foreach ($forward_list as $forward_name) {  
            if (in_array($forward_name, $manifest_forward_name_list)) {  
            $elt['template_file'] = 
$this->ctl->_getForwardPath($forward_name);  
            if ($elt['view_class'] == 
'Ethna_ViewClass') {  
                $elt['view_class'] = 
null;  
                $elt['view_class'] = 
null;  
            $implicit_forward_list[$forward_name] = 
$elt;  
        return $implicit_forward_list;  
     *  @return array   設定一覧を格納した配列  
     *  @todo   respect access controll  
        $elts[_et('Application URL')] = 
$this->ctl->getURL();  
        $r[_et('Class')] = 
$elts;  
        foreach ($this->ctl->db as $key => 
$db) {  
        $r[_et('DB Type')] = 
$elts;  
        foreach ($db_list as $key => 
$name) {  
            $dsn = 
$this->config->get($config_key);  
        $r[_et('Directory')] = 
$elts;  
        $elts[_et('Template')] = 
$this->ctl->getExt('tpl');  
        $elts[_et('PHP Script')] = 
$this->ctl->getExt('php');  
        $r[_et('File Extention')] = 
$elts;  
        foreach ($this->ctl->filter as $filter) {  
        $r[_et('Filter')] = 
$elts;  
        $r[_et('Application Manager')] = 
$elts;  
     *  @return array   設定一覧を格納した配列  
     *  @todo   respect access controll  
        foreach ($plugin->searchAllPluginType() as $type) {  
            $plugin->searchAllPluginSrc($type);  
            if (isset
($plugin->src_registry[$type])) {  
                foreach ($plugin->src_registry[$type] as $name => 
$src) {  
 
 
	
		Documentation generated on Fri, 11 Nov 2011 03:59:51 +0900 by phpDocumentor 1.4.3