/** * 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; }
/** * commitTransaction * トランザクションを終了し、全ての変更をコミットする * * @return 成功時:true 失敗時:false */ public function CommitTransaction() { if (Ethna::isError($this->db->commit())) { return false; } return true; }
/** * @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; }
/** * @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; }
/** * @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 * @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; }
/** * スケルトンを削除する * * @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; }
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()); } }
/** * 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; }
/** * check arguments * * @access private */ function _validateArgList() { $arg_list = array(); if (count($this->arg_list) < 1) { return Ethna::raiseError('too few argments', 'usage'); } else { if (count($this->arg_list) > 2) { return Ethna::raiseError('too many argments', 'usage'); } else { if (count($this->arg_list) == 1) { $arg_list[] = $this->arg_list[0]; $arg_list[] = getcwd(); } else { $arg_list = $this->arg_list; } } } $r = Ethna_Controller::checkAppId($arg_list[0]); if (Ethna::isError($r)) { return $r; } if (is_dir($arg_list[1]) == false) { return Ethna::raiseError("no such directory [{$arg_list[1]}]"); } return $arg_list; }
/** * 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; }
/** * 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; }
/** * @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; }
/** * 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; }
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 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 */ 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; }
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'; } }
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()); } }
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; }
/** * get handler object * * @access public */ function &getHandler($id) { $name = preg_replace('/\\-(.)/e', "strtoupper('\$1')", ucfirst($id)); $handler =& $this->plugin->getPlugin('Handle', $name); if (Ethna::isError($handler)) { return $handler; } return $handler; }
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'; }
/** * board_delete action implementation. * * @access public * @return string forward name. */ public function perform() { $bm = new BoardManager(); $res = $bm->delete($this->backend, $this->af->get('id')); if (Ethna::isError($res)) { $this->ae->addObject('DeleteError', $res); } else { $this->redirect('board'); } return 'board'; }
/** * setting_do action implementation. * * @access public * @return string forward name. */ public function perform() { $um = $this->backend->getManager('user'); $user = $this->session->get('user'); if (Ethna::isError($um->updateNickname($user['id'], $this->af->get('nickname')))) { return 'error500'; } $user['nickname'] = $this->af->get('nickname'); $this->session->set('user', $user); return array('redirect', 'setting'); }
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; }
/** * ユーザの所持金を減らします。 * 指定した額より所持金が少ない場合は Ethna_Error を返します。 * * @param int $value * @param boolean $update */ public function decreaseMoney($value, $update = false) { $money_available_result = $this->isMoneyAvailable($value); if (Ethna::isError($money_available_result)) { return $money_available_result; } $this->set('money', $money_available_result - $value); if ($update) { return $this->update(); } }
/** * get handler object * * @access public */ public function getHandler($id) { $name = preg_replace_callback('/\\-(.)/', function (array $matches) { return strtoupper($matches[1]); }, ucfirst($id)); $handler = $this->plugin->getPlugin('Handle', $name); if (Ethna::isError($handler)) { return $handler; } return $handler; }
/** * user-info action implementation. * * @access public * @return string forward name. */ public function perform() { $um = new UserManager(); $id = $this->af->get('id'); $res = $um->userdelete($this->backend, $id); if (Ethna::isError($res)) { (new JsonResponse(array('error' => (string) $res, 400)))->send(); } else { $userlist = $um->userlist($this->backend); (new JsonResponse(array('users' => $userlist), 200))->send(); } return null; }
/** * Ethna_Configクラスのコンストラクタ * * @access public * @param object Ethna_Controller $controller controllerオブジェクト */ public function __construct($controller) { $this->controller = $controller; // 設定ファイルの読み込み $r = $this->_getConfig(); if (Ethna::isError($r)) { // この時点ではlogging等は出来ない(Loggerオブジェクトが生成されていない) $fp = fopen("php://stderr", "r"); fputs($fp, sprintf("error occured while reading config file(s) [%s]\n"), $r->getInfo(0)); fclose($fp); $this->controller->fatal(); } }
/** * delete action implementation. * * @access public * @return string forward name. */ public function perform() { if (!$this->session->isStart()) { return "needlogin"; } $um = new UserManager(); $result = $um->userdelete($this->backend, $this->af->get("mailaddress")); if (Ethna::isError($result)) { //$this->ae->addObject("loginError",$result); return 'userlist'; } return 'userlist'; }