2 // vim: foldmethod=marker
6 * @author Masaki Fujimoto <fujimoto@php.net>
7 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
14 * ¥³¥ó¥È¥í¡¼¥é¥ª¥Ö¥¸¥§¥¯¥È¤ò¼èÆÀ¤¹¤ë
17 * @return object ¥³¥ó¥È¥í¡¼¥é¥ª¥Ö¥¸¥§¥¯¥È
19 function &getController()
21 $controller =& $GLOBALS['controller'];
26 // {{{ Ethna_Controller
30 * @author Masaki Fujimoto <fujimoto@php.net>
34 class Ethna_Controller
41 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID
43 var $appid = 'PHPSTRUTS';
46 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê
51 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL
56 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥óDSN(Data Source Name)
61 * @var array ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
63 var $directory = array(
64 'action' => 'app/action',
69 'template' => 'template',
70 'template_c' => 'tmp',
76 * @var array DB¥¢¥¯¥»¥¹ÄêµÁ
83 * @var array ³ÈÄ¥»ÒÀßÄê
91 * @var array ¥¯¥é¥¹ÀßÄê
94 'config' => 'Ethna_Config',
96 'logger' => 'Ethna_Logger',
97 'sql' => 'Ethna_AppSQL',
101 * @var string »ÈÍѸÀ¸ìÀßÄê
106 * @var string ¥·¥¹¥Æ¥à¦¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
108 var $system_encoding;
111 * @var string ¥¯¥é¥¤¥¢¥ó¥È¦¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
113 var $client_encoding;
116 * @var string ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×
121 * @var string ¸½ºß¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾
126 * @var array forwardÄêµÁ
128 var $forward = array();
131 * @var array actionÄêµÁ
133 var $action = array();
136 * @var array soap actionÄêµÁ
138 var $soap_action = array();
141 * @var array ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Þ¥Í¡¼¥¸¥ãÄêµÁ
143 var $manager = array();
146 * @var array smarty modifierÄêµÁ
148 var $smarty_modifier_plugin = array();
151 * @var array smarty functionÄêµÁ
153 var $smarty_function_plugin = array();
156 * @var array smarty prefilterÄêµÁ
158 var $smarty_prefilter_plugin = array();
161 * @var array smarty postfilterÄêµÁ
163 var $smarty_postfilter_plugin = array();
166 * @var array smarty outputfilterÄêµÁ
168 var $smarty_outputfilter_plugin = array();
171 * @var object Ethna_Backend backend¥ª¥Ö¥¸¥§¥¯¥È
176 * @var object Ethna_I18N i18n¥ª¥Ö¥¸¥§¥¯¥È
181 * @var object Ethna_ActionError action error¥ª¥Ö¥¸¥§¥¯¥È
183 var $action_error = null;
186 * @var object Ethna_ActionForm action form¥ª¥Ö¥¸¥§¥¯¥È
188 var $action_form = null;
191 * @var object Ethna_Session ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È
196 * @var object Ethna_Config ÀßÄꥪ¥Ö¥¸¥§¥¯¥È
201 * @var object Ethna_Logger ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È
206 * @var object Ethna_AppSQL SQL¥ª¥Ö¥¸¥§¥¯¥È
214 * Ethna_Controller¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
218 function Ethna_Controller()
220 $GLOBALS['controller'] =& $this;
223 // ¥¨¥é¡¼¥Ï¥ó¥É¥é¤ÎÀßÄê
224 Ethna::setErrorCallback(array(&$this, 'handleError'));
226 // ¥Ç¥£¥ì¥¯¥È¥ê̾¤ÎÀßÄê(ÁêÂХѥ¹->ÀäÂХѥ¹)
227 foreach ($this->directory as $key => $value) {
228 if ($key == 'plugins') {
229 // Smarty¥×¥é¥°¥¤¥ó¥Ç¥£¥ì¥¯¥È¥ê¤ÏÇÛÎó¤Ç»ØÄꤹ¤ë
230 $tmp = array(SMARTY_DIR . 'plugins');
231 foreach (to_array($value) as $elt) {
232 if ($elt{0} != '/') {
233 $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt;
236 $this->directory[$key] = $tmp;
238 if ($value{0} != '/') {
239 $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value;
243 $this->i18n =& new Ethna_I18N($this->getDirectory('locale'), $this->getAppId());
244 list($this->language, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage();
245 $this->client_type = $this->_getDefaultClientType();
247 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
248 $config_class = $this->class['config'];
249 $this->config =& new $config_class($this);
250 $this->dsn = $this->_prepareDSN();
251 $this->url = $this->config->get('url');
254 $logger_class = $this->class['logger'];
255 $this->logger =& new $logger_class($this);
256 $this->logger->begin();
258 // SQL¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®
259 $sql_class = $this->class['sql'];
260 $this->sql =& new $sql_class($this);
262 // Ethna¥Þ¥Í¡¼¥¸¥ãÀßÄê
263 $this->_activateEthnaManager();
267 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID¤òÊÖ¤¹
270 * @return string ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID
274 return ucfirst(strtolower($this->appid));
281 * @param string $type DB¼ïÊÌ
284 function getDSN($type = "")
286 if (isset($this->dsn[$type]) == false) {
289 return $this->dsn[$type];
293 * DSN¤Î»ý³ÀܳÀßÄê¤òÊÖ¤¹
296 * @param string $type DB¼ïÊÌ
297 * @return bool true:persistent false:non-persistent(¤¢¤ë¤¤¤ÏÀßÄê̵¤·)
299 function getDSN_persistent($type = "")
301 $key = sprintf("dsn%s_persistent", $type == "" ? "" : "_$type");
302 $dsn_persistent = $this->config->get($key);
303 if (is_null($dsn_persistent)) {
306 return $dsn_persistent;
310 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL¤òÊÖ¤¹
313 * @return string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL
321 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê¤òÊÖ¤¹
324 * @return string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê
326 function getBasedir()
332 * ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×/¸À¸ì¤«¤é¥Æ¥ó¥×¥ì¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
335 * @return string ¥Æ¥ó¥×¥ì¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê
337 function getTemplatedir()
339 $template = $this->getDirectory('template');
341 // ¸À¸ìÊ̥ǥ£¥ì¥¯¥È¥ê
342 if (file_exists($template . '/' . $this->language)) {
343 $template .= '/' . $this->language;
346 // ¥¯¥é¥¤¥¢¥ó¥ÈÊ̥ǥ£¥ì¥¯¥È¥ê(if we need)
347 if ($this->client_type == CLIENT_TYPE_MOBILE_AU && file_exists($template . '/au')) {
355 * ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
358 * @return string ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
360 function getActiondir()
362 return (empty($this->directory['action']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['action'] . "/"));
366 * ¥Ó¥å¡¼¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
369 * @return string ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
371 function getViewdir()
373 return (empty($this->directory['view']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['view'] . "/"));
377 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥¯¥é¥¹ÀßÄê¤òÊÖ¤¹
380 * @param string $key ¥¯¥é¥¹¥¿¥¤¥×("config", "db", "logger", "sql")
381 * @return string $key¤ËÂбþ¤·¤¿¥¯¥é¥¹Ì¾(ÀßÄ꤬¤Ê¤¤¾ì¹ç¤Ïnull)
383 function getClass($key)
385 if (isset($this->class[$key]) == false) {
388 return $this->class[$key];
392 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥êÀßÄê¤òÊÖ¤¹
395 * @param string $key ¥Ç¥£¥ì¥¯¥È¥ê¥¿¥¤¥×("tmp", "template"...)
396 * @return string $key¤ËÂбþ¤·¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
398 function getDirectory($key)
400 if (isset($this->directory[$key]) == false) {
403 return $this->directory[$key];
410 * @param string $key DB¥¿¥¤¥×("r", ...)
411 * @return string $key¤ËÂбþ¤¹¤ëDB¼ïÊÌÄêµÁ(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
415 if (isset($this->db[$key]) == false) {
418 return $this->db[$key];
422 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó³ÈÄ¥»ÒÀßÄê¤òÊÖ¤¹
425 * @param string $key ³ÈÄ¥»Ò¥¿¥¤¥×("php", "tpl"...)
426 * @return string $key¤ËÂбþ¤·¤¿³ÈÄ¥»Ò(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
428 function getExt($key)
430 if (isset($this->ext[$key]) == false) {
433 return $this->ext[$key];
437 * i18n¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ(R)
440 * @return object Ethna_I18N i18n¥ª¥Ö¥¸¥§¥¯¥È
448 * ÀßÄꥪ¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
451 * @return object Ethna_Config ÀßÄꥪ¥Ö¥¸¥§¥¯¥È
453 function &getConfig()
455 return $this->config;
459 * backend¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
462 * @return object Ethna_Backend backend¥ª¥Ö¥¸¥§¥¯¥È
464 function &getBackend()
466 return $this->backend;
470 * action error¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
473 * @return object Ethna_ActionError action error¥ª¥Ö¥¸¥§¥¯¥È
475 function &getActionError()
477 return $this->action_error;
481 * action form¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
484 * @return object Ethna_ActionForm action form¥ª¥Ö¥¸¥§¥¯¥È
486 function &getActionForm()
488 return $this->action_form;
492 * ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
495 * @return object Ethna_Session ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È
497 function &getSession()
499 return $this->session;
503 * ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
506 * @return object Ethna_Logger ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È
508 function &getLogger()
510 return $this->logger;
514 * SQL¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
517 * @return object Ethna_AppSQL SQL¥ª¥Ö¥¸¥§¥¯¥È
525 * ¥Þ¥Í¡¼¥¸¥ã°ìÍ÷¤òÊÖ¤¹
528 * @return array ¥Þ¥Í¡¼¥¸¥ã°ìÍ÷
530 function getManagerList()
532 return $this->manager;
536 * ¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
539 * @return string ¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾
541 function getCurrentActionName()
543 return $this->action_name;
550 * @return array »ÈÍѸÀ¸ì,¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾,¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
552 function getLanguage()
554 return array($this->language, $this->system_encoding, $this->client_encoding);
558 * ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤ò¼èÆÀ¤¹¤ë
561 * @return int ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
563 function getClientType()
565 return $this->client_type;
569 * ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤òÀßÄꤹ¤ë
572 * @param int $client_type ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
574 function setClientType($client_type)
576 $this->client_type = $client_type;
580 * ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¼èÆÀ¤¹¤ë(¸½ºß¤Ïsmarty¤Î¤ßÂбþ)
583 * @return object Smarty ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¥ª¥Ö¥¸¥§¥¯¥È
584 * @todo ¥Ö¥í¥Ã¥¯´Ø¿ô¥×¥é¥°¥¤¥ó(etc)Âбþ
586 function &getTemplateEngine()
588 $smarty =& new Smarty();
589 $smarty->template_dir = $this->getTemplatedir();
590 $smarty->compile_dir = $this->getDirectory('template_c') . '/tpl_' . md5($smarty->template_dir);
591 if (@is_dir($smarty->compile_dir) == false) {
592 mkdir($smarty->compile_dir, 0755);
594 $smarty->plugins_dir = $this->getDirectory('plugins');
597 $smarty->register_modifier('number_format', 'smarty_modifier_number_format');
598 $smarty->register_modifier('strftime', 'smarty_modifier_strftime');
599 $smarty->register_modifier('count', 'smarty_modifier_count');
600 $smarty->register_modifier('join', 'smarty_modifier_join');
601 $smarty->register_modifier('filter', 'smarty_modifier_filter');
602 $smarty->register_modifier('unique', 'smarty_modifier_unique');
603 $smarty->register_modifier('wordwrap_i18n', 'smarty_modifier_wordwrap_i18n');
604 $smarty->register_modifier('i18n', 'smarty_modifier_i18n');
605 $smarty->register_modifier('checkbox', 'smarty_modifier_checkbox');
606 $smarty->register_modifier('select', 'smarty_modifier_select');
607 $smarty->register_modifier('form_value', 'smarty_modifier_form_value');
609 // user defined modifiers
610 foreach ($this->smarty_modifier_plugin as $modifier) {
611 $name = str_replace('smarty_modifier_', '', $modifier);
612 $smarty->register_modifier($name, $modifier);
616 $smarty->register_function('message', 'smarty_function_message');
617 $smarty->register_function('uniqid', 'smarty_function_uniqid');
618 $smarty->register_function('select', 'smarty_function_select');
619 $smarty->register_function('checkbox_list', 'smarty_function_checkbox_list');
621 // user defined functions
622 foreach ($this->smarty_function_plugin as $function) {
623 $name = str_replace('smarty_function_', '', $function);
624 $smarty->register_function($name, $function);
627 // user defined prefilters
628 foreach ($this->smarty_prefilter_plugin as $prefilter) {
629 $smarty->register_prefilter($prefilter);
632 // user defined postfilters
633 foreach ($this->smarty_postfilter_plugin as $postfilter) {
634 $smarty->register_postfilter($postfilter);
637 // user defined outputfilters
638 foreach ($this->smarty_outputfilter_plugin as $outputfilter) {
639 $smarty->register_outputfilter($outputfilter);
646 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
649 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
650 * @param mixed $action_name »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾(¾Êά²Ä)
651 * @param mixed $fallback_action_name ¥¢¥¯¥·¥ç¥ó¤¬·èÄê¤Ç¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾(¾Êά²Ä)
654 function main($class_name, $action_name = "", $fallback_action_name = "")
656 $c =& new $class_name;
657 $c->trigger($action_name, $fallback_action_name);
661 * ¥³¥Þ¥ó¥É¥é¥¤¥ó¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
664 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
665 * @param string $action_name ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾
668 function main_CLI($class_name, $action_name)
670 $c =& new $class_name;
671 $c->action[$action_name] = array();
672 $c->trigger($action_name);
676 * SOAP¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
679 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
682 function main_SOAP($class_name)
684 $c =& new $class_name;
685 $c->setClientType(CLIENT_TYPE_SOAP);
690 * AMF(Flash Remoting)¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
693 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
696 function main_AMF($class_name)
698 $c =& new $class_name;
699 $c->setClientType(CLIENT_TYPE_AMF);
704 * ¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò³«»Ï¤¹¤ë
706 * °ú¿ô$default_action_name¤ËÇÛÎ󤬻ØÄꤵ¤ì¤¿¾ì¹ç¡¢¤½¤ÎÇÛÎó¤Ç»ØÄꤵ¤ì¤¿
707 * ¥¢¥¯¥·¥ç¥ó°Ê³°¤Ï¼õ¤±ÉÕ¤±¤Ê¤¤(¤½¤ì°Ê³°¤Î¥¢¥¯¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
708 * ÇÛÎó¤ÎÀèƬ¤Ç»ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤¬¼Â¹Ô¤µ¤ì¤ë)
711 * @param mixed $default_action_name »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾
712 * @param mixed $fallback_action_name ¥¢¥¯¥·¥ç¥ó̾¤¬·èÄê¤Ç¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾
713 * @return mixed 0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
715 function trigger($default_action_name = "", $fallback_action_name = "")
717 // ¥¢¥¯¥·¥ç¥ó̾¤Î¼èÆÀ
718 $action_name = $this->_getActionName($default_action_name, $fallback_action_name);
720 // ¥¢¥¯¥·¥ç¥óÄêµÁ¤Î¼èÆÀ
721 $action_obj =& $this->_getAction($action_name);
722 if (is_null($action_obj)) {
723 if ($fallback_action_name != "") {
724 $this->logger->log(LOG_DEBUG, 'undefined action [%s] -> try fallback action [%s]', $action_name, $fallback_action_name);
725 $action_obj =& $this->_getAction($fallback_action_name);
727 if ($action_obj == null) {
728 return Ethna::raiseError(E_APP_UNDEFINED_ACTION, "undefined action [%s]", $action_name);
730 $action_name = $fallback_action_name;
733 $this->action_name = $action_name;
736 $this->_setLanguage($this->language, $this->system_encoding, $this->client_encoding);
739 $this->action_error =& new Ethna_ActionError();
740 $form_name = $this->getActionFormName($action_name);
741 $this->action_form =& new $form_name($this);
742 $this->session =& new Ethna_Session($this->getAppId(), $this->getDirectory('tmp'), $this->logger);
744 // ¥Ð¥Ã¥¯¥¨¥ó¥É½èÍý¼Â¹Ô
745 $backend =& new Ethna_Backend($this);
746 $this->backend =& $backend;
747 $forward_name = $backend->perform($action_name);
749 // ¥³¥ó¥È¥í¡¼¥é¤ÇÁ«°ÜÀè¤ò·èÄꤹ¤ë
750 $forward_name = $this->_sortForward($action_name, $forward_name);
752 if ($forward_name != null) {
753 $backend->preforward($forward_name);
755 if ($this->_forward($forward_name) != 0) {
764 * SOAP¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò³«»Ï¤¹¤ë
768 function trigger_SOAP()
770 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É
771 $this->_includeActionScript();
773 // SOAP¥¨¥ó¥È¥ê¥¯¥é¥¹
774 $gg =& new Ethna_SoapGatewayGenerator();
775 $script = $gg->generate();
778 // SOAP¥ê¥¯¥¨¥¹¥È½èÍý
779 $server =& new SoapServer(null, array('uri' => $this->config->get('url')));
780 $server->setClass($gg->getClassName());
785 * AMF(Flash Remoting)¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò³«»Ï¤¹¤ë
789 function trigger_AMF()
791 include_once('ethna/contrib/amfphp/app/Gateway.php');
793 $this->action_error =& new Ethna_ActionError();
795 // Credential¥Ø¥Ã¥À¤Ç¥»¥Ã¥·¥ç¥ó¤ò½èÍý¤¹¤ë¤Î¤Ç¤³¤³¤Ç¤Ïnull¤ËÀßÄê
796 $this->session = null;
798 $this->_setLanguage($this->language, $this->system_encoding, $this->client_encoding);
800 // backend¥ª¥Ö¥¸¥§¥¯¥È
801 $backend =& new Ethna_Backend($this);
802 $this->backend =& $backend;
804 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É
805 $this->_includeActionScript();
807 // amfphp¤Ë½èÍý¤ò°Ñ¾ù
808 $gateway =& new Gateway();
809 $gateway->setBaseClassPath('');
816 * ¥¨¥é¡¼È¯À¸»þ¤ÎÄɲýèÍý¤ò¹Ô¤¤¤¿¤¤¾ì¹ç¤Ï¤³¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹
817 * (¥¢¥é¡¼¥È¥á¡¼¥ëÁ÷¿®Åù¡Ý¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¥í¥°½ÐÎÏ»þ¤Ë¥¢¥é¡¼¥È¥á¡¼¥ë
818 * ¤¬Á÷¿®¤µ¤ì¤ë¤¬¡¢¥¨¥é¡¼È¯À¸»þ¤ËÊ̤˥¢¥é¡¼¥È¥á¡¼¥ë¤ò¤³¤³¤ÇÁ÷¿®
822 * @param object Ethna_Error ¥¨¥é¡¼¥ª¥Ö¥¸¥§¥¯¥È
824 function handleError(&$error)
827 list ($log_level, $dummy) = $this->logger->errorLevelToLogLevel($error->getLevel());
828 $message = $error->getMessage();
829 $this->logger->log($log_level, sprintf("[APP(%d)] %s", $error->getCode(), $message));
833 * ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ò¼èÆÀ¤¹¤ë
836 * @param int $code ¥¨¥é¡¼¥³¡¼¥É
837 * @return string ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
839 function getErrorMessage($code)
841 $message_list =& $GLOBALS['_Ethna_error_message_list'];
842 for ($i = count($message_list)-1; $i >= 0; $i--) {
843 if (array_key_exists($code, $message_list[$i])) {
844 return $message_list[$i][$code];
851 * »ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Î¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
854 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
855 * @return string ¥¢¥¯¥·¥ç¥ó¤Î¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾
857 function getActionFormName($action_name)
859 $action_obj =& $this->_getAction($action_name);
860 if (is_null($action_obj)) {
864 return $action_obj['form_name'];
868 * »ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Î¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
871 * @param string $action_name ¥¢¥¯¥·¥ç¥ó¤Î̾¾Î
872 * @return string ¥¢¥¯¥·¥ç¥ó¤Î¥¯¥é¥¹Ì¾
874 function getActionClassName($action_name)
876 $action_obj =& $this->_getAction($action_name);
877 if ($action_obj == null) {
881 return $action_obj['class_name'];
885 * »ØÄꤵ¤ì¤¿Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
887 * ¥Ó¥å¡¼¥¯¥é¥¹¤ÏAction Class¤Ëpreforward()¥á¥½¥Ã¥É¤ò¼ÂÁõ¤·¤¿¤â¤Î(Èó¿ä¾©)¡¢
888 * ¤¢¤ë¤¤¤ÏViewClass¤ò·Ñ¾µ¤·¤¿¤â¤Î¤¤¤º¤ì¤«¤É¤Á¤é¤Ç¤â¤è¤¤(ViewClass¿ä¾©)
891 * @param string $forward_name Á«°ÜÀè¤Î̾¾Î
892 * @return string view class¤Î¥¯¥é¥¹Ì¾
894 function getViewClassName($forward_name)
896 if ($forward_name == null) {
900 if (isset($this->forward[$forward_name])) {
901 $forward_obj = $this->forward[$forward_name];
903 $forward_obj = array();
906 if (isset($forward_obj['preforward_name'])) {
907 $class_name = $forward_obj['preforward_name'];
908 if (class_exists($class_name)) {
915 // view¤Î¥¤¥ó¥¯¥ë¡¼¥É
916 $this->_includeViewScript($forward_obj, $forward_name);
918 if (is_null($class_name) == false && class_exists($class_name)) {
920 } else if (is_null($class_name) == false) {
921 $this->logger->log(LOG_WARNING, 'stated preforward class is not defined [%s] -> try default', $class_name);
924 $class_name = $this->getDefaultViewClass($forward_name);
925 if (class_exists($class_name)) {
933 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
935 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_Form_[¥¢¥¯¥·¥ç¥ó̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
938 * @param string $action_name action̾
939 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
940 * @return string action form¥¯¥é¥¹Ì¾
942 function getDefaultFormClass($action_name, $fallback = true)
944 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
947 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
948 $r = sprintf("%s_SOAPForm_%s", $this->getAppId(), $postfix);
949 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
950 $tmp = sprintf("%s_MobileAUForm_%s", $this->getAppId(), $postfix);
951 if ($fallback == false || class_exists($tmp)) {
957 $r = sprintf("%s_Form_%s", $this->getAppId(), $postfix);
959 $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
964 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥Õ¥©¡¼¥à¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
966 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï_getDefaultActionPath()¤ÈƱ¤¸·ë²Ì¤òÊÖ¤¹(1¥Õ¥¡¥¤¥ë¤Ë
967 * ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤È¥Õ¥©¡¼¥à¥¯¥é¥¹¤¬µ½Ò¤µ¤ì¤ë)¤Î¤Ç¡¢¹¥¤ß¤Ë±þ¤¸¤Æ
971 * @param string $action_name action̾
972 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
973 * @return string form class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
975 function getDefaultFormPath($action_name, $fallback = true)
977 return $this->getDefaultActionPath($action_name, $fallback);
981 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
983 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_Action_[¥¢¥¯¥·¥ç¥ó̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
986 * @param string $action_name action̾
987 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
988 * @return string action class¥¯¥é¥¹Ì¾
990 function getDefaultActionClass($action_name, $fallback = true)
992 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
995 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
996 $r = sprintf("%s_SOAPAction_%s", $this->getAppId(), $postfix);
997 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
998 $tmp = sprintf("%s_MobileAUAction_%s", $this->getAppId(), $postfix);
999 if ($fallback == false || class_exists($tmp)) {
1005 $r = sprintf("%s_Action_%s", $this->getAppId(), $postfix);
1007 $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1012 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥¢¥¯¥·¥ç¥ó¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1014 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar" -> "/Foo/Bar.php"¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1017 * @param string $action_name action̾
1018 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1019 * @return string action class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1021 function getDefaultActionPath($action_name, $fallback = true)
1023 $default_path = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($action_name)) . '.php';
1024 $action_dir = $this->getActiondir();
1026 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
1028 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1029 $r = 'MobileAU/' . $r;
1034 if ($fallback && file_exists($action_dir . $r) == false && $r != $default_path) {
1035 $this->logger->log(LOG_DEBUG, 'client_type specific file not found [%s] -> try defualt', $r);
1039 $this->logger->log(LOG_DEBUG, "default action path [%s]", $r);
1044 * Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
1046 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_View_[Á«°Ü̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1049 * @param string $forward_name forward̾
1050 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1051 * @return string view class¥¯¥é¥¹Ì¾
1053 function getDefaultViewClass($forward_name, $fallback = true)
1055 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($forward_name));
1058 if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1059 $tmp = sprintf("%s_MobileAUView_%s", $this->getAppId(), $postfix);
1060 if ($fallback == false || class_exists($tmp)) {
1066 $r = sprintf("%s_View_%s", $this->getAppId(), $postfix);
1068 $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1073 * Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1075 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar" -> "/Foo/Bar.php"¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1078 * @param string $forward_name forward̾
1079 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1080 * @return string view class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1082 function getDefaultViewPath($forward_name, $fallback = true)
1084 $default_path = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($forward_name)) . '.php';
1085 $view_dir = $this->getViewdir();
1087 if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1088 $r = 'MobileAU/' . $r;
1093 if ($fallback && file_exists($view_dir . $r) == false && $r != $default_path) {
1094 $this->logger->log(LOG_DEBUG, 'client_type specific file not found [%s] -> try defualt', $r);
1098 $this->logger->log(LOG_DEBUG, "default action path [%s]", $r);
1103 * ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
1106 * @param mixed $default_action_name »ØÄê¤Îaction̾
1107 * @return string ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾
1109 function _getActionName($default_action_name, $fallback_action_name)
1111 // ¥Õ¥©¡¼¥à¤«¤éÍ׵ᤵ¤ì¤¿action̾¤ò¼èÆÀ¤¹¤ë
1112 $form_action_name = $this->_getActionName_Form();
1113 $this->logger->log(LOG_DEBUG, 'form_action_name[%s]', $form_action_name);
1115 // ¥Õ¥©¡¼¥à¤«¤é¤Î»ØÄ̵꤬¤¤¾ì¹ç¤Ï¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È¤Ë»ØÄꤵ¤ì¤¿¥Ç¥Õ¥©¥ë¥ÈÃͤòÍøÍѤ¹¤ë
1116 if ($form_action_name == "" && count($default_action_name) > 0) {
1117 $tmp = is_array($default_action_name) ? $default_action_name[0] : $default_action_name;
1118 $this->logger->log(LOG_DEBUG, '-> default_action_name[%s]', $tmp);
1119 $action_name = $tmp;
1121 $action_name = $form_action_name;
1124 // ¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È¤ËÇÛÎ󤬻ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï»ØÄê°Ê³°¤Îaction̾¤ÏµñÈݤ¹¤ë
1125 if (is_array($default_action_name)) {
1126 if (in_array($action_name, $default_action_name) == false) {
1127 // »ØÄê°Ê³°¤Îaction̾¤Ç¹ç¤Ã¤¿¾ì¹ç¤Ï$fallback_action_name(or ¥Ç¥Õ¥©¥ë¥È)
1128 $tmp = $fallback_action_name != "" ? $fallback_action_name : $default_action_name[0];
1129 $this->logger->log(LOG_DEBUG, '-> fallback_action_name[%s]', $tmp);
1130 $action_name = $tmp;
1134 $this->logger->log(LOG_DEBUG, '<<< action_name[%s] >>>', $action_name);
1136 return $action_name;
1140 * ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
1142 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÎÀ¼Á¤Ë±þ¤¸¤Æ¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤Æ²¼¤µ¤¤¡£
1143 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"action_"¤Ç»Ï¤Þ¤ë¥Õ¥©¡¼¥àÃͤÎ"action_"¤ÎÉôʬ¤ò½ü¤¤¤¿¤â¤Î
1144 * ("action_sample"¤Ê¤é"sample")¤¬action̾¤È¤·¤Æ°·¤ï¤ì¤Þ¤¹
1147 * @return string ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿action¤Î̾¾Î
1149 function _getActionName_Form()
1151 if (isset($_SERVER['REQUEST_METHOD']) == false) {
1152 return $default_action_name;
1155 if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
1156 $http_vars =& $_POST;
1158 $http_vars =& $_GET;
1161 // ¥Õ¥©¡¼¥àÃͤ«¤é¥ê¥¯¥¨¥¹¥È¤µ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤ò¼èÆÀ¤¹¤ë
1162 $action_name = $sub_action_name = null;
1163 foreach ($http_vars as $name => $value) {
1164 if ($value == "" || strncmp($name, 'action_', 7) != 0) {
1168 $tmp = substr($name, 7);
1171 if (preg_match('/_x$/', $name) || preg_match('/_y$/', $name)) {
1172 $tmp = substr($tmp, 0, strlen($tmp)-2);
1175 // value="dummy"¤È¤Ê¤Ã¤Æ¤¤¤ë¤â¤Î¤ÏÍ¥ÀèÅÙ¤ò²¼¤²¤ë
1176 if ($value == "dummy") {
1177 $sub_action_name = $tmp;
1179 $action_name = $tmp;
1182 if ($action_name == null) {
1183 $action_name = $sub_action_name;
1186 return $action_name;
1190 * ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤ËÂбþ¤¹¤ëÄêµÁ¤òÊÖ¤¹
1193 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
1194 * @return array ¥¢¥¯¥·¥ç¥óÄêµÁ
1196 function &_getAction($action_name)
1198 if ($this->client_type == CLIENT_TYPE_SOAP) {
1199 $action =& $this->soap_action;
1201 $action =& $this->action;
1204 $action_obj = array();
1205 if (isset($action[$action_name])) {
1206 $action_obj = $action[$action_name];
1207 if (isset($action_obj['inspect']) && $action_obj['inspect']) {
1211 $this->logger->log(LOG_DEBUG, "action [%s] is not defined -> try default", $action_name);
1214 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤Î¥¤¥ó¥¯¥ë¡¼¥É
1215 $this->_includeActionScript($action_obj, $action_name);
1218 if (isset($action_obj['class_name']) == false) {
1219 $action_obj['class_name'] = $this->getDefaultActionClass($action_name);
1222 if (isset($action_obj['form_name']) == false) {
1223 $action_obj['form_name'] = $this->getDefaultFormClass($action_name);
1225 // ÌÀ¼¨»ØÄꤵ¤ì¤¿¥Õ¥©¡¼¥à¥¯¥é¥¹¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï·Ù¹ð
1226 $this->logger->log(LOG_WARNING, 'stated form class is not defined [%s]', $action_obj['form_name']);
1230 if (class_exists($action_obj['class_name']) == false) {
1231 $this->logger->log(LOG_WARNING, 'action class is not defined [%s]', $action_obj['class_name']);
1234 if (class_exists($action_obj['form_name']) == false) {
1235 // ¥Õ¥©¡¼¥à¥¯¥é¥¹¤Ï̤ÄêµÁ¤Ç¤âÎɤ¤
1236 $this->logger->log(LOG_DEBUG, 'form class is not defined [%s] -> falling back to default [%s]', $action_obj['form_name'], 'Ethna_ActionForm');
1237 $action_obj['form_name'] = 'Ethna_ActionForm';
1240 $action_obj['inspect'] = true;
1241 $action[$action_name] = $action_obj;
1242 return $action[$action_name];
1246 * ¥¢¥¯¥·¥ç¥ó̾¤È¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤«¤é¤ÎÌá¤êÃͤ˴ð¤Å¤¤¤ÆÁ«°ÜÀè¤ò·èÄꤹ¤ë
1249 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
1250 * @param string $retval ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤«¤é¤ÎÌá¤êÃÍ
1251 * @return string Á«°ÜÀè
1253 function _sortForward($action_name, $retval)
1259 * »ØÄꤵ¤ì¤¿Á«°Ü̾¤ËÂбþ¤¹¤ë²èÌ̤ò½ÐÎϤ¹¤ë
1262 * @param string $forward_name Á«°Ü̾
1263 * @return bool 0:Àµ¾ï½ªÎ» -1:¥¨¥é¡¼
1265 function _forward($forward_name)
1267 $forward_path = $this->_getForwardPath($forward_name);
1268 $smarty =& $this->getTemplateEngine();
1270 $form_array =& $this->action_form->getArray();
1271 $app_array =& $this->action_form->getAppArray();
1272 $app_ne_array =& $this->action_form->getAppNEArray();
1273 $smarty->assign_by_ref('form', $form_array);
1274 $smarty->assign_by_ref('app', $app_array);
1275 $smarty->assign_by_ref('app_ne', $app_ne_array);
1276 $smarty->assign_by_ref('errors', Ethna_Util::escapeHtml($this->action_error->getMessageList()));
1277 if (isset($_SESSION)) {
1278 $smarty->assign_by_ref('session', Ethna_Util::escapeHtml($_SESSION));
1280 $smarty->assign('script', basename($_SERVER['PHP_SELF']));
1281 $smarty->assign('request_uri', htmlspecialchars($_SERVER['REQUEST_URI']));
1283 // ¥Ç¥Õ¥©¥ë¥È¥Þ¥¯¥í¤ÎÀßÄê
1284 $this->_setDefaultMacro($smarty);
1286 $smarty->display($forward_path);
1292 * Á«°Ü̾¤«¤é¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹Ì¾¤ò¼èÆÀ¤¹¤ë
1295 * @param string $forward_name forward̾
1296 * @return string ¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹Ì¾
1298 function _getForwardPath($forward_name)
1300 $forward_obj = null;
1302 if (isset($this->forward[$forward_name]) == false) {
1304 $this->forward[$forward_name] = array();
1306 $forward_obj =& $this->forward[$forward_name];
1307 if (isset($forward_obj['forward_path']) == false) {
1309 $forward_obj['forward_path'] = $this->_getDefaultForwardPath($forward_name);
1312 return $forward_obj['forward_path'];
1316 * »ÈÍѸÀ¸ì¤òÀßÄꤹ¤ë
1318 * ¾Íè¤Ø¤Î³ÈÄ¥¤Î¤¿¤á¤Î¤ß¤Ë¸ºß¤·¤Æ¤¤¤Þ¤¹¡£¸½ºß¤ÏÆä˥ª¡¼¥Ð¡¼¥é¥¤¥É¤ÎɬÍפϤ¢¤ê¤Þ¤»¤ó¡£
1321 * @param string $language ¸À¸ìÄêµÁ(LANG_JA, LANG_EN...)
1322 * @param string $system_encoding ¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
1323 * @param string $client_encoding ¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
1325 function _setLanguage($language, $system_encoding = null, $client_encoding = null)
1327 $this->language = $language;
1328 $this->system_encoding = $system_encoding;
1329 $this->client_encoding = $client_encoding;
1331 $this->i18n->setLanguage($language, $system_encoding, $client_encoding);
1335 * ¥Ç¥Õ¥©¥ë¥È¾õÂ֤ǤλÈÍѸÀ¸ì¤ò¼èÆÀ¤¹¤ë
1338 * @return array »ÈÍѸÀ¸ì,¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾,¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
1340 function _getDefaultLanguage()
1342 return array(LANG_JA, null, null);
1346 * ¥Ç¥Õ¥©¥ë¥È¾õÂ֤ǤΥ¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤ò¼èÆÀ¤¹¤ë
1349 * @return int ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
1351 function _getDefaultClientType()
1353 if (is_null($GLOBALS['_Ethna_client_type']) == false) {
1354 return $GLOBALS['_Ethna_client_type'];
1356 return CLIENT_TYPE_WWW;
1360 * ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1362 * ¤¿¤À¤·¡¢¥¤¥ó¥¯¥ë¡¼¥É¤·¤¿¥Õ¥¡¥¤¥ë¤Ë¥¯¥é¥¹¤¬Àµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÏÊݾڤ·¤Ê¤¤
1365 * @param array $action_obj ¥¢¥¯¥·¥ç¥óÄêµÁ
1366 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
1368 function _includeActionScript($action_obj, $action_name)
1370 $class_path = $form_path = null;
1372 $action_dir = $this->getActiondir();
1374 // class_path°À¥Á¥§¥Ã¥¯
1375 if (isset($action_obj['class_path'])) {
1376 if (file_exists($action_dir . $action_obj['class_path']) == false) {
1377 $this->logger->log(LOG_WARNING, 'class_path file not found [%s] -> try default', $action_obj['class_path']);
1379 include_once($action_dir . $action_obj['class_path']);
1380 $class_path = $action_obj['class_path'];
1384 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1385 if (is_null($class_path)) {
1386 $class_path = $this->getDefaultActionPath($action_name);
1387 if (file_exists($action_dir . $class_path)) {
1388 include_once($action_dir . $class_path);
1390 $this->logger->log(LOG_DEBUG, 'default action file not found [%s] -> try all files', $class_path);
1395 // Á´¥Õ¥¡¥¤¥ë¥¤¥ó¥¯¥ë¡¼¥É
1396 if (is_null($class_path)) {
1397 $this->_includeDirectory($this->getActiondir());
1401 // form_path°À¥Á¥§¥Ã¥¯
1402 if (isset($action_obj['form_path'])) {
1403 if ($action_obj['form_path'] == $class_path) {
1406 if (file_exists($action_dir . $action_obj['form_path']) == false) {
1407 $this->logger->log(LOG_WARNING, 'form_path file not found [%s] -> try default', $action_obj['form_path']);
1409 include_once($action_dir . $action_obj['form_path']);
1410 $form_path = $action_obj['form_path'];
1414 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1415 if (is_null($form_path)) {
1416 $form_path = $this->getDefaultFormPath($action_name);
1417 if ($form_path == $class_path) {
1420 if (file_exists($action_dir . $form_path)) {
1421 include_once($action_dir . $form_path);
1423 $this->logger->log(LOG_DEBUG, 'default form file not found [%s] -> maybe falling back to default form class', $form_path);
1429 * ¥Ó¥å¡¼¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1431 * ¤¿¤À¤·¡¢¥¤¥ó¥¯¥ë¡¼¥É¤·¤¿¥Õ¥¡¥¤¥ë¤Ë¥¯¥é¥¹¤¬Àµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÏÊݾڤ·¤Ê¤¤
1434 * @param array $forward_obj Á«°ÜÄêµÁ
1435 * @param string $forward_name Á«°Ü̾
1437 function _includeViewScript($forward_obj, $forward_name)
1439 $view_dir = $this->getViewdir();
1441 // preforward_path°À¥Á¥§¥Ã¥¯
1442 if (isset($action_obj['preforward_path'])) {
1443 if (file_exists($view_dir . $forward_obj['preforward_path']) == false) {
1444 $this->logger->log(LOG_WARNING, 'preforward_path file not found [%s] -> try default', $forward_obj['preforward_path']);
1446 include_once($action_dir . $forward_obj['preforward_path']);
1451 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1452 $preforward_path = $this->getDefaultViewPath($forward_name);
1453 if (file_exists($view_dir . $preforward_path)) {
1454 include_once($view_dir . $preforward_path);
1457 $this->logger->log(LOG_DEBUG, 'default preforward file not found [%s]', $preforward_path);
1458 $preforward_path = null;
1463 * ¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤ÎÁ´¤Æ¤Î¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1467 function _includeDirectory($dir)
1469 $ext = "." . $this->ext['php'];
1470 $ext_len = strlen($ext);
1472 if (is_dir($dir) == false) {
1476 $dh = opendir($dir);
1478 while (($file = readdir($dh)) !== false) {
1479 if ($file != '.' && $file != '..' && is_dir("$dir/$file")) {
1480 $this->_includeDirectory("$dir/$file");
1482 if (substr($file, -$ext_len, $ext_len) != $ext) {
1485 include_once("$dir/$file");
1492 * Á«°Ü»þ¤Î¥Ç¥Õ¥©¥ë¥È¥Þ¥¯¥í¤òÀßÄꤹ¤ë
1495 * @param object Smarty $smarty ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¥ª¥Ö¥¸¥§¥¯¥È
1497 function _setDefaultMacro(&$smarty)
1502 * Ethna¥Þ¥Í¡¼¥¸¥ã¤òÀßÄꤹ¤ë(ÉÔÍפʾì¹ç¤Ï¶õ¤Î¥á¥½¥Ã¥É¤È¤·¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤Æ¤â¤è¤¤)
1506 function _activateEthnaManager()
1508 $base = dirname(dirname(__FILE__));
1510 if ($this->config->get('debug') == false) {
1515 $this->action['__ethna_info__'] = array(
1516 'form_name' => 'Ethna_Form_Info',
1517 'class_name' => 'Ethna_Action_Info',
1519 $this->action['__ethna_info_do__'] = array(
1520 'form_name' => 'Ethna_Form_InfoDo',
1521 'class_name' => 'Ethna_Action_InfoDo',
1525 $forward_obj = array();
1527 $forward_obj['forward_path'] = sprintf("%s/tpl/info.tpl", $base);
1528 $forward_obj['preforward_name'] = 'Ethna_Action_Info';
1529 $this->forward['__ethna_info__'] = $forward_obj;
1533 * Á«°Ü̾¤ËÂбþ¤¹¤ë¥Æ¥ó¥×¥ì¡¼¥È¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1535 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar"¤È¤¤¤¦forward̾¤¬"foo/bar" + ¥Æ¥ó¥×¥ì¡¼¥È³ÈÄ¥»Ò¤È¤Ê¤ë
1536 * ¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1539 * @param string $forward_name forward̾
1540 * @return string forward¥Ñ¥¹Ì¾
1542 function _getDefaultForwardPath($forward_name)
1544 return str_replace('_', '/', $forward_name) . '.' . $this->ext['tpl'];
1548 * ÀßÄê¥Õ¥¡¥¤¥ë¤ÎDSNÄêµÁ¤«¤é»ÈÍѤ¹¤ë¥Ç¡¼¥¿¤òºÆ¹½ÃÛ¤¹¤ë(¥¹¥ì¡¼¥Ö¥¢¥¯¥»¥¹Ê¬´ôÅù)
1550 * DSN¤ÎÄêµÁÊýË¡(¥Ç¥Õ¥©¥ë¥È:ÀßÄê¥Õ¥¡¥¤¥ë)¤òÊѤ¨¤¿¤¤¾ì¹ç¤Ï¤³¤³¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1553 * @return array DSNÄêµÁ
1555 function _prepareDSN()
1559 foreach ($this->db as $key => $value) {
1560 $config_key = "dsn";
1562 $config_key .= "_$key";
1564 $dsn = $this->config->get($config_key);
1565 if (is_array($dsn)) {
1566 // ¼ïÊÌ1¤Ä¤Ë¤Ä¤Ê£¿ôDSN¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¥¢¥¯¥»¥¹Ê¬´ô
1567 $dsn = $this->_selectDSN($key, $dsn);
1575 * DSN¤Î¥¢¥¯¥»¥¹Ê¬´ô¤ò¹Ô¤¦
1577 * ¥¹¥ì¡¼¥Ö¥µ¡¼¥Ð¤Ø¤Î¿¶Ê¬¤±½èÍý(¥Ç¥Õ¥©¥ë¥È:¥é¥ó¥À¥à)¤òÊѹ¹¤·¤¿¤¤¾ì¹ç¤Ï¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1580 * @param string $type DB¼ïÊÌ
1581 * @param array $dsn_list DSN°ìÍ÷
1582 * @return string ÁªÂò¤µ¤ì¤¿DSN
1584 function _selectDSN($type, $dsn_list)
1586 // ¥Ç¥Õ¥©¥ë¥È:¥é¥ó¥À¥à
1587 list($usec, $sec) = explode(' ', microtime());
1588 mt_srand($sec + ((float) $usec * 100000));
1589 $n = mt_rand(0, count($dsn_list)-1);
1591 return $dsn_list[$n];