运行应用

@return bool
@throws \Exception
778470
public function run()
    {
        if ($this->runningInConsole()) {
            $kernel = $kernel = static::make('ConsoleKernel');

            $input = new Input();
            $output = new Output();

            $status = $kernel->handle($input, $output);

            $kernel->terminate($input, $status);

            exit($status);
        }
        else {
            $kernel = static::make('HttpKernel');

            $request = Request::createFromGlobals();
            $request::enableHttpMethodParameterOverride();
            $request->enableHttpRequestParameterOverride();
            $response = $kernel->handle($request);

            $response->send();

            $kernel->terminate($request, $response);
        }

        return true;
    }
347345
public function execute()
    {
        // Check if we have a url
        if (!$this->url || trim($this->url) == '') {
            $this->url = '/';
        }

        // Make sure the url starts with a slash
        if (substr($this->url, 0, 1) !== '/') {
            $this->url = '/' . $this->url;
        }

        // Check if the absolute route exists in our routes array
        // - and if that route has the same type of request as the current request.
        if (isset($this->routes[$this->method][$this->url])) {
            return call_user_func_array($this->routes[$this->method][$this->url], []);
        }

        // Check if the absolute route exists in our routes array
        // - and if that route has the "any" type.
        if (isset($this->routes['any'][$this->url])) {
            return call_user_func_array($this->routes['any'][$this->url], []);
        }

        // Create an array of methods to check and loop through them
        $methods = [$this->method, 'any'];
        foreach ($methods as $method) {
            // Loop through the routes set for this method
            foreach ($this->routes[$method] as $route => $callable) {
                // Check if the route matches
                $regex = '/^' . str_replace('/', '\/', $route) . '/Uim';
                $matches = [];
                if (preg_match($regex, $this->url, $matches) === 1 && $matches[0] === $this->url) {
                    // First value in the array is the string that matched
                    array_shift($matches);

                    // Execute the callable method
                    return call_user_func_array($callable, $matches);
                }
            }
        }

        // No route found, check if we have an empty route.
        // - We should always have an empty route.
        if (!isset($this->routes['any']['/'])) {
            header('HTTP/1.1 404 Not Found');
            exit;
        }

        // Return the empty route's callable
        return call_user_func_array($this->routes['any']['/'], []);
    }
1054965
public function actionRun()
    {
        $crontab = Task::findAll(['switch' => Task::SWITCH_ACTIVE]);
        $tasks = [];

        foreach ($crontab as $task) {
            // 第一次运行,先计算下次运行时间
            if (!$task->next_rundate) {
                $task->next_rundate = $task->getNextRunDate();
                $task->save(false);
                continue;
            }
            // 判断运行时间到了没
            if ($task->next_rundate <= date('Y-m-d H:i:s')) {
                $tasks[] = $task;
            }
        }

        $this->executeTask($tasks);
        return ExitCode::OK;
    }
194022
public function run()
    {
        if (! $this->runPreSearch()) {
            return $this->value;
        }

        $matches = [];
        if (preg_match_all('/(?:(?:\A|[^\d])0x[a-f\d]{3,}[a-f\d]*)+/im', $this->value, $matches)) {
            foreach ($matches[0] as $match) {
                $converted = '';
                foreach (str_split($match, 2) as $hexIndex) {
                    if (preg_match('/[a-f\d]{2,3}/i', $hexIndex)) {
                        $converted .= chr(hexdec($hexIndex));
                    }
                }
                $this->value = str_replace($match, $converted, $this->value);
            }
        }
        // take care of hex encoded ctrl chars
        $this->value = preg_replace('/0x\d+/m', ' 1 ', $this->value);

        return $this->value;
    }
814311
public function run()
    {
        $isValid = true;
        if (empty($this->rules)) {
            return true;
        }

        $this->rulesExecuted = [];

        foreach ($this->rules as $key => $val) {
            $rules = explode('|', $val);

            foreach ($rules as $rule) {

                // Executes rule for min and max validation.
                if (string_has($rule, ':') && strstr($rule, 'max') || strstr($rule, 'min')) {
                    $isValid = $this->doValidateMinMax($rule, $key, $isValid);
                } elseif (string_has($rule, ':') && (!strstr($rule, 'max') && !strstr($rule, 'min'))) {
                    // Executes rule for other than min, max validation with ":" keyword in rule.
                    $isValid = $this->validateRulesHasPlaceHolder($key, $rule, $isValid);
                } else {
                    // Executes all other rules.
                    $isValid = $this->doValidateData($rule, $key, $isValid);
                }

                $this->rulesExecuted[] = $isValid;
            }
        }

        /*
        | We will fire all after validation callbacks
        | This is useful to override error message with
        | custom messages
        */
        foreach ($this->after as $event) {
            call_user_func($event);
        }

        // We will return false if any one of the validation rules failed.
        if (in_array(false, $this->rulesExecuted)) {
            return false;
        }

        return true;
    }
599575
public function exec(): bool
    {
        /* @var $sqlStmt \PDOStatement */
        $sqlStmt = $this->getConnection()->prepare($this->getQuery());

        if ($sqlStmt === false) {
            return $this->execFails($sqlStmt, ErrorType::CONNECTION_ERROR);
        }

        // Bind input
        foreach ($this->bindedValues as /* @var $i int */
                 $i => $bindedValue) {
            $type = $this->getPDOType($bindedValue);

            if ($type === false) {
                throw new \Exception('Invalid type of binded value at position ' . ($i + 1) . '.');
            }

            $bindParamsResult = $sqlStmt->bindValue($i + 1, $bindedValue, $type);

            if ($bindParamsResult === false) {
                return $this->execFails($sqlStmt, ErrorType::BINDING_ERROR);
            }
        }

        // Exec query
        $result = $sqlStmt->execute();

        if ($result == false) {
            return $this->execFails($sqlStmt, ErrorType::STATEMENT_ERROR);
        }

        $this->result = new MPDOResult($sqlStmt);

        $sqlStmt->closeCursor();

        return true;
    }
450774
private function RunRequest()
    {
        $result = curl_exec($this->_curlHandle);
        if ($result === false && curl_errno($this->_curlHandle) != 0) {
            $this->logger->error("cURL error: " . curl_error($this->_curlHandle));
            throw new Exception('cURL error: ' . curl_error($this->_curlHandle));
        }

        $response = new HttpResponse();
        $response->ResponseCode = (int) curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE);

        curl_close($this->_curlHandle);

        $explode = explode("\r\n\r\n", $result);

        // multiple query (follow redirect) take only the last request
        $explode = array_slice($explode, sizeof($explode) - 2, 2);

        $response->Headers = explode("\n", implode($explode));
        $response->Body = array_pop($explode);

        return $response;
    }
64193
public function run() {

        foreach ( $this->requests as $request ) {

            if ( isset($request['ERROR_CODE']) && isset($request['ERROR_MESSAGE']) ) {

                $this->logger->warning("Invalid request ".$request['ID']);

                $result = self::packJsonError($request['ERROR_CODE'], $request['ERROR_MESSAGE'], $request['ID']);

                if ( !is_null($result) ) $this->results[] = $result;

            } else {

                try {

                    $this->logger->debug("Serving request ".$request['METHOD']."(".$request['ID'].")");

                    $response = $this->runSingleRequest($request['METHOD'], $request['PARAMETERS']);

                    $result = self::packJsonSuccess($response, $request['ID']);

                } catch (RpcException $re) {

                    $this->logger->warning("Error handling request ".$request['ID'].": ".$re->getMessage());

                    $result = self::packJsonError($re->getCode(), $re->getMessage(), $request['ID']);

                } catch (Exception $e) {

                    $this->logger->error($e->getMessage());

                    throw $e;

                }

                if ( !is_null($result) ) $this->results[] = $result;

            }


        }

        if ( empty($this->results) ) {

            return null;

        } else if ( $this->is_batch_request ) {

            return $this->results;

        } else {

            return $this->results[0];

        }

    }
533361
public function run() {
        $results = [
            $this->simulateDelete(),
            $this->simulateUpdate(),
            $this->simulateCreate()
        ];
        
        return array_search(false, $results, true) === false;
    }
234506
public function execute()
    {
        if (!$this->tryAndProcessRules()) {
            return false;
        }

        $phpmdBinaryPath = $this->phpci->findBinary('phpmd');

        $this->executePhpMd($phpmdBinaryPath);

        $errorCount = $this->processReport(trim($this->phpci->getLastOutput()));
        $this->build->storeMeta('phpmd-warnings', $errorCount);

        return $this->wasLastExecSuccessful($errorCount);
    }
1052992
public function run()
    {
        $running = null;
        do {
            curl_multi_exec($this->_mh, $running);
            $this->_updated = false;
            while ($info = curl_multi_info_read($this->_mh)) {
                $index = false;
                foreach ($this->_requests as $i => $item) {
                    if ($item->curl === $info['handle']) {
                        $index = $i;
                        break;
                    }
                }
                if ($index === false) {
                    throw new \Exception('Curl request not founded in list');
                }
                $request = $this->_requests[$index];
                unset($this->_requests[$index]);

                $content  = curl_multi_getcontent($request->curl);
                $response = curl_getinfo($request->curl);

                curl_multi_remove_handle($this->_mh, $info['handle']);

                if ($info['result'] === CURLE_OK) {
                    $this->onSuccess($request, $response, $content);
                } else {
                    $errCode = $info['result'];
                    $errMsg  = function_exists('curl_strerror') ? curl_strerror($errCode) : "cURL error {$errCode}";
                    $this->onError($request, $response, $content, $errCode, $errMsg);
                }
                $this->onAlways($request, $response, $content);
            }
            curl_multi_select($this->_mh, 1);
        } while ($running>0 || $this->_updated);
    }
117309
public function verify()
    {
        $data = $_GET;
        $sign = $data['md5'];

        if (Helper::verify($data, $sign) === false) {
            throw new \Exception('盈华讯方异步通知验签失败');
        }
        return $data;
    }
1200815
final public function truncate()
    {
        if (!$this->DB) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        $table = $this->getTable();
        $sql = "truncate table " . $table;
        $this->sql = $sql;
        /**
         * 只获取sql
         */
        if ($this->justSql) {
            return true;
        }
        return $this->DB->execute($sql);
    }
1070879
public function run(): bool
    {
        if ($this->startup) {
            $this->logger->debug('Calling startup callback');
            call_user_func($this->startup, $this);
        }

        $actions = implode(', ', array_keys($this->callbacks));
        $this->logger->info("Component running with callbacks for $actions");
        $this->executor->execute(
            $this->apiFactory,
            $this->input,
            $this->callbacks,
            $this->error
        );

        if ($this->shutdown) {
            $this->logger->debug('Calling shutdown callback');
            call_user_func($this->shutdown, $this);
        }

        return true;
    }
825820
public function run()
    {
        if (Yii::$app->user->isGuest) {
            $client = Yii::$app->wechat->oauth;
            return $this->auth($client);
        } else {
            return $this->controller->goHome();
        }
    }
413520
public function start()
    {
        $try = $this->tryStart();
        $this->log('debug', 'try start', [
            'result' => (int) $try,
        ]);

        if (!$try) {
            return false;
        }

        $this->log('info', 'Job start');

        // 把进程ID和开始时间记录到上下文中
        $this->setContext(self::KEY_PROC_ID, posix_getpid());
        $this->setContext(self::KEY_PROC_TIME, time());
        $this->saveContext();

        // 执行任务逻辑
        try {
            $this->execute();
        } catch (\Exception $ex) {
            $this->log('error', 'Job execute error', [
                'error' => $ex->getMessage(),
            ]);

            return false;
        }

        $this->stop();

        return true;
    }
1073203
public function run()
    {
        $count = 0;
        $start = microtime(true);

        while (true) {
            try {
                return call_user_func($this->callable);
            } catch (\Throwable $e) {
                // Check exception
                if (!$e instanceof $this->exceptionType) {
                    throw $e;
                }

                // Check timeout
                if ($this->timeout > -1 && microtime(true) - $start > ($this->timeout / self::SECONDS)) {
                    throw $e;
                }

                // Check count
                if ($this->count > -1 && ++$count >= $this->count) {
                    throw $e;
                }

                // Before pause hook
                if (array_key_exists(self::BEFORE_PAUSE_HOOK, $this->hooks)) {
                    call_user_func($this->hooks[self::BEFORE_PAUSE_HOOK], $e);
                }

                usleep($this->pause);

                // After pause hook
                if (array_key_exists(self::AFTER_PAUSE_HOOK, $this->hooks)) {
                    call_user_func($this->hooks[self::AFTER_PAUSE_HOOK], $e);
                }
            }
        }
    }