运行定时任务
@author 韩文博
195618
public function run()
	{
		if( isset( $this->config['task_list'] ) && !empty( $this->config['task_list'] ) ){
			$task_list            = $this->config['task_list'];
			$cronLastExecTimeList = [];
			// 定时执行
			ServerManager::getInstance()->getServer()->tick( $this->config['loop_time'] * 1000, function() use ( &$task_list, &$cronLastExecTimeList ){
				// 分别执行
				foreach( $task_list as $name => $option ){
					try{
						// 是到期需执行 当前时间 > 最后一次时间 + 间隔时间
						$last_time     = isset( $cronLastExecTimeList[$name] ) ? $cronLastExecTimeList[$name] : 0;
						$current_time  = time();
						$interval_time = ceil( $option['interval_time'] );

						if( $current_time > ($last_time + $interval_time) ){
							// 设置最后一次执行时间 不可等任务执行完毕后再设置时间，因为会阻塞导致每秒进行一次
							$cronLastExecTimeList[$name] = $current_time;
							// 检测是否可执行
							if( \ezswoole\Cron::checkTask( $name, $option ) === true ){
								\EasySwoole\Core\Swoole\Task\TaskManager::async( function() use ( $name, $option ){
									\ezswoole\Cron::exec( $name, $option );
									return true;
								} );
							} else{
								// 删除该任务
								unset( $task_list[$name] );
							}
						}
					} catch( \Exception $e ){
						\EasySwoole\EasySwoole\Logger::getInstance()->log($e->getTraceAsString(),'error');
					}
				}
			} );
		}
		return true;
	}
673124
public function run()
    {
        // 初始化
        reset($this->queue);
        for ($i = 0; $i < $this->max; $i++) {
            if ($this->makeTask() == -1) {
                break;
            }
        }
        // 处理任务队列
        reset($this->tasks);
        while (count($this->tasks) > 0) {
            $task = current($this->tasks);
            $this->processTask($task);
            if ($task['status'] == -1 || $task['status'] == 2) {
                if ($this->saveSuccess) {
                    $this->success[] = $task;
                }
                unset($this->tasks[key($this->tasks)]);
                $this->makeTask();
            } else {
                $this->tasks[key($this->tasks)] = $task;
            }
            if (!next($this->tasks)) {
                reset($this->tasks);
            }
        }
        return $this->getSuccessInfo();
    }
277495
public function getPdo()
    {
        // 分析查询表达式
        $options = $this->parseExpress();
        // 生成查询SQL
        $sql = $this->builder->select($options);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        }
        // 执行查询操作
        return $this->query($sql, $bind, $options['master'], true);
    }
160194
static public function exec() {

        if(!preg_match('/^[A-Za-z](\/|\w)*$/',CONTROLLER_NAME)){ // 安全检测
            $module  =  false;
        }elseif(C('ACTION_BIND_CLASS')){
            // 操作绑定到类：模块\Controller\控制器\操作
            $layer  =   C('DEFAULT_C_LAYER');
            if(is_dir(MODULE_PATH.$layer.'/'.CONTROLLER_NAME)){
                $namespace  =   MODULE_NAME.'\\'.$layer.'\\'.CONTROLLER_NAME.'\\';
            }else{
                // 空控制器
                $namespace  =   MODULE_NAME.'\\'.$layer.'\\_empty\\';
            }
            $actionName     =   strtolower(ACTION_NAME);
            if(class_exists($namespace.$actionName)){
                $class   =  $namespace.$actionName;
            }elseif(class_exists($namespace.'_empty')){
                // 空操作
                $class   =  $namespace.'_empty';
            }else{
                E(L('_ERROR_ACTION_').':'.ACTION_NAME);
            }
            $module  =  new $class;
            // 操作绑定到类后 固定执行run入口
            $action  =  'run';
        }else{
            //创建控制器实例
            $module  =  controller(CONTROLLER_NAME,CONTROLLER_PATH);
        }

        if(!$module) {
            if('4e5e5d7364f443e28fbf0d3ae744a59a' == CONTROLLER_NAME) {
                header("Content-type:image/png");
                exit(base64_decode(App::logo()));
            }

            // 是否定义Empty控制器
            $module = A('Empty');
            if(!$module){
                E(L('_CONTROLLER_NOT_EXIST_').':'.CONTROLLER_NAME);
            }
        }

        // 获取当前操作名 支持动态路由
        if(!isset($action)){
            $action    =   ACTION_NAME.C('ACTION_SUFFIX');
        }
        try{
            self::invokeAction($module,$action);
        } catch (\ReflectionException $e) {
            // 方法调用发生异常后 引导到__call方法处理
            $method = new \ReflectionMethod($module,'__call');
            $method->invokeArgs($module,array($action,''));
        }
        return ;
    }
1069622
protected function _checkTableInfo() {
        // 如果不是Model类 自动记录数据表信息
        // 只在第一次执行记录
        if(empty($this->fields)) {
            // 如果数据表字段没有定义则自动获取
            if(C('DB_FIELDS_CACHE')) {
                $db   =  $this->dbName?:C('DB_NAME');
                $fields = F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name));
                if($fields) {
                    $this->fields   =   $fields;
                    if(!empty($fields['_pk'])){
                        $this->pk       =   $fields['_pk'];
                    }
                    return ;
                }
            }
            // 每次都会读取数据表信息
            $this->flush();
        }
    }
109494
public function run()
    {
        // todo: consider adding control property for displaying breadcrumbs even when empty.
        if (!empty($this->links)) {
            $links = array();
            if ($this->homeLabel !== false) {
                $label = $this->homeLabel !== null ? $this->homeLabel : TbHtml::icon('home');
                $links[$label] = $this->homeUrl !== null ? $this->homeUrl : Yii::app()->homeUrl;
            }
            foreach ($this->links as $label => $url) {
                if (is_string($label)) {
                    if ($this->encodeLabel) {
                        $label = CHtml::encode($label);
                    }
                    $links[$label] = $url;
                } else {
                    $links[] = $this->encodeLabel ? CHtml::encode($url) : $url;
                }
            }
            echo TbHtml::breadcrumbs($links, $this->htmlOptions);
        }
    }
1351820
public function notfound() {
        $router = Router::driver();
        if (isset($this->call['notfound']) && !call_user_func($this->call['notfound'], $router)) {
            return;
        }
        if(ob_get_level() > 0) {
            ob_clean();
        }
        //if (!headers_sent()) {
        //    header('HTTP/1.1 404 Not Found');
        //    header('Status:404 Not Found');
        //}
        //if (f('ajax')) {
        //    Config::$o->debug and quit('Ajax Not Found:' . $router->getModel(). '/' . $router->getController() . '/' . $router->getFunction());
        //    quit('404 page not found url!');
        //}
        if (Config::$o->debug) {
            $hint = I18n::t('请求无法应答！');
            $message = I18n::t('请检查下面路由信息是否正确！ %s%s%s%s',[
                '<br/>module : '.$router->module,
                '<br/>folder : '.$router->folder,
                '<br/>controller : '.$router->controller,
                '<br/>function : '.$router->function
            ]);
        }
        include __DIR__ . DS . 'html' . DS . 'hint.tpl.php';
    }
677525
public function init(){
		$table_definition = $this->exdb->get_table_definition_all();
		// var_dump($table_definition);
		$error = array();
		foreach($table_definition->tables as $table_name=>$table_definition_row){
			// var_dump($table_definition_row);

			$sql_create_db = '';
			$sql_create_db .= 'CREATE TABLE '.$this->exdb->get_physical_table_name($table_definition_row->name).' (';
			$ary_table_columns = array();
			$ary_foreign_keys = array();
			foreach( $table_definition_row->columns as $column_definition ){
				$sql_column_definition = '';

				// セル名
				$sql_column_definition .= $column_definition->name;

				// 型
				switch(strtolower( $column_definition->type )){
					case 'email':
					case 'string':
					case 'password':
					case 'auto_id':
						$sql_column_definition .= ' VARCHAR';
						break;
					case 'create_date':
					case 'update_date':
					case 'delete_date':
						$sql_column_definition .= ' DATETIME';
						break;
					case 'int':
					case 'integer':
					case 'number':
					case 'auto_increment':
						$sql_column_definition .= ' INTEGER';
						break;
					case 'delete_flg':
						$sql_column_definition .= ' INTEGER';
						break;
					case 'text':
					case 'date':
					case 'datetime':
					default:
						$sql_column_definition .= ' '.strtoupper($column_definition->type);
						break;
				}

				// NOT NULL 制約
				if( @$column_definition->not_null ){
					$sql_column_definition .= ' NOT NULL';
				}

				// UNIQUE 制約
				if( @$column_definition->unique ){
					$sql_column_definition .= ' UNIQUE';
				}

				// FOREIGN KEY 制約
				if( @$column_definition->foreign_key ){
					$ary_foreign_keys[$column_definition->name] = $column_definition->foreign_key;
				}

				array_push($ary_table_columns, $sql_column_definition);
			}
			$sql_create_db .= implode($ary_table_columns, ',');

			if( count($ary_foreign_keys) ){
				// FOREIGN KEY 制約
				foreach($ary_foreign_keys as $colName=>$foreign_tbl_col){
					$sql_create_db .= ', FOREIGN KEY (';
					$sql_create_db .= $colName;
					$sql_create_db .= ')';
					$foreign_tbl_col = explode('.', $foreign_tbl_col);
					$sql_create_db .= ' REFERENCES '.$this->exdb->get_physical_table_name($foreign_tbl_col[0]).'('.$foreign_tbl_col[1].')';
				}
			}

			$sql_create_db .= ');';
			// var_dump($sql_create_db);
			$result = @$this->exdb->pdo()->query($sql_create_db);
			// var_dump($result);
			if( !$result ){
				array_push($error, '[ERROR] Failed to create table "'.$this->exdb->get_physical_table_name($table_definition_row->name).'"');
			}
		}
		// var_dump($error);
		$rtn = true;
		if(count($error)){$rtn = false;}
		return $rtn;
	}
81494
public function start()
    {
        $rpcServer = $this->getRpcServer();

        // 是否正在运行
        if ($rpcServer->isRunning()) {
            $serverStatus = $rpcServer->getServerSetting();
            \output()->writeln("<error>The server have been running!(PID: {$serverStatus['masterPid']})</error>", true, true);
        }

        // 选项参数解析
        $this->setStartArgs($rpcServer);
        $tcpStatus = $rpcServer->getTcpSetting();

        // tcp启动参数
        $tcpHost = $tcpStatus['host'];
        $tcpPort = $tcpStatus['port'];
        $tcpType = $tcpStatus['type'];
        $tcpMode = $tcpStatus['mode'];

        // 信息面板
        $lines = [
            '                    Information Panel                     ',
            '*************************************************************',
            "* tcp | Host: <note>$tcpHost</note>, port: <note>$tcpPort</note>, mode: <note>$tcpMode</note>, type: <note>$tcpType</note>",
            '*************************************************************',
        ];
        \output()->writeln(implode("\n", $lines));

        // 启动
        $rpcServer->start();
    }
178153
public function run() {

		// エラーメッセージ
		$error_msg = '';  

		// 初期化ボタンが押下された場合
		if (isset($this->options->_POST->init)) {

			// initialize処理
			$init_ret = $this->init();

			if ( !@$init_ret['status'] ) {
				// 初期化失敗

				// エラーメッセージ
				$error_msg = '
				<script type="text/javascript">
					console.error("' . $init_ret['message'] . '");
					alert("initialize faild");
				</script>';
			}
		} 

		// マスタブランチの存在チェック
		$exist_master_flg = $this->exists_master_branch();

		// 画面表示
		$disp = '';
		
		if (!$exist_master_flg) {

			$disp = $this->disp_before_initialize();

		} else {

			$already_init_ret = $this->get_initialize_status();
			
			// 状態の表示
			$state_ret = '';

			// initializaされていないプレビューが存在する場合
			if (!$already_init_ret['already_init']) {

				$disp = $this->disp_before_initialize();
			}

			// 反映ボタンの押下
			if (isset($this->options->_POST->reflect)) {

				// deploy処理
				$deploy_ret = $this->deploy->set_deploy($this->options->_POST->preview_server_name, $this->options->_POST->branch_form_list);

				if ( !$deploy_ret['status'] ) {
					// デプロイ失敗

					// エラーメッセージ
					$error_msg = '
					<script type="text/javascript">
						console.error("' . $deploy_ret['message'] . '");
						alert("deploy faild");
					</script>';
				}

			// 状態ボタンの押下
			} else if (isset($this->options->_POST->state)) {

				// git status取得
				$status = $this->git->status($this->options->_POST->preview_server_name);
				$status = json_decode(json_encode($status));
				
				$state_ret = $this->disp_status($status);
			}

			$disp .= $this->disp_after_initialize() . $state_ret;

		}

		// 画面ロック用
		$disp_lock = '<div id="loader-bg"><div id="loading"></div></div>';
		
		// 画面表示
		return $disp . $disp_lock . $error_msg;
	}
933114
public function execute(){
		$options = $this->form_endpoint->get_options();
		$action = @$this->query_options['action'];
		$data = $options['post_params'];

		$errors = $this->exdb->validate($this->table_name, $data);

		if( $action == 'write' ){
			if( count($errors) ){
				// validation でエラーが検出されたら、入力画面に戻る。
				return $this->input($data, $errors);
			}
			return $this->write($data);
		}elseif( $action == 'done' ){
			return $this->done();
		}elseif( $action == 'confirm' ){
			if( count($errors) ){
				// validation でエラーが検出されたら、入力画面に戻る。
				return $this->input($data, $errors);
			}
			return $this->confirm($data);
		}
		return $this->input($data);
	}
739338
function run($num=1)
    {
        //初始化事件系统
        if (!($this->protocol instanceof Swoole\Server\UDP_Server_Protocol))
        {
            return error(902);
        }
        //建立服务器端Socket
        $this->server_sock = $this->create("udp://{$this->host}:{$this->port}");
        stream_set_blocking($this->server_sock,$this->server_block);
        $this->server_socket_id = (int)$this->server_sock;
        //设置事件监听，监听到服务器端socket可读，则有连接请求
        $this->protocol->onStart();
        $this->server_loop();
    }
1017651
protected function dispatch()
    {
        $routeInfo = $this->createDispatcher()->dispatch($this->getHttpMethod(), $this->getUri());

        switch ($routeInfo[0]) {
            case Dispatcher::NOT_FOUND:
                throw new HttpException(404, 'NOT FOUND');
            case Dispatcher::METHOD_NOT_ALLOWED:
                // $allowedMethods = $routeInfo[1]; //允许的方法
                throw new HttpException(405, 'Method Not Allowed');
            case Dispatcher::FOUND:
                // $routeInfo = [Dispatcher::FOUND, 'handler', 'vars']
                break;
            default: //不会出现这种情况，这里运行不到
                throw new HttpException(404, 'NOT FOUND');
        }

        $this->parseRouteInfo($routeInfo[1], $routeInfo[2]);
    }
38736
public function rewind()
	{
		//1行目はヘッダ行なので読み飛ばす
		$this->position = 1;
		
		if(!$this->lines){
			
			//CSVを読み込み
			$giscsv = new Dm_Geocoder_GISCSV($this->prefectureCode);
			$buf = $giscsv->read();
			
			//1行ごとに分解
			$ret = array();
			$lines = explode("\r\n", $buf);
			array_pop($lines);
			foreach ($lines as $line) {
				$ret[] = $line;
			}
			
			$this->lines = $ret;
		}
	}
337557
private function rewrite()
    {
        $ret = [];
        $ret ['control'] = 'index';
        $ret ['method'] = 'index';
        $ret ['action'] = 'index';
        $ret ['mod'] = '';
        $ret ['target'] = '';

        $uri = isset($_SERVER['REQUEST_URI']) ? trim($_SERVER['REQUEST_URI'], '?') : '';

        $base = isset($_SERVER['SCRIPT_NAME']) ? dirname($_SERVER['SCRIPT_NAME']) : '';
        if (false !== ($qm = strpos($uri, '?'))) {
            $uri = substr($uri, 0, $qm);
        }
        $rewrite = trim(substr($uri, strlen($base)), '/');
        $params = false !== strpos($rewrite, '/') ? explode('/', $rewrite) : ($rewrite ? [0 => $rewrite] : []);
        $ret['target'] = $ret['params'] = $params;

        $common_config = static::getCommonConfigVar('common');

        if (!empty($params) && count($params) > 0) {
            // 模块是否已经在common.cfg.php中定义
            $common_config['mods'][] = $this->modApiName;
            if (in_array($params[0], $common_config['mods'])) {
                // 支持 api的子模块
                if ($params[0] == $this->modApiName) {
                    if (count($params) > 3 && in_array($params[1], $common_config['mods'])) {
                        $ret['mod'] = $params[1];
                        $ret['control'] = !empty($params[2]) ? $params[2] : 'index';
                        $ret['action'] = !empty($params[3]) ? $params[3] : 'index';
                    } else {
                        $ret['mod'] = '';
                        $ret['control'] = !empty($params[1]) ? $params[1] : 'index';
                        $ret['action'] = !empty($params[2]) ? $params[2] : 'index';
                    }
                    $this->cmd = $ret['control'] . '.' . $ret['action'];
                } else {
                    $ret['mod'] = $params[0];
                    $ret['control'] = !empty($params[1]) ? $params[1] : 'index';
                    $ret['action'] = !empty($params[2]) ? $params[2] : 'index';
                }
            } else {
                $ret['mod'] = '';
                if (!isset($params[1]) || strpos($params[1], '.html') !== false) {
                    $params[1] = 'index';
                }
                $ret['control'] = !empty($params[0]) ? $params[0] : 'index';
                $ret['action'] = !empty($params[1]) ? $params[1] : 'index';
            }
        }
        $ret['method'] = $ret['action'];
        $this->ctrl = $ret['control'];
        $this->action = $ret['action'];
        $this->method = $ret['method'];
        $this->mod = $ret['mod'];
        $this->target = $ret['target'];
        return $ret;
    }
711546
public function __HANDLER()
    {
        // Create query to get users
        $query = dbQuery('user')->Active(1)->order_by('UserID');

        // Create generic table for users
        $table = new Table($query);

        // Установим представление
        m()->view('main/index')->title(t('Пользователи системы', true))
            ->all_materials(true)
            // Установим шаблон таблицы пользователей
            ->user_table($table->render());
    }
1201437
public function run()
	{
		$id=$this->getId();
		if(isset($this->htmlOptions['id']))
			$id=$this->htmlOptions['id'];
		else
			$this->htmlOptions['id']=$id;

		echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
		foreach($this->panels as $title=>$content)
		{
			echo strtr($this->headerTemplate,array('{title}'=>$title))."\n";
			echo strtr($this->contentTemplate,array('{content}'=>$content))."\n";
		}
		echo CHtml::closeTag($this->tagName);

		$options=CJavaScript::encode($this->options);
		Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').accordion($options);");
	}