2 // vim: foldmethod=marker
6 * @author Masaki Fujimoto <fujimoto@php.net>
7 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 // {{{ Ethna_Controller
16 * @author Masaki Fujimoto <fujimoto@php.net>
20 class Ethna_Controller
27 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID
32 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê
37 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL
42 * @var string ¥¢¥×¥ê¥±¡¼¥·¥ç¥óDSN(Data Source Name)
47 * @var array ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
49 var $directory = array(
50 'action' => 'app/action',
52 'filter' => 'app/filter',
56 'template' => 'template',
57 'template_c' => 'tmp',
63 * @var array DB¥¢¥¯¥»¥¹ÄêµÁ
70 * @var array ³ÈÄ¥»ÒÀßÄê
78 * @var array ¥¯¥é¥¹ÀßÄê
81 'config' => 'Ethna_Config',
83 'logger' => 'Ethna_Logger',
84 'sql' => 'Ethna_AppSQL',
88 * @var array ¥Õ¥£¥ë¥¿ÀßÄê
94 * @var string »ÈÍѸÀ¸ìÀßÄê
99 * @var string ¥·¥¹¥Æ¥à¦¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
101 var $system_encoding;
104 * @var string ¥¯¥é¥¤¥¢¥ó¥È¦¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
106 var $client_encoding;
109 * @var string ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×
114 * @var string ¸½ºß¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾
119 * @var array forwardÄêµÁ
121 var $forward = array();
124 * @var array actionÄêµÁ
126 var $action = array();
129 * @var array soap actionÄêµÁ
131 var $soap_action = array();
134 * @var array ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Þ¥Í¡¼¥¸¥ãÄêµÁ
136 var $manager = array();
139 * @var array smarty modifierÄêµÁ
141 var $smarty_modifier_plugin = array();
144 * @var array smarty functionÄêµÁ
146 var $smarty_function_plugin = array();
149 * @var array smarty prefilterÄêµÁ
151 var $smarty_prefilter_plugin = array();
154 * @var array smarty postfilterÄêµÁ
156 var $smarty_postfilter_plugin = array();
159 * @var array smarty outputfilterÄêµÁ
161 var $smarty_outputfilter_plugin = array();
164 * @var object Ethna_Backend backend¥ª¥Ö¥¸¥§¥¯¥È
169 * @var object Ethna_I18N i18n¥ª¥Ö¥¸¥§¥¯¥È
174 * @var object Ethna_ActionError action error¥ª¥Ö¥¸¥§¥¯¥È
176 var $action_error = null;
179 * @var object Ethna_ActionForm action form¥ª¥Ö¥¸¥§¥¯¥È
181 var $action_form = null;
184 * @var object Ethna_Session ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È
189 * @var object Ethna_Config ÀßÄꥪ¥Ö¥¸¥§¥¯¥È
194 * @var object Ethna_Logger ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È
199 * @var object Ethna_AppSQL SQL¥ª¥Ö¥¸¥§¥¯¥È
204 * @var array ¥Õ¥£¥ë¥¿¡¼¥Á¥§¥¤¥ó(Ethna_Filter¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇÛÎó)
206 var $filter_chain = array();
212 * Ethna_Controller¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
216 function Ethna_Controller()
218 $GLOBALS['controller'] =& $this;
221 // ¥¨¥é¡¼¥Ï¥ó¥É¥é¤ÎÀßÄê
222 Ethna::setErrorCallback(array(&$this, 'handleError'));
224 // ¥Ç¥£¥ì¥¯¥È¥ê̾¤ÎÀßÄê(ÁêÂХѥ¹->ÀäÂХѥ¹)
225 foreach ($this->directory as $key => $value) {
226 if ($key == 'plugins') {
227 // Smarty¥×¥é¥°¥¤¥ó¥Ç¥£¥ì¥¯¥È¥ê¤ÏÇÛÎó¤Ç»ØÄꤹ¤ë
228 $tmp = array(SMARTY_DIR . 'plugins');
229 foreach (to_array($value) as $elt) {
230 if ($elt{0} != '/') {
231 $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt;
234 $this->directory[$key] = $tmp;
236 if ($value{0} != '/') {
237 $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value;
241 $this->i18n =& new Ethna_I18N($this->getDirectory('locale'), $this->getAppId());
242 list($this->language, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage();
243 $this->client_type = $this->_getDefaultClientType();
245 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
246 $config_class = $this->class['config'];
247 $this->config =& new $config_class($this);
248 $this->dsn = $this->_prepareDSN();
249 $this->url = $this->config->get('url');
252 $logger_class = $this->class['logger'];
253 $this->logger =& new $logger_class($this);
254 $this->logger->begin();
256 // SQL¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®
257 $sql_class = $this->class['sql'];
258 $this->sql =& new $sql_class($this);
260 // Ethna¥Þ¥Í¡¼¥¸¥ãÀßÄê
261 $this->_activateEthnaManager();
265 * (¸½ºß¥¢¥¯¥Æ¥£¥Ö¤Ê)¥³¥ó¥È¥í¡¼¥é¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òÊÖ¤¹
268 * @return object Ethna_Controller ¥³¥ó¥È¥í¡¼¥é¤Î¥¤¥ó¥¹¥¿¥ó¥¹
271 function &getInstance()
273 if (isset($GLOBALS['controller'])) {
274 return $GLOBALS['controller'];
281 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID¤òÊÖ¤¹
284 * @return string ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID
288 return ucfirst(strtolower($this->appid));
295 * @param string $type DB¼ïÊÌ
298 function getDSN($type = "")
300 if (isset($this->dsn[$type]) == false) {
303 return $this->dsn[$type];
307 * DSN¤Î»ý³ÀܳÀßÄê¤òÊÖ¤¹
310 * @param string $type DB¼ïÊÌ
311 * @return bool true:persistent false:non-persistent(¤¢¤ë¤¤¤ÏÀßÄê̵¤·)
313 function getDSN_persistent($type = "")
315 $key = sprintf("dsn%s_persistent", $type == "" ? "" : "_$type");
316 $dsn_persistent = $this->config->get($key);
317 if (is_null($dsn_persistent)) {
320 return $dsn_persistent;
324 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL¤òÊÖ¤¹
327 * @return string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL
335 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê¤òÊÖ¤¹
338 * @return string ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê
340 function getBasedir()
346 * ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×/¸À¸ì¤«¤é¥Æ¥ó¥×¥ì¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
349 * @return string ¥Æ¥ó¥×¥ì¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê
351 function getTemplatedir()
353 $template = $this->getDirectory('template');
355 // ¸À¸ìÊ̥ǥ£¥ì¥¯¥È¥ê
356 if (file_exists($template . '/' . $this->language)) {
357 $template .= '/' . $this->language;
360 // ¥¯¥é¥¤¥¢¥ó¥ÈÊ̥ǥ£¥ì¥¯¥È¥ê(if we need)
361 if ($this->client_type == CLIENT_TYPE_MOBILE_AU && file_exists($template . '/au')) {
369 * ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
372 * @return string ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
374 function getActiondir()
376 return (empty($this->directory['action']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['action'] . "/"));
380 * ¥Ó¥å¡¼¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
383 * @return string ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
385 function getViewdir()
387 return (empty($this->directory['view']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['view'] . "/"));
391 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥¯¥é¥¹ÀßÄê¤òÊÖ¤¹
394 * @param string $key ¥¯¥é¥¹¥¿¥¤¥×("config", "db", "logger", "sql")
395 * @return string $key¤ËÂбþ¤·¤¿¥¯¥é¥¹Ì¾(ÀßÄ꤬¤Ê¤¤¾ì¹ç¤Ïnull)
397 function getClass($key)
399 if (isset($this->class[$key]) == false) {
402 return $this->class[$key];
406 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥êÀßÄê¤òÊÖ¤¹
409 * @param string $key ¥Ç¥£¥ì¥¯¥È¥ê¥¿¥¤¥×("tmp", "template"...)
410 * @return string $key¤ËÂбþ¤·¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
412 function getDirectory($key)
414 if (isset($this->directory[$key]) == false) {
417 return $this->directory[$key];
424 * @param string $key DB¥¿¥¤¥×("r", ...)
425 * @return string $key¤ËÂбþ¤¹¤ëDB¼ïÊÌÄêµÁ(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
429 if (isset($this->db[$key]) == false) {
432 return $this->db[$key];
436 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó³ÈÄ¥»ÒÀßÄê¤òÊÖ¤¹
439 * @param string $key ³ÈÄ¥»Ò¥¿¥¤¥×("php", "tpl"...)
440 * @return string $key¤ËÂбþ¤·¤¿³ÈÄ¥»Ò(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
442 function getExt($key)
444 if (isset($this->ext[$key]) == false) {
447 return $this->ext[$key];
451 * i18n¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ(R)
454 * @return object Ethna_I18N i18n¥ª¥Ö¥¸¥§¥¯¥È
462 * ÀßÄꥪ¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
465 * @return object Ethna_Config ÀßÄꥪ¥Ö¥¸¥§¥¯¥È
467 function &getConfig()
469 return $this->config;
473 * backend¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
476 * @return object Ethna_Backend backend¥ª¥Ö¥¸¥§¥¯¥È
478 function &getBackend()
480 return $this->backend;
484 * action error¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
487 * @return object Ethna_ActionError action error¥ª¥Ö¥¸¥§¥¯¥È
489 function &getActionError()
491 return $this->action_error;
495 * action form¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
498 * @return object Ethna_ActionForm action form¥ª¥Ö¥¸¥§¥¯¥È
500 function &getActionForm()
502 return $this->action_form;
506 * ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
509 * @return object Ethna_Session ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È
511 function &getSession()
513 return $this->session;
517 * ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
520 * @return object Ethna_Logger ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È
522 function &getLogger()
524 return $this->logger;
528 * SQL¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
531 * @return object Ethna_AppSQL SQL¥ª¥Ö¥¸¥§¥¯¥È
539 * ¥Þ¥Í¡¼¥¸¥ã°ìÍ÷¤òÊÖ¤¹
542 * @return array ¥Þ¥Í¡¼¥¸¥ã°ìÍ÷
544 function getManagerList()
546 return $this->manager;
550 * ¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
553 * @return string ¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾
555 function getCurrentActionName()
557 return $this->action_name;
564 * @return array »ÈÍѸÀ¸ì,¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾,¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
566 function getLanguage()
568 return array($this->language, $this->system_encoding, $this->client_encoding);
572 * ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤ò¼èÆÀ¤¹¤ë
575 * @return int ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
577 function getClientType()
579 return $this->client_type;
583 * ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤òÀßÄꤹ¤ë
586 * @param int $client_type ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
588 function setClientType($client_type)
590 $this->client_type = $client_type;
594 * ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¼èÆÀ¤¹¤ë(¸½ºß¤Ïsmarty¤Î¤ßÂбþ)
597 * @return object Smarty ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¥ª¥Ö¥¸¥§¥¯¥È
598 * @todo ¥Ö¥í¥Ã¥¯´Ø¿ô¥×¥é¥°¥¤¥ó(etc)Âбþ
600 function &getTemplateEngine()
602 $smarty =& new Smarty();
603 $smarty->template_dir = $this->getTemplatedir();
604 $smarty->compile_dir = $this->getDirectory('template_c') . '/tpl_' . md5($smarty->template_dir);
605 if (@is_dir($smarty->compile_dir) == false) {
606 mkdir($smarty->compile_dir, 0755);
608 $smarty->plugins_dir = $this->getDirectory('plugins');
611 $smarty->register_modifier('number_format', 'smarty_modifier_number_format');
612 $smarty->register_modifier('strftime', 'smarty_modifier_strftime');
613 $smarty->register_modifier('count', 'smarty_modifier_count');
614 $smarty->register_modifier('join', 'smarty_modifier_join');
615 $smarty->register_modifier('filter', 'smarty_modifier_filter');
616 $smarty->register_modifier('unique', 'smarty_modifier_unique');
617 $smarty->register_modifier('wordwrap_i18n', 'smarty_modifier_wordwrap_i18n');
618 $smarty->register_modifier('i18n', 'smarty_modifier_i18n');
619 $smarty->register_modifier('checkbox', 'smarty_modifier_checkbox');
620 $smarty->register_modifier('select', 'smarty_modifier_select');
621 $smarty->register_modifier('form_value', 'smarty_modifier_form_value');
623 // user defined modifiers
624 foreach ($this->smarty_modifier_plugin as $modifier) {
625 $name = str_replace('smarty_modifier_', '', $modifier);
626 $smarty->register_modifier($name, $modifier);
630 $smarty->register_function('message', 'smarty_function_message');
631 $smarty->register_function('uniqid', 'smarty_function_uniqid');
632 $smarty->register_function('select', 'smarty_function_select');
633 $smarty->register_function('checkbox_list', 'smarty_function_checkbox_list');
635 // user defined functions
636 foreach ($this->smarty_function_plugin as $function) {
637 $name = str_replace('smarty_function_', '', $function);
638 $smarty->register_function($name, $function);
641 // user defined prefilters
642 foreach ($this->smarty_prefilter_plugin as $prefilter) {
643 $smarty->register_prefilter($prefilter);
646 // user defined postfilters
647 foreach ($this->smarty_postfilter_plugin as $postfilter) {
648 $smarty->register_postfilter($postfilter);
651 // user defined outputfilters
652 foreach ($this->smarty_outputfilter_plugin as $outputfilter) {
653 $smarty->register_outputfilter($outputfilter);
656 $this->_setDefaultTemplateEngine($smarty);
662 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
665 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
666 * @param mixed $action_name »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾(¾Êά²Ä)
667 * @param mixed $fallback_action_name ¥¢¥¯¥·¥ç¥ó¤¬·èÄê¤Ç¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾(¾Êά²Ä)
670 function main($class_name, $action_name = "", $fallback_action_name = "")
672 $c =& new $class_name;
673 $c->trigger('www', $action_name, $fallback_action_name);
677 * ¥³¥Þ¥ó¥É¥é¥¤¥ó¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
680 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
681 * @param string $action_name ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾
684 function main_CLI($class_name, $action_name)
686 $c =& new $class_name;
687 $c->action[$action_name] = array();
688 $c->trigger('www', $action_name);
692 * SOAP¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
695 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
698 function main_SOAP($class_name)
700 $c =& new $class_name;
701 $c->setClientType(CLIENT_TYPE_SOAP);
706 * AMF(Flash Remoting)¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
709 * @param string $class_name ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
712 function main_AMF($class_name)
714 $c =& new $class_name;
715 $c->setClientType(CLIENT_TYPE_AMF);
720 * ¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò³«»Ï¤¹¤ë
723 * @param strint $type ½èÍý¥¿¥¤¥×(WWW/SOAP/AMF)
724 * @param mixed $default_action_name »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾
725 * @param mixed $fallback_action_name ¥¢¥¯¥·¥ç¥ó̾¤¬·èÄê¤Ç¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾
726 * @return mixed 0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
728 function trigger($type, $default_action_name = "", $fallback_action_name = "")
731 $this->_createFilterChain();
734 for ($i = 0; $i < count($this->filter_chain); $i++) {
735 $this->filter_chain[$i]->prefilter();
739 if ($type == 'www') {
740 $this->_trigger($default_action_name, $fallback_action_name);
741 } else if ($type == 'soap') {
742 $this->_trigger_SOAP();
743 } else if ($type == 'amf') {
744 $this->_trigger_AMF();
748 for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
749 $this->filter_chain[$i]->postfilter();
754 * ¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò¼Â¹Ô¤¹¤ë(WWW)
756 * °ú¿ô$default_action_name¤ËÇÛÎ󤬻ØÄꤵ¤ì¤¿¾ì¹ç¡¢¤½¤ÎÇÛÎó¤Ç»ØÄꤵ¤ì¤¿
757 * ¥¢¥¯¥·¥ç¥ó°Ê³°¤Ï¼õ¤±ÉÕ¤±¤Ê¤¤(¤½¤ì°Ê³°¤Î¥¢¥¯¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
758 * ÇÛÎó¤ÎÀèƬ¤Ç»ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤¬¼Â¹Ô¤µ¤ì¤ë)
761 * @param mixed $default_action_name »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾
762 * @param mixed $fallback_action_name ¥¢¥¯¥·¥ç¥ó̾¤¬·èÄê¤Ç¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾
763 * @return mixed 0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
765 function _trigger($default_action_name = "", $fallback_action_name = "")
767 // ¥¢¥¯¥·¥ç¥ó̾¤Î¼èÆÀ
768 $action_name = $this->_getActionName($default_action_name, $fallback_action_name);
770 // ¥¢¥¯¥·¥ç¥óÄêµÁ¤Î¼èÆÀ
771 $action_obj =& $this->_getAction($action_name);
772 if (is_null($action_obj)) {
773 if ($fallback_action_name != "") {
774 $this->logger->log(LOG_DEBUG, 'undefined action [%s] -> try fallback action [%s]', $action_name, $fallback_action_name);
775 $action_obj =& $this->_getAction($fallback_action_name);
777 if ($action_obj == null) {
778 return Ethna::raiseError(E_APP_UNDEFINED_ACTION, "undefined action [%s]", $action_name);
780 $action_name = $fallback_action_name;
783 $this->action_name = $action_name;
786 $this->_setLanguage($this->language, $this->system_encoding, $this->client_encoding);
789 $this->action_error =& new Ethna_ActionError();
790 $form_name = $this->getActionFormName($action_name);
791 $this->action_form =& new $form_name($this);
792 $this->session =& new Ethna_Session($this->getAppId(), $this->getDirectory('tmp'), $this->logger);
794 // ¥Ð¥Ã¥¯¥¨¥ó¥É½èÍý¼Â¹Ô
795 $backend =& new Ethna_Backend($this);
796 $this->backend =& $backend;
797 $forward_name = $backend->perform($action_name);
799 // ¥³¥ó¥È¥í¡¼¥é¤ÇÁ«°ÜÀè¤ò·èÄꤹ¤ë(¥ª¥×¥·¥ç¥ó)
800 $forward_name = $this->_sortForward($action_name, $forward_name);
802 if ($forward_name != null) {
803 $view_name = $this->getViewClassName($forward_name);
804 $view_class =& new $view_name($this->backend, $forward_name, $this->_getForwardPath($forward_name));
806 if (is_subclass_of($view_class, 'Ethna_ViewClass') == false) {
807 $view_class->preforward();
808 $view_class =& new Ethna_ViewClass($this->backend, $forward_name, $this->_getForwardPath($forward_name));
810 $view_class->forward();
817 * SOAP¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò¼Â¹Ô¤¹¤ë
823 function _trigger_SOAP()
825 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É
826 $this->_includeActionScript();
828 // SOAP¥¨¥ó¥È¥ê¥¯¥é¥¹
829 $gg =& new Ethna_SoapGatewayGenerator();
830 $script = $gg->generate();
833 // SOAP¥ê¥¯¥¨¥¹¥È½èÍý
834 $server =& new SoapServer(null, array('uri' => $this->config->get('url')));
835 $server->setClass($gg->getClassName());
840 * AMF(Flash Remoting)¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò¼Â¹Ô¤¹¤ë
846 function _trigger_AMF()
848 include_once('ethna/contrib/amfphp/app/Gateway.php');
850 $this->action_error =& new Ethna_ActionError();
852 // Credential¥Ø¥Ã¥À¤Ç¥»¥Ã¥·¥ç¥ó¤ò½èÍý¤¹¤ë¤Î¤Ç¤³¤³¤Ç¤Ïnull¤ËÀßÄê
853 $this->session = null;
855 $this->_setLanguage($this->language, $this->system_encoding, $this->client_encoding);
857 // backend¥ª¥Ö¥¸¥§¥¯¥È
858 $backend =& new Ethna_Backend($this);
859 $this->backend =& $backend;
861 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É
862 $this->_includeActionScript();
864 // amfphp¤Ë½èÍý¤ò°Ñ¾ù
865 $gateway =& new Gateway();
866 $gateway->setBaseClassPath('');
873 * ¥¨¥é¡¼È¯À¸»þ¤ÎÄɲýèÍý¤ò¹Ô¤¤¤¿¤¤¾ì¹ç¤Ï¤³¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹
874 * (¥¢¥é¡¼¥È¥á¡¼¥ëÁ÷¿®Åù¡Ý¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¥í¥°½ÐÎÏ»þ¤Ë¥¢¥é¡¼¥È¥á¡¼¥ë
875 * ¤¬Á÷¿®¤µ¤ì¤ë¤¬¡¢¥¨¥é¡¼È¯À¸»þ¤ËÊ̤˥¢¥é¡¼¥È¥á¡¼¥ë¤ò¤³¤³¤ÇÁ÷¿®
879 * @param object Ethna_Error ¥¨¥é¡¼¥ª¥Ö¥¸¥§¥¯¥È
881 function handleError(&$error)
884 list ($log_level, $dummy) = $this->logger->errorLevelToLogLevel($error->getLevel());
885 $message = $error->getMessage();
886 $this->logger->log($log_level, sprintf("[APP(%d)] %s", $error->getCode(), $message));
890 * ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ò¼èÆÀ¤¹¤ë
893 * @param int $code ¥¨¥é¡¼¥³¡¼¥É
894 * @return string ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
896 function getErrorMessage($code)
898 $message_list =& $GLOBALS['_Ethna_error_message_list'];
899 for ($i = count($message_list)-1; $i >= 0; $i--) {
900 if (array_key_exists($code, $message_list[$i])) {
901 return $message_list[$i][$code];
908 * »ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Î¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
911 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
912 * @return string ¥¢¥¯¥·¥ç¥ó¤Î¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾
914 function getActionFormName($action_name)
916 $action_obj =& $this->_getAction($action_name);
917 if (is_null($action_obj)) {
921 return $action_obj['form_name'];
925 * »ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Î¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
928 * @param string $action_name ¥¢¥¯¥·¥ç¥ó¤Î̾¾Î
929 * @return string ¥¢¥¯¥·¥ç¥ó¤Î¥¯¥é¥¹Ì¾
931 function getActionClassName($action_name)
933 $action_obj =& $this->_getAction($action_name);
934 if ($action_obj == null) {
938 return $action_obj['class_name'];
942 * »ØÄꤵ¤ì¤¿Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
945 * @param string $forward_name Á«°ÜÀè¤Î̾¾Î
946 * @return string view class¤Î¥¯¥é¥¹Ì¾
948 function getViewClassName($forward_name)
950 if ($forward_name == null) {
954 if (isset($this->forward[$forward_name])) {
955 $forward_obj = $this->forward[$forward_name];
957 $forward_obj = array();
960 if (isset($forward_obj['view_name'])) {
961 $class_name = $forward_obj['view_name'];
962 if (class_exists($class_name)) {
969 // view¤Î¥¤¥ó¥¯¥ë¡¼¥É
970 $this->_includeViewScript($forward_obj, $forward_name);
972 if (is_null($class_name) == false && class_exists($class_name)) {
974 } else if (is_null($class_name) == false) {
975 $this->logger->log(LOG_WARNING, 'stated view class is not defined [%s] -> try default', $class_name);
978 $class_name = $this->getDefaultViewClass($forward_name);
979 if (class_exists($class_name)) {
982 $this->logger->log(LOG_DEBUG, 'view class is not defined for [%s] -> use default [%s]', $forward_name, 'Ethna_ViewClass');
983 return 'Ethna_ViewClass';
988 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
990 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_Form_[¥¢¥¯¥·¥ç¥ó̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
993 * @param string $action_name action̾
994 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
995 * @return string action form¥¯¥é¥¹Ì¾
997 function getDefaultFormClass($action_name, $fallback = true)
999 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
1002 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
1003 $r = sprintf("%s_SOAPForm_%s", $this->getAppId(), $postfix);
1004 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1005 $tmp = sprintf("%s_MobileAUForm_%s", $this->getAppId(), $postfix);
1006 if ($fallback == false || class_exists($tmp)) {
1012 $r = sprintf("%s_Form_%s", $this->getAppId(), $postfix);
1014 $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1019 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥Õ¥©¡¼¥à¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1021 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï_getDefaultActionPath()¤ÈƱ¤¸·ë²Ì¤òÊÖ¤¹(1¥Õ¥¡¥¤¥ë¤Ë
1022 * ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤È¥Õ¥©¡¼¥à¥¯¥é¥¹¤¬µ½Ò¤µ¤ì¤ë)¤Î¤Ç¡¢¹¥¤ß¤Ë±þ¤¸¤Æ
1023 * ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1026 * @param string $action_name action̾
1027 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1028 * @return string form class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1030 function getDefaultFormPath($action_name, $fallback = true)
1032 return $this->getDefaultActionPath($action_name, $fallback);
1036 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
1038 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_Action_[¥¢¥¯¥·¥ç¥ó̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1041 * @param string $action_name action̾
1042 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1043 * @return string action class¥¯¥é¥¹Ì¾
1045 function getDefaultActionClass($action_name, $fallback = true)
1047 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
1050 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
1051 $r = sprintf("%s_SOAPAction_%s", $this->getAppId(), $postfix);
1052 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1053 $tmp = sprintf("%s_MobileAUAction_%s", $this->getAppId(), $postfix);
1054 if ($fallback == false || class_exists($tmp)) {
1060 $r = sprintf("%s_Action_%s", $this->getAppId(), $postfix);
1062 $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1067 * ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥¢¥¯¥·¥ç¥ó¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1069 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar" -> "/Foo/Bar.php"¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1072 * @param string $action_name action̾
1073 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1074 * @return string action class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1076 function getDefaultActionPath($action_name, $fallback = true)
1078 $default_path = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($action_name)) . '.' . $this->getExt('php');
1079 $action_dir = $this->getActiondir();
1081 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
1083 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1084 $r = 'MobileAU/' . $r;
1089 if ($fallback && file_exists($action_dir . $r) == false && $r != $default_path) {
1090 $this->logger->log(LOG_DEBUG, 'client_type specific file not found [%s] -> try defualt', $r);
1094 $this->logger->log(LOG_DEBUG, "default action path [%s]", $r);
1099 * Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
1101 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_View_[Á«°Ü̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1104 * @param string $forward_name forward̾
1105 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1106 * @return string view class¥¯¥é¥¹Ì¾
1108 function getDefaultViewClass($forward_name, $fallback = true)
1110 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($forward_name));
1113 if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1114 $tmp = sprintf("%s_MobileAUView_%s", $this->getAppId(), $postfix);
1115 if ($fallback == false || class_exists($tmp)) {
1121 $r = sprintf("%s_View_%s", $this->getAppId(), $postfix);
1123 $this->logger->log(LOG_DEBUG, "default view class [%s]", $r);
1128 * Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1130 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar" -> "/Foo/Bar.php"¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1133 * @param string $forward_name forward̾
1134 * @param bool $fallback ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1135 * @return string view class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1137 function getDefaultViewPath($forward_name, $fallback = true)
1139 $default_path = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($forward_name)) . '.' . $this->getExt('php');
1140 $view_dir = $this->getViewdir();
1142 if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1143 $r = 'MobileAU/' . $r;
1148 if ($fallback && file_exists($view_dir . $r) == false && $r != $default_path) {
1149 $this->logger->log(LOG_DEBUG, 'client_type specific file not found [%s] -> try defualt', $r);
1153 $this->logger->log(LOG_DEBUG, "default view path [%s]", $r);
1158 * ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
1161 * @param mixed $default_action_name »ØÄê¤Îaction̾
1162 * @return string ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾
1164 function _getActionName($default_action_name, $fallback_action_name)
1166 // ¥Õ¥©¡¼¥à¤«¤éÍ׵ᤵ¤ì¤¿action̾¤ò¼èÆÀ¤¹¤ë
1167 $form_action_name = $this->_getActionName_Form();
1168 $form_action_name = preg_replace('/[^a-z0-9\-_]+/i', '', $form_action_name);
1169 $this->logger->log(LOG_DEBUG, 'form_action_name[%s]', $form_action_name);
1171 // ¥Õ¥©¡¼¥à¤«¤é¤Î»ØÄ̵꤬¤¤¾ì¹ç¤Ï¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È¤Ë»ØÄꤵ¤ì¤¿¥Ç¥Õ¥©¥ë¥ÈÃͤòÍøÍѤ¹¤ë
1172 if ($form_action_name == "" && count($default_action_name) > 0) {
1173 $tmp = is_array($default_action_name) ? $default_action_name[0] : $default_action_name;
1174 $this->logger->log(LOG_DEBUG, '-> default_action_name[%s]', $tmp);
1175 $action_name = $tmp;
1177 $action_name = $form_action_name;
1180 // ¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È¤ËÇÛÎ󤬻ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï»ØÄê°Ê³°¤Îaction̾¤ÏµñÈݤ¹¤ë
1181 if (is_array($default_action_name)) {
1182 if ($this->_isAcceptableActionName($action_name, $default_action_name) == false) {
1183 // »ØÄê°Ê³°¤Îaction̾¤Ç¹ç¤Ã¤¿¾ì¹ç¤Ï$fallback_action_name(or ¥Ç¥Õ¥©¥ë¥È)
1184 $tmp = $fallback_action_name != "" ? $fallback_action_name : $default_action_name[0];
1185 if ($tmp{strlen($tmp)-1} == '*') {
1186 $tmp = substr($tmp, 0, -1);
1188 $this->logger->log(LOG_DEBUG, '-> fallback_action_name[%s]', $tmp);
1189 $action_name = $tmp;
1193 $this->logger->log(LOG_DEBUG, '<<< action_name[%s] >>>', $action_name);
1195 return $action_name;
1199 * ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
1201 * ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÎÀ¼Á¤Ë±þ¤¸¤Æ¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤Æ²¼¤µ¤¤¡£
1202 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"action_"¤Ç»Ï¤Þ¤ë¥Õ¥©¡¼¥àÃͤÎ"action_"¤ÎÉôʬ¤ò½ü¤¤¤¿¤â¤Î
1203 * ("action_sample"¤Ê¤é"sample")¤¬action̾¤È¤·¤Æ°·¤ï¤ì¤Þ¤¹
1206 * @return string ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿action¤Î̾¾Î
1208 function _getActionName_Form()
1210 if (isset($_SERVER['REQUEST_METHOD']) == false) {
1211 return $default_action_name;
1214 if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
1215 $http_vars =& $_POST;
1217 $http_vars =& $_GET;
1220 // ¥Õ¥©¡¼¥àÃͤ«¤é¥ê¥¯¥¨¥¹¥È¤µ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤ò¼èÆÀ¤¹¤ë
1221 $action_name = $sub_action_name = null;
1222 foreach ($http_vars as $name => $value) {
1223 if ($value == "" || strncmp($name, 'action_', 7) != 0) {
1227 $tmp = substr($name, 7);
1230 if (preg_match('/_x$/', $name) || preg_match('/_y$/', $name)) {
1231 $tmp = substr($tmp, 0, strlen($tmp)-2);
1234 // value="dummy"¤È¤Ê¤Ã¤Æ¤¤¤ë¤â¤Î¤ÏÍ¥ÀèÅÙ¤ò²¼¤²¤ë
1235 if ($value == "dummy") {
1236 $sub_action_name = $tmp;
1238 $action_name = $tmp;
1241 if ($action_name == null) {
1242 $action_name = $sub_action_name;
1245 return $action_name;
1249 * ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤ËÂбþ¤¹¤ëÄêµÁ¤òÊÖ¤¹
1252 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
1253 * @return array ¥¢¥¯¥·¥ç¥óÄêµÁ
1255 function &_getAction($action_name)
1257 if ($this->client_type == CLIENT_TYPE_SOAP) {
1258 $action =& $this->soap_action;
1260 $action =& $this->action;
1263 $action_obj = array();
1264 if (isset($action[$action_name])) {
1265 $action_obj = $action[$action_name];
1266 if (isset($action_obj['inspect']) && $action_obj['inspect']) {
1270 $this->logger->log(LOG_DEBUG, "action [%s] is not defined -> try default", $action_name);
1273 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤Î¥¤¥ó¥¯¥ë¡¼¥É
1274 $this->_includeActionScript($action_obj, $action_name);
1277 if (isset($action_obj['class_name']) == false) {
1278 $action_obj['class_name'] = $this->getDefaultActionClass($action_name);
1281 if (isset($action_obj['form_name']) == false) {
1282 $action_obj['form_name'] = $this->getDefaultFormClass($action_name);
1284 // ÌÀ¼¨»ØÄꤵ¤ì¤¿¥Õ¥©¡¼¥à¥¯¥é¥¹¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï·Ù¹ð
1285 $this->logger->log(LOG_WARNING, 'stated form class is not defined [%s]', $action_obj['form_name']);
1289 if (class_exists($action_obj['class_name']) == false) {
1290 $this->logger->log(LOG_WARNING, 'action class is not defined [%s]', $action_obj['class_name']);
1293 if (class_exists($action_obj['form_name']) == false) {
1294 // ¥Õ¥©¡¼¥à¥¯¥é¥¹¤Ï̤ÄêµÁ¤Ç¤âÎɤ¤
1295 $this->logger->log(LOG_DEBUG, 'form class is not defined [%s] -> falling back to default [%s]', $action_obj['form_name'], 'Ethna_ActionForm');
1296 $action_obj['form_name'] = 'Ethna_ActionForm';
1299 $action_obj['inspect'] = true;
1300 $action[$action_name] = $action_obj;
1301 return $action[$action_name];
1305 * ¥¢¥¯¥·¥ç¥ó̾¤È¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤«¤é¤ÎÌá¤êÃͤ˴ð¤Å¤¤¤ÆÁ«°ÜÀè¤ò·èÄꤹ¤ë
1308 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
1309 * @param string $retval ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤«¤é¤ÎÌá¤êÃÍ
1310 * @return string Á«°ÜÀè
1312 function _sortForward($action_name, $retval)
1318 * Á«°Ü̾¤«¤é¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹Ì¾¤ò¼èÆÀ¤¹¤ë
1321 * @param string $forward_name forward̾
1322 * @return string ¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹Ì¾
1324 function _getForwardPath($forward_name)
1326 $forward_obj = null;
1328 if (isset($this->forward[$forward_name]) == false) {
1330 $this->forward[$forward_name] = array();
1332 $forward_obj =& $this->forward[$forward_name];
1333 if (isset($forward_obj['forward_path']) == false) {
1335 $forward_obj['forward_path'] = $this->_getDefaultForwardPath($forward_name);
1338 return $forward_obj['forward_path'];
1342 * »ÈÍѸÀ¸ì¤òÀßÄꤹ¤ë
1344 * ¾Íè¤Ø¤Î³ÈÄ¥¤Î¤¿¤á¤Î¤ß¤Ë¸ºß¤·¤Æ¤¤¤Þ¤¹¡£¸½ºß¤ÏÆä˥ª¡¼¥Ð¡¼¥é¥¤¥É¤ÎɬÍפϤ¢¤ê¤Þ¤»¤ó¡£
1347 * @param string $language ¸À¸ìÄêµÁ(LANG_JA, LANG_EN...)
1348 * @param string $system_encoding ¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
1349 * @param string $client_encoding ¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
1351 function _setLanguage($language, $system_encoding = null, $client_encoding = null)
1353 $this->language = $language;
1354 $this->system_encoding = $system_encoding;
1355 $this->client_encoding = $client_encoding;
1357 $this->i18n->setLanguage($language, $system_encoding, $client_encoding);
1361 * ¥Ç¥Õ¥©¥ë¥È¾õÂ֤ǤλÈÍѸÀ¸ì¤ò¼èÆÀ¤¹¤ë
1364 * @return array »ÈÍѸÀ¸ì,¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾,¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
1366 function _getDefaultLanguage()
1368 return array(LANG_JA, null, null);
1372 * ¥Ç¥Õ¥©¥ë¥È¾õÂ֤ǤΥ¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤ò¼èÆÀ¤¹¤ë
1375 * @return int ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
1377 function _getDefaultClientType()
1379 if (is_null($GLOBALS['_Ethna_client_type']) == false) {
1380 return $GLOBALS['_Ethna_client_type'];
1382 return CLIENT_TYPE_WWW;
1386 * ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1388 * ¤¿¤À¤·¡¢¥¤¥ó¥¯¥ë¡¼¥É¤·¤¿¥Õ¥¡¥¤¥ë¤Ë¥¯¥é¥¹¤¬Àµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÏÊݾڤ·¤Ê¤¤
1391 * @param array $action_obj ¥¢¥¯¥·¥ç¥óÄêµÁ
1392 * @param string $action_name ¥¢¥¯¥·¥ç¥ó̾
1394 function _includeActionScript($action_obj, $action_name)
1396 $class_path = $form_path = null;
1398 $action_dir = $this->getActiondir();
1400 // class_path°À¥Á¥§¥Ã¥¯
1401 if (isset($action_obj['class_path'])) {
1402 if (file_exists($action_dir . $action_obj['class_path']) == false) {
1403 $this->logger->log(LOG_WARNING, 'class_path file not found [%s] -> try default', $action_obj['class_path']);
1405 include_once($action_dir . $action_obj['class_path']);
1406 $class_path = $action_obj['class_path'];
1410 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1411 if (is_null($class_path)) {
1412 $class_path = $this->getDefaultActionPath($action_name);
1413 if (file_exists($action_dir . $class_path)) {
1414 include_once($action_dir . $class_path);
1416 $this->logger->log(LOG_DEBUG, 'default action file not found [%s] -> try all files', $class_path);
1421 // Á´¥Õ¥¡¥¤¥ë¥¤¥ó¥¯¥ë¡¼¥É
1422 if (is_null($class_path)) {
1423 $this->_includeDirectory($this->getActiondir());
1427 // form_path°À¥Á¥§¥Ã¥¯
1428 if (isset($action_obj['form_path'])) {
1429 if ($action_obj['form_path'] == $class_path) {
1432 if (file_exists($action_dir . $action_obj['form_path']) == false) {
1433 $this->logger->log(LOG_WARNING, 'form_path file not found [%s] -> try default', $action_obj['form_path']);
1435 include_once($action_dir . $action_obj['form_path']);
1436 $form_path = $action_obj['form_path'];
1440 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1441 if (is_null($form_path)) {
1442 $form_path = $this->getDefaultFormPath($action_name);
1443 if ($form_path == $class_path) {
1446 if (file_exists($action_dir . $form_path)) {
1447 include_once($action_dir . $form_path);
1449 $this->logger->log(LOG_DEBUG, 'default form file not found [%s] -> maybe falling back to default form class', $form_path);
1455 * ¥Ó¥å¡¼¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1457 * ¤¿¤À¤·¡¢¥¤¥ó¥¯¥ë¡¼¥É¤·¤¿¥Õ¥¡¥¤¥ë¤Ë¥¯¥é¥¹¤¬Àµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÏÊݾڤ·¤Ê¤¤
1460 * @param array $forward_obj Á«°ÜÄêµÁ
1461 * @param string $forward_name Á«°Ü̾
1463 function _includeViewScript($forward_obj, $forward_name)
1465 $view_dir = $this->getViewdir();
1467 // view_path°À¥Á¥§¥Ã¥¯
1468 if (isset($action_obj['view_path'])) {
1469 if (file_exists($view_dir . $forward_obj['view_path']) == false) {
1470 $this->logger->log(LOG_WARNING, 'view_path file not found [%s] -> try default', $forward_obj['view_path']);
1472 include_once($action_dir . $forward_obj['view_path']);
1477 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1478 $view_path = $this->getDefaultViewPath($forward_name);
1479 if (file_exists($view_dir . $view_path)) {
1480 include_once($view_dir . $view_path);
1483 $this->logger->log(LOG_DEBUG, 'default view file not found [%s]', $view_path);
1489 * ¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤ÎÁ´¤Æ¤Î¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1493 function _includeDirectory($dir)
1495 $ext = "." . $this->ext['php'];
1496 $ext_len = strlen($ext);
1498 if (is_dir($dir) == false) {
1502 $dh = opendir($dir);
1504 while (($file = readdir($dh)) !== false) {
1505 if ($file != '.' && $file != '..' && is_dir("$dir/$file")) {
1506 $this->_includeDirectory("$dir/$file");
1508 if (substr($file, -$ext_len, $ext_len) != $ext) {
1511 include_once("$dir/$file");
1518 * ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¤Î¥Ç¥Õ¥©¥ë¥È¾õÂÖ¤òÀßÄꤹ¤ë
1521 * @param object Smarty $smarty ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¥ª¥Ö¥¸¥§¥¯¥È
1523 function _setDefaultTemplateEngine(&$smarty)
1528 * Ethna¥Þ¥Í¡¼¥¸¥ã¤òÀßÄꤹ¤ë(ÉÔÍפʾì¹ç¤Ï¶õ¤Î¥á¥½¥Ã¥É¤È¤·¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤Æ¤â¤è¤¤)
1532 function _activateEthnaManager()
1534 $base = dirname(dirname(__FILE__));
1536 if ($this->config->get('debug') == false) {
1541 $this->action['__ethna_info__'] = array(
1542 'form_name' => 'Ethna_Form_Info',
1543 'class_name' => 'Ethna_Action_Info',
1545 $this->action['__ethna_info_do__'] = array(
1546 'form_name' => 'Ethna_Form_InfoDo',
1547 'class_name' => 'Ethna_Action_InfoDo',
1551 $forward_obj = array();
1553 $forward_obj['forward_path'] = sprintf("%s/tpl/info.tpl", $base);
1554 $forward_obj['view_name'] = 'Ethna_Action_Info';
1555 $this->forward['__ethna_info__'] = $forward_obj;
1559 * Á«°Ü̾¤ËÂбþ¤¹¤ë¥Æ¥ó¥×¥ì¡¼¥È¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1561 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar"¤È¤¤¤¦forward̾¤¬"foo/bar" + ¥Æ¥ó¥×¥ì¡¼¥È³ÈÄ¥»Ò¤È¤Ê¤ë
1562 * ¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1565 * @param string $forward_name forward̾
1566 * @return string forward¥Ñ¥¹Ì¾
1568 function _getDefaultForwardPath($forward_name)
1570 return str_replace('_', '/', $forward_name) . '.' . $this->ext['tpl'];
1574 * ÀßÄê¥Õ¥¡¥¤¥ë¤ÎDSNÄêµÁ¤«¤é»ÈÍѤ¹¤ë¥Ç¡¼¥¿¤òºÆ¹½ÃÛ¤¹¤ë(¥¹¥ì¡¼¥Ö¥¢¥¯¥»¥¹Ê¬´ôÅù)
1576 * DSN¤ÎÄêµÁÊýË¡(¥Ç¥Õ¥©¥ë¥È:ÀßÄê¥Õ¥¡¥¤¥ë)¤òÊѤ¨¤¿¤¤¾ì¹ç¤Ï¤³¤³¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1579 * @return array DSNÄêµÁ
1581 function _prepareDSN()
1585 foreach ($this->db as $key => $value) {
1586 $config_key = "dsn";
1588 $config_key .= "_$key";
1590 $dsn = $this->config->get($config_key);
1591 if (is_array($dsn)) {
1592 // ¼ïÊÌ1¤Ä¤Ë¤Ä¤Ê£¿ôDSN¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¥¢¥¯¥»¥¹Ê¬´ô
1593 $dsn = $this->_selectDSN($key, $dsn);
1601 * DSN¤Î¥¢¥¯¥»¥¹Ê¬´ô¤ò¹Ô¤¦
1603 * ¥¹¥ì¡¼¥Ö¥µ¡¼¥Ð¤Ø¤Î¿¶Ê¬¤±½èÍý(¥Ç¥Õ¥©¥ë¥È:¥é¥ó¥À¥à)¤òÊѹ¹¤·¤¿¤¤¾ì¹ç¤Ï¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1606 * @param string $type DB¼ïÊÌ
1607 * @param array $dsn_list DSN°ìÍ÷
1608 * @return string ÁªÂò¤µ¤ì¤¿DSN
1610 function _selectDSN($type, $dsn_list)
1612 // ¥Ç¥Õ¥©¥ë¥È:¥é¥ó¥À¥à
1613 list($usec, $sec) = explode(' ', microtime());
1614 mt_srand($sec + ((float) $usec * 100000));
1615 $n = mt_rand(0, count($dsn_list)-1);
1617 return $dsn_list[$n];
1621 * ¥¢¥¯¥·¥ç¥ó̾¤¬¼Â¹Ôµö²Ä¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤«¤É¤¦¤«¤òÊÖ¤¹
1624 * @param string $action_name ¥ê¥¯¥¨¥¹¥È¤µ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾
1625 * @param array $default_action_name µö²Ä¤µ¤ì¤Æ¤¤¤ë¥¢¥¯¥·¥ç¥ó̾
1626 * @return bool true:µö²Ä false:ÉÔµö²Ä
1628 function _isAcceptableActionName($action_name, $default_action_name)
1630 foreach (to_array($default_action_name) as $name) {
1631 if ($action_name == $name) {
1633 } else if ($name{strlen($name)-1} == '*') {
1634 if (strncmp($action_name, substr($name, 0, -1), strlen($name)-1) == 0) {
1643 * ¥Õ¥£¥ë¥¿¡¼¥Á¥§¥¤¥ó¤òÀ¸À®¤¹¤ë
1647 function _createFilterChain()
1649 $this->filter_chain = array();
1650 foreach ($this->filter as $filter) {
1651 $file = sprintf("%s/%s.%s", $this->getDirectory('filter'), $filter, $this->getExt('php'));
1652 if (file_exists($file)) {
1653 include_once($file);
1655 if (class_exists($filter)) {
1656 $this->filter_chain[] =& new $filter($this);