/** * add view * * @access public */ function perform() { $r =& $this->_getopt(array('basedir=', 'skelfile=', 'template')); if (Ethna::isError($r)) { return $r; } list($opt_list, $arg_list) = $r; // view_name $view_name = array_shift($arg_list); if ($view_name == null) { return Ethna::raiseError('view name isn\'t set.', 'usage'); } $r =& Ethna_Controller::checkViewName($view_name); if (Ethna::isError($r)) { return $r; } // add view $ret =& $this->_perform('View', $view_name, $opt_list); if (Ethna::isError($ret) || $ret === false) { return $ret; } // add template if (isset($opt_list['template'])) { $ret =& $this->_perform('Template', $view_name, $opt_list); if (Ethna::isError($ret) || $ret === false) { return $ret; } } return true; }
/** * @access public */ function perform() { $args =& $this->_parseArgList(); if (Ethna::isError($args)) { return $args; } $pear =& new Ethna_PearWrapper(); if (isset($args['pearopt'])) { $pear->setPearOpt($args['pearopt']); } $target = isset($args['target']) ? $args['target'] : null; $channel = isset($args['channel']) ? $args['channel'] : null; $basedir = isset($args['basedir']) ? realpath($args['basedir']) : getcwd(); $r =& $pear->init($target, $basedir, $channel); if (Ethna::isError($r)) { return $r; } $r =& $pear->doClearCache(); if (Ethna::isError($r)) { return $r; } $r =& $pear->doChannelUpdate(); if (Ethna::isError($r)) { return $r; } return true; }
/** * @access protected */ function &_perform($target, $target_name, $opt_list) { // basedir if (isset($opt_list['basedir'])) { $basedir = realpath(end($opt_list['basedir'])); } else { $basedir = getcwd(); } // skelfile if (isset($opt_list['skelfile'])) { $skelfile = end($opt_list['skelfile']); } else { $skelfile = null; } // gateway if (isset($opt_list['gateway'])) { $gateway = 'GATEWAY_' . strtoupper(end($opt_list['gateway'])); if (defined($gateway)) { $gateway = constant($gateway); } else { return Ethna::raiseError('unknown gateway', 'usage'); } } else { $gateway = GATEWAY_WWW; } $r =& Ethna_Generator::generate($target, $basedir, $target_name, $skelfile, $gateway); if (Ethna::isError($r)) { printf("error occurred while generating skelton. please see also following error message(s)\n\n"); return $r; } $true = true; return $true; }
/** * commitTransaction * トランザクションを終了し、全ての変更をコミットする * * @return 成功時:true 失敗時:false */ public function CommitTransaction() { if (Ethna::isError($this->db->commit())) { return false; } return true; }
/** * show help * * @access public */ function perform() { $r = $this->_getopt(); if (Ethna::isError($r)) { return $r; } list($opt_list, $arg_list) = $r; // action_name $handle_name = array_shift($arg_list); if (!strlen($handle_name)) { $handler_list = $this->eh->getHandlerList(); printf("usage: ethna [option] [command] [args...]\n\n"); printf("available options are as follows:\n\n"); printf(" -v, --version show version and exit\n"); printf("\navailable commands are as follows:\n\n"); foreach ($handler_list as $handler) { printf(" %s\n", $handler->getId()); } return true; } // getHandler $handler = $this->eh->getHandler($handle_name); if (Ethna::isError($handler) || $handler === false) { // command not found return Ethna::raiseError('command not found.', 'usage'); } echo $handler->getDescription(); return true; }
/** * ビューを出力する * * @param string $template テンプレート名 * @param bool $capture true ならば出力を表示せずに返す * * @access public */ function perform($template = null, $capture = false) { if ($template === null && $this->template === null) { return Ethna::raiseWarning('template is not defined'); } if ($template !== null) { $this->template = $template; } if (!is_absolute_path($this->template)) { $this->template = sprintf('%s%s', $this->template_dir, $this->template); } if (is_readable($this->template)) { ob_start(); include $this->template; $captured = ob_get_contents(); ob_end_clean(); if ($capture === true) { return $captured; } else { echo $captured; } } else { return Ethna::raiseWarning('template not found ' . $this->template); } }
/** * @access protected */ function _perform($target) { $r =& $this->_getopt(array('basedir=')); if (Ethna::isError($r)) { return $r; } list($opt_list, $arg_list) = $r; // table_name $table_name = array_shift($arg_list); if ($table_name == null) { return Ethna::raiseError('table name isn\'t set.', 'usage'); } // basedir if (isset($opt_list['basedir'])) { $basedir = realpath(end($opt_list['basedir'])); } else { $basedir = getcwd(); } $r =& Ethna_Generator::generate($target, $basedir, $table_name); if (Ethna::isError($r)) { printf("error occurred while generating skelton. please see also following error message(s)\n\n"); return $r; } return true; }
/** * 最小値のチェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public function validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['min']) == false || $this->isEmpty($var, $type)) { return $true; } switch ($type) { case VAR_TYPE_INT: if ($var < $params['min']) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %d(int) to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_INT, array($params['min'])); } break; case VAR_TYPE_FLOAT: if ($var < $params['min']) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %f(float) to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_FLOAT, array($params['min'])); } break; case VAR_TYPE_DATETIME: $t_min = strtotime($params['min']); $t_var = strtotime($var); if ($t_var < $t_min) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input datetime value %s or later to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_DATETIME, array($params['min'])); } break; case VAR_TYPE_FILE: $st = stat($var['tmp_name']); if ($st[7] < $params['min'] * 1024) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please specify file whose size is more than %d KB.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_FILE, array($params['min'])); } break; case VAR_TYPE_STRING: $params['mbstrmin'] = $params['min']; unset($params['min']); $vld = $this->plugin->getPlugin('Validator', 'Mbstrmin'); return $vld->validate($name, $var, $params); break; } return $true; }
/** * @access public */ function perform() { $args =& $this->_parseArgList(); if (Ethna::isError($args)) { return $args; } $pear =& new Ethna_PearWrapper(); if (isset($args['pearopt'])) { $pear->setPearOpt($args['pearopt']); } if (isset($args['type']) && isset($args['name'])) { $target = isset($args['target']) ? $args['target'] : null; $channel = isset($args['channel']) ? $args['channel'] : null; $basedir = isset($args['basedir']) ? realpath($args['basedir']) : getcwd(); if ($target == 'master') { $pkg_name = sprintf('Ethna_Plugin_%s_%s', $args['type'], $args['name']); } else { $pkg_name = sprintf('App_Plugin_%s_%s', $args['type'], $args['name']); } $r =& $pear->init($target, $basedir, $channel); if (Ethna::isError($r)) { return $r; } $r =& $pear->doInfo($pkg_name); if (Ethna::isError($r)) { return $r; } } else { return Ethna::raiseError('invalid arguments', 'usage'); } return true; }
/** * add project:) * * @access public */ function perform() { $r = $this->_getopt(array('basedir=')); if (Ethna::isError($r)) { return $r; } list($opt_list, $arg_list) = $r; // app_id $app_id = array_shift($arg_list); if ($app_id == null) { return Ethna::raiseError('project id isn\'t set.', 'usage'); } $r = Ethna_Controller::checkAppId($app_id); if (Ethna::isError($r)) { return $r; } // basedir if (isset($opt_list['basedir'])) { $basedir = realpath(end($opt_list['basedir'])); } else { $basedir = getcwd(); } $r = Ethna_Generator::generate('Project', null, $app_id, $basedir); if (Ethna::isError($r)) { printf("error occurred while generating skelton. please see also error messages given above\n\n"); return $r; } printf("\nproject skelton for [%s] is successfully generated at [%s]\n\n", $app_id, $basedir); return true; }
function test_cmd_option() { // unrecognized option $r = $this->proj->runCmd('add-template', array('-k')); $this->assertTrue(Ethna::isError($r)); $this->assertEqual('unrecognized option -k', $r->getMessage()); // skel requires an argument $r = $this->proj->runCmd('add-template', array('-s')); $this->assertTrue(Ethna::isError($r)); $this->assertEqual('option -s requires an argument', $r->getMessage()); $r = $this->proj->runCmd('add-template', array('--skelfile')); $this->assertTrue(Ethna::isError($r)); $this->assertEqual('option --skelfile requires an argument', $r->getMessage()); // locale requires an argument $r = $this->proj->runCmd('add-template', array('-l')); $this->assertTrue(Ethna::isError($r)); $this->assertEqual('option -l requires an argument', $r->getMessage()); $r = $this->proj->runCmd('add-template', array('--locale')); $this->assertTrue(Ethna::isError($r)); $this->assertEqual('option --locale requires an argument', $r->getMessage()); // template name isn't set $r = $this->proj->runCmd('add-template', array()); $this->assertTrue(Ethna::isError($r)); $this->assertEqual('template name isn\'t set.', $r->getMessage()); // invalid locale $r = $this->proj->runCmd('add-template', array('-l', 'invalid::locale', 'test')); $this->assertTrue(Ethna::isError($r)); $this->assertEqual('You specified locale, but invalid : invalid::locale', $r->getMessage()); // normal command exexute $r = $this->proj->runCmd('add-template', array('-l', 'ja_JP', 'test')); $this->assertFalse(Ethna::isError($r)); }
function preforward() { $item_manager = $this->backend->getManager('Item'); $filter = array('price' => new Ethna_AppSearchObject(0, OBJECT_CONDITION_GE)); $order = array('price' => OBJECT_SORT_DESC); $offset = 0; $count = 10; $object_list_result = $item_manager->getObjectList('Item', $filter, $order, $offset, $count); if (Ethna::isError($object_list_result)) { $this->ae->addObject(null, $object_list_result); return; } $item_list = array(); foreach ($object_list_result[1] as $item_object) { if ($item_object->get('type') == ITEM_TYPE_BEER) { $type_name = 'ビール'; } else { if ($item_object->get('type') == ITEM_TYPE_SNACK) { $type_name = 'お菓子'; } } $item_tmp = $item_object->getNameObject(); $item_tmp['type_name'] = $type_name; $item_list[] = $item_tmp; } $this->af->setApp('item_list', $item_list); $this->session->start(); // omajinai $user_object = $this->backend->getObject('User', 'id', $this->session->get('id')); if ($user_object->isValid()) { $this->af->setApp('user', $user_object->getNameObject()); } }
/** * add action entry point * * @access public */ function perform() { $r = $this->_getopt(array('basedir=', 'skelfile=', 'gateway=')); if (Ethna::isError($r)) { return $r; } list($opt_list, $arg_list) = $r; // action_name $action_name = array_shift($arg_list); if ($action_name == null) { return Ethna::raiseError('action name isn\'t set.', 'usage'); } $r = Ethna_Controller::checkActionName($action_name); if (Ethna::isError($r)) { return $r; } // add entry point $ret = $this->_perform('EntryPoint', $action_name, $opt_list); if (Ethna::isError($ret) || $ret === false) { return $ret; } // add action (no effects if already exists.) $ret = $this->_perform('Action', $action_name, $opt_list); if (Ethna::isError($ret) || $ret === false) { return $ret; } return true; }
/** * Ethna_Errorクラスのコンストラクタ * * @access public * @param int $level エラーレベル * @param string $message エラーメッセージ * @param int $code エラーコード * @param array $userinfo エラー追加情報(エラーコード以降の全ての引数) */ function Ethna_Error($message = null, $code = null, $mode = null, $options = null) { $controller =& Ethna_Controller::getInstance(); if ($controller !== null) { $this->i18n =& $controller->getI18N(); } // $options以降の引数->$userinfo if (func_num_args() > 4) { $userinfo = array_slice(func_get_args(), 4); if (count($userinfo) == 1) { if (is_array($userinfo[0])) { $userinfo = $userinfo[0]; } else { if (is_null($userinfo[0])) { $userinfo = array(); } } } } else { $userinfo = array(); } // メッセージ補正処理 if (is_null($message)) { // $codeからメッセージを取得する $message = $controller->getErrorMessage($code); if (is_null($message)) { $message = 'unkown error'; } } parent::PEAR_Error($message, $code, $mode, $options, $userinfo); // Ethnaフレームワークのエラーハンドラ(PEAR_Errorのコールバックとは異なる) Ethna::handleError($this); }
/** * スケルトンを削除する * * @access public * @param string $type 生成する対象 * @param string $app_dir アプリケーションのディレクトリ * (nullのときはアプリケーションを特定しない) * @param mixed residue プラグインのremove()にそのまま渡す * @static */ function &remove() { $arg_list = func_get_args(); $type = array_shift($arg_list); $app_dir = array_shift($arg_list); if ($app_dir === null) { $ctl =& Ethna_Handle::getEthnaController(); } else { $ctl =& Ethna_Handle::getAppController($app_dir); } if (Ethna::isError($ctl)) { return $ctl; } $plugin_manager =& $ctl->getPlugin(); if (Ethna::isError($plugin_manager)) { return $plugin_manager; } $generator =& $plugin_manager->getPlugin('Generator', $type); if (Ethna::isError($generator)) { return $generator; } // 引数はプラグイン依存とする $ret = call_user_func_array(array(&$generator, 'remove'), $arg_list); return $ret; }
/** * @access public */ function perform() { $r = $this->_getopt(array('basedir=', 'type=', 'plugin-package')); if (Ethna::isError($r)) { return $r; } list($opt_list, $arg_list) = $r; // plugin name $plugin_name = array_shift($arg_list); if (empty($plugin_name)) { return Ethna::raiseError('Please specify plugin Name.', 'usage'); } // plugin types $type = end($opt_list['type']); $types = explode(',', $type); if (empty($type)) { $types = array('v', 'f', 'sm'); // Validator, Filter, Smarty modifier. } // basedir if (isset($opt_list['basedir'])) { $basedir = realpath(end($opt_list['basedir'])); } else { $basedir = getcwd(); } // no-ini file flag. $forpackage = isset($opt_list['plugin-package']) ? true : false; $r = Ethna_Generator::generate('CreatePlugin', NULL, $basedir, $types, $forpackage, $plugin_name); if (Ethna::isError($r)) { printf("error occurred while generating plugin skelton. please see also error messages given above\n\n"); return $r; } printf("\nplugin skelton for [%s] is successfully generated.\n\n", $plugin_name); return true; }
function perform() { $item_id = $this->af->get('id'); $item_object = $this->backend->getObject('Item', 'id', $item_id); $item_count = $this->af->get('count'); $sugoi_manager = $this->backend->getManager('Sugoi'); $login_user_object = $sugoi_manager->getLoginUserObject(); // 本当はベースクラスの authenticate() ですべき if (Ethna::isError($login_user_object)) { $this->ae->addObject(null, $login_user_object); return 'error'; } // Confirm でもやってるけど、ずるするやついるので $validate_result = $sugoi_manager->validateShop($login_user_object, $item_object, $item_count); if (Ethna::isError($validate_result)) { $this->ae->addObject(null, $validate_result); return 'error'; } $sugoi_manager->db->begin(); // ここのインデントは本当はいらないです。が、個人的にトランザクション中であることが分かりやすいようにブロックで囲みます。 $update_result = $sugoi_manager->completeShop($login_user_object, $item_object, $item_count, true); if (Ethna::isError($update_result)) { $this->ae->addObject(null, $update_result); return 'error'; // エラーしたらここで perform() が終了するので commit() は呼び出されない。めでたし。 } $sugoi_manager->db->commit(); $this->af->setApp('user', $login_user_object->getNameObject()); $this->af->setApp('item', $item_object->getNameObject()); $this->af->setApp('cost', $item_object->getCost($item_count)); return 'good_shop_complete'; }
/** * コマンドの実装部分 * * テストケースファイル生成を行う * * @access protected * @return mixed 実行結果: TRUE: 成功 * Ethna_Error: エラー */ function &perform() { // get args. $r = $this->_getopt(array('basedir=', 'skelfile=')); if (Ethna::isError($r)) { return $r; } list($optlist, $arglist) = $r; $num = count($arglist); if ($num < 1 || $num > 3) { return Ethna::raiseError("Invalid Arguments.", 'usage'); } if (isset($optlist['skelfile'])) { $skelfile = end($optlist['skelfile']); } else { $skelfile = null; } $baseDir = isset($optlist['basedir']) ? $optlist['basedir'] : getcwd(); $name = $arglist[0]; $r =& Ethna_Generator::generate('Test', $baseDir, $skelfile, $name); if (Ethna::isError($r)) { return $r; } $true = true; return $true; }
/** * generate message catalog. * * @access public */ function perform() { $r = $this->_getopt(array('basedir=', 'locale=', 'gettext')); if (Ethna::isError($r)) { return $r; } list($opt_list, $arg_list) = $r; // basedir if (isset($opt_list['basedir'])) { $basedir = realpath(end($opt_list['basedir'])); } else { $basedir = getcwd(); } // locale if (isset($opt_list['locale'])) { $locale = end($opt_list['locale']); if (!preg_match('/^[A-Za-z_]+$/', $locale)) { return Ethna::raiseError("You specified locale, but invalid : {$locale}", 'usage'); } } else { $locale = 'ja_JP'; // default locale. } // use gettext ? $use_gettext = isset($opt_list['gettext']) ? true : false; // generate message catalog. $ret =& Ethna_Generator::generate('I18n', $basedir, $locale, $use_gettext, $arg_list); if (Ethna::isError($ret)) { printf("error occurred while generating skelton. please see also following error message(s)\n\n"); return $ret; } return $ret; }
/** * 最大値のチェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ * @return true: 成功 Ethna_Error: エラー */ public function validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['strmaxcompat']) == false || $this->isEmpty($var, $type)) { return $true; } $ctl = $this->backend->getController(); $client_enc = $ctl->getClientEncoding(); if (mb_enabled() && (strcasecmp('EUC-JP', $client_enc) != 0 && strcasecmp('eucJP-win', $client_enc) != 0)) { $var = mb_convert_encoding($var, 'EUC-JP', $client_enc); } if ($type == VAR_TYPE_STRING) { $max_param = $params['strmaxcompat']; if (strlen($var) > $max_param) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input less than %d full-size (%d half-size) characters to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MAX_STRING, array(intval($max_param / 2), $max_param)); } } return $true; }
function preFilter() { $db_list = $this->_getDBList(); if (Ethna::isError($db_list) || is_null($db_list)) { $this->logger->log(LOG_INFO, 'WARNING: DB connection failed.'); // return 'maintenance'; } }
/** * ユーザの支払能力をチェックします * * @param int $value * @return int */ public function isMoneyAvailable($value = 0) { $current_money = $this->get('money'); if ($current_money < $value) { return Ethna::raiseNotice('そんなお金ないです。'); } return $current_money; }
public function getUser($id) { $ret = $this->db->getRow(sprintf('SELECT * FROM %s WHERE id = ?', $this->_table), $id); if (Ethna::isError($ret)) { return array(); } return $ret; }
function preforward() { $sugoi_manager = $this->backend->getManager('Sugoi'); $login_user_object = $sugoi_manager->getLoginUserObject(); if (!Ethna::isError($login_user_object)) { $this->af->setApp('user', $login_user_object->getNameObject()); } }
function perform() { $item_id = $this->af->get('id'); $item_count = $this->af->get('count'); $this->session->start(); // omajinai $user_object = $this->backend->getObject('User', 'id', $this->session->get('id')); if (!$user_object->isValid()) { $this->ae->add(null, '会員になってね'); return 'error'; } $item_object = $this->backend->getObject('Item', 'id', $item_id); if (!$item_object->isValid()) { $this->ae->add(null, 'おまー! URL のパラメータ書き換えたろ!'); return 'error'; } // お金はあるかね $amount = $item_object->get('price') * $item_count; if ($user_object->get('money') < $amount) { $this->ae->add(null, 'お金ないんでしょ。冷やかしはやめてね。'); return 'error'; } // ネンレーカクニンガヒツヨーナショーヒンデス $user_age = $user_object->get('age'); if ($item_object->get('type') == ITEM_TYPE_BEER && $user_age < 20) { $this->ae->add(null, 'ビールはハタチになってから!'); return 'error'; } // 食いしん坊はダメっすよ if ($item_object->get('type') == ITEM_TYPE_SNACK) { $item_manager = $this->backend->getManager('Item'); $snack_item_id_list = $item_manager->getItemIdListByType(ITEM_TYPE_SNACK); // ↑ これ Action 側に展開すると解説の腰をへし折ってしまうレベルでバッドになるのでやめました。 if (Ethna::isError($snack_item_id_list)) { $this->ae->addObject(null, $snack_item_id_list); return 'error'; } $user_item_manager = $this->backend->getManager('UserItem'); $filter = array('item_id' => new Ethna_AppSearchObject($snack_item_id_list, OBJECT_CONDITION_EQ)); $filter['item_id']->addObject('user_id', new Ethna_AppSearchObject($user_object->get('id'), OBJECT_CONDITION_EQ), OBJECT_CONDITION_AND); $snack_stock_result = $user_item_manager->getObjectList('UserItem', $filter, null, 0, 0); if (Ethna::isError($snack_stock_result)) { $this->ae->addObject(null, $snack_stock_result); return 'error'; } $snack_stock_count = $item_count + $snack_stock_result[0]; if ($snack_stock_count > 10) { $this->ae->add(null, 'お菓子はおひとりさま十個限り!'); return 'error'; } } $this->af->setApp('item', $item_object->getNameObject()); $this->af->setApp('user', $user_object->getNameObject()); $this->af->setApp('cost', $amount); return 'bad_shop_confirm'; }
/** * エラーオブジェクトを生成/追加する * * @access public * @param string $name エラーの発生したフォーム項目名(不要ならnull) * @param string $message i18n翻訳後のエラーメッセージ * @param int $code エラーコード * @return Ethna_Error エラーオブジェクト */ public function add($name, $message, $code = null) { if (func_num_args() > 3) { $userinfo = array_slice(func_get_args(), 3); $error = Ethna::raiseNotice($message, $code, $userinfo); } else { $error = Ethna::raiseNotice($message, $code); } $this->addObject($name, $error); return $error; }
function perform() { $item_manager = $this->backend->getManager('Item'); $item_manager->db->begin(); $import_result = $item_manager->import(BASE . '/schema/item.csv'); if (Ethna::isError($import_result)) { return null; } $item_manager->db->commit(); return null; }
/** * エントリポイントのスケルトンを生成する * * @access public * @param string $skelton スケルトンファイル名 * @param int $gateway ゲートウェイ * @return true|Ethna_Error true:成功 Ethna_Error:失敗 */ function &generate($action_name, $skelton = null, $gateway = GATEWAY_WWW) { $true = true; // entity switch ($gateway) { case GATEWAY_WWW: $entity = sprintf("%s/%s.%s", $this->ctl->getDirectory('www'), $action_name, $this->ctl->getExt('php')); break; case GATEWAY_CLI: $entity = sprintf("%s/%s.%s", $this->ctl->getDirectory('bin'), $action_name, $this->ctl->getExt('php')); break; default: $ret = Ethna::raiseError('add-entry-point accepts only GATEWAY_WWW or GATEWAY_CLI.'); return $ret; } // skelton if ($skelton === null) { switch ($gateway) { case GATEWAY_WWW: $skelton = 'skel.entry_www.php'; break; case GATEWAY_CLI: $skelton = 'skel.entry_cli.php'; break; } } if (file_exists($entity)) { printf("file [%s] already exists -> skip\n", $entity); return $true; } // macro $macro = array(); $macro['project_id'] = $this->ctl->getAppId(); $macro['action_name'] = $action_name; $macro['dir_app'] = $this->ctl->getDirectory('app'); // user macro $user_macro = $this->_getUserMacro(); $macro = array_merge($macro, $user_macro); // generate $ret = $this->_generateFile($skelton, $entity, $macro); if ($ret) { printf("action script(s) successfully created [%s]\n", $entity); } else { printf("[warning] file creation failed [%s]\n", $entity); return $true; // XXX: error handling } // chmod if ($gateway === GATEWAY_CLI) { // is needed? //$ret = Ethna_Util::chmod($entity, 0777); } return $true; }
/** * フォーム値の型チェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public function validate($name, $var, $params) { $true = true; $type = $params['type']; if ($type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } foreach (array_keys(to_array($var)) as $key) { switch ($type) { case VAR_TYPE_INT: if (!preg_match('/^-?\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input integer value to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_INT); } break; case VAR_TYPE_FLOAT: if (!preg_match('/^-?\\d+$/', $var) && !preg_match('/^-?\\d+\\.\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input float value to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FLOAT); } break; case VAR_TYPE_BOOLEAN: if ($var != "1" && $var != "0") { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('You can input 0 or 1 to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_BOOLEAN); } break; case VAR_TYPE_DATETIME: $r = strtotime($var); if ($r == -1 || $r === false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input valid datetime to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_DATETIME); } break; } } return $true; }
/** * フォーム値の型チェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; $type = $params['type']; if ($type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } foreach (array_keys(to_array($var)) as $key) { switch ($type) { case VAR_TYPE_INT: if (!preg_match('/^-?\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には数字(整数)を入力して下さい"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_INT); } break; case VAR_TYPE_FLOAT: if (!preg_match('/^-?\\d+$/', $var) && !preg_match('/^-?\\d+\\.\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には数字(小数)を入力して下さい"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FLOAT); } break; case VAR_TYPE_BOOLEAN: if ($var != "1" && $var != "0") { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には1または0のみ入力できます"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_BOOLEAN); } break; case VAR_TYPE_DATETIME: $r = strtotime($var); if ($r == -1 || $r === false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には日付を入力して下さい"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_DATETIME); } break; } } return $true; }