国产chinesehdxxxx老太婆,办公室玩弄爆乳女秘hd,扒开腿狂躁女人爽出白浆 ,丁香婷婷激情俺也去俺来也,ww国产内射精品后入国产

電子發(fā)燒友App

硬聲App

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>MixVega CLI HTTP網(wǎng)絡(luò)框架

MixVega CLI HTTP網(wǎng)絡(luò)框架

2022-06-30 | zip | 0.03 MB | 次下載 | 免費(fèi)

資料介紹

授權(quán)協(xié)議 Apache
開(kāi)發(fā)語(yǔ)言 PHP
操作系統(tǒng) 跨平臺(tái)
軟件類型 開(kāi)源軟件

軟件簡(jiǎn)介

Vega 是一個(gè)用 PHP 編寫(xiě)的 CLI 模式 HTTP 網(wǎng)絡(luò)框架,支持 Swoole、WorkerMan、FPM、CLI-Server

概述

Vega 是?MixPHP?V3+?內(nèi)置的最核心的組件 (可獨(dú)立使用),參考 golang?gin?mux?開(kāi)發(fā),它包含 Web 應(yīng)用處理的大量功能 (數(shù)據(jù)庫(kù)處理除外) ,包括:路由、渲染、參數(shù)獲取、中間件、文件上傳、靜態(tài)文件處理等;具有 CLI 模式下強(qiáng)大的兼容性,同時(shí)支持 Swoole、WorkerMan、FPM、CLI-Server, 并且支持 Swoole 的多種進(jìn)程模型與協(xié)程。

推薦搭配以下數(shù)據(jù)庫(kù)使用:

推薦文章:

技術(shù)交流

知乎:https://www.zhihu.com/people/onanying
官方QQ群:284806582?,?825122875?敲門(mén)暗號(hào):vega

安裝

需先安裝?Swoole?或者?WorkerMan

composer require mix/vega

快速開(kāi)始

  • Swoole 多進(jìn)程 (異步) 中使用

require __DIR__ . '/vendor/autoload.php';

$vega = new Mix\Vega\Engine();
$vega->handle('/hello', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET');

$http = new Swoole\Http\Server('0.0.0.0', 9501);
$http->on('Request', $vega->handler());
$http->set([
    'worker_num' => 4,
]);
$http->start();

開(kāi)啟多進(jìn)程協(xié)程

$http->on('Request', $vega->handler());
$http->on('WorkerStart', function ($server, $workerId) {
    // 協(xié)程初始化
    // 比如:?jiǎn)?dòng) mix/database mix/redis 的連接池
});
$http->set([
    'enable_coroutine' => true,
    'worker_num' => 4,
]);
php swoole.php
  • Swoole 單進(jìn)程 (協(xié)程) 中使用

require __DIR__ . '/vendor/autoload.php';

Swoole\Coroutine\run(function () {
    $vega = new Mix\Vega\Engine();
    $vega->handle('/hello', function (Mix\Vega\Context $ctx) {
        $ctx->string(200, 'hello, world!');
    })->methods('GET');
    
    $server = new Swoole\Coroutine\Http\Server('0.0.0.0', 9502, false);
    $server->handle('/', $vega->handler());
    $server->start();
});
php swooleco.php
  • WorkerMan 中使用

require __DIR__ . '/vendor/autoload.php';

$vega = new Mix\Vega\Engine();
$vega->handle('/hello', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET');

$http_worker = new Workerman\Worker("http://0.0.0.0:2345");
$http_worker->onMessage = $vega->handler();
$http_worker->count = 4;
Workerman\Worker::runAll();
php wokerman.php start
  • PHP-FPM 中使用

在?nginx?配置?rewrite?重寫(xiě)到?index.php


require __DIR__ . '/vendor/autoload.php';

$vega = new Mix\Vega\Engine();
$vega->handle('/hello', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET');
return $vega->run();

這個(gè)內(nèi)置的Web服務(wù)器主要用于本地開(kāi)發(fā)使用,不可用于線上產(chǎn)品環(huán)境。


require __DIR__ . '/vendor/autoload.php';

$vega = new Mix\Vega\Engine();
$vega->handle('/hello', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET');
return $vega->run();
php -S localhost:8000 router.php
  • 訪問(wèn)測(cè)試
% curl http://127.0.0.1:9501/hello
hello, world!

路由配置

配置?Closure?閉包路由

$vega = new Mix\Vega\Engine();
$vega->handle('/hello', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET');

配置?callable?路由

class Hello {
    public function index(Mix\Vega\Context $ctx) {
        $ctx->string(200, 'hello, world!');
    }
}
$vega = new Mix\Vega\Engine();
$vega->handle('/hello', [new Hello(), 'index'])->methods('GET');

配置路由變量

$vega = new Mix\Vega\Engine();
$vega->handle('/users/{id:\d+}', function (Mix\Vega\Context $ctx) {
    $id = $ctx->param('id');
    $ctx->string(200, 'hello, world!');
})->methods('GET');

配置多個(gè)?method

$vega = new Mix\Vega\Engine();
$vega->handle('/hello', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET', 'POST');

路由前綴 (分組)

$vega = new Mix\Vega\Engine();
$sub = $vega->pathPrefix('/foo');
$sub->handle('/bar1', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET');
$sub->handle('/bar2', function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello1, world!');
})->methods('GET');

參數(shù)獲取

請(qǐng)求參數(shù)

方法名稱 描述
$ctx->request: ServerRequestInterface 符合PSR的請(qǐng)求對(duì)象
$ctx->response: ResponseInterface 符合PSR的響應(yīng)對(duì)象
ctx?>param(stringctx?>param(stringkey): string 獲取路由參數(shù)
ctx?>query(stringctx?>query(stringkey): string 獲取url參數(shù),包含路由參數(shù)
ctx?>defaultQuery(stringctx?>defaultQuery(stringkey, string $default): string 獲取url參數(shù),可配置默認(rèn)值
ctx?>getQuery(stringctx?>getQuery(stringkey): string or null 獲取url參數(shù), 可判斷是否存在
ctx?>postForm(stringctx?>postForm(stringkey): string 獲取post參數(shù)
ctx?>defaultPostForm(stringctx?>defaultPostForm(stringkey, string $default): string 獲取post參數(shù),可配置默認(rèn)值
ctx?>getPostForm(stringctx?>getPostForm(stringkey): string or null 獲取post參數(shù),可判斷是否存在

Headers, Cookies, Uri ...

方法名稱 描述
$ctx->contentType(): string 請(qǐng)求類型
ctx?>header(stringctx?>header(stringkey): string 請(qǐng)求頭
ctx?>cookie(stringctx?>cookie(stringname): string cookies
$ctx->uri(): UriInterface 完整uri
$ctx->rawData(): string 原始包數(shù)據(jù)

客戶端IP

方法名稱 描述
$ctx->clientIP(): string 從反向代理獲取用戶真實(shí)IP
$ctx->remoteIP(): string 獲取遠(yuǎn)程IP

上傳文件處理

方法名稱 描述
ctx?>formFile(stringctx?>formFile(stringname): UploadedFileInterface 獲取上傳的第一個(gè)文件
$ctx->multipartForm(): UploadedFileInterface[] 獲取上傳的全部文件

文件保存

$file = $ctx->formFile('img');
$targetPath = '/data/project/public/uploads/' . $file->getClientFilename();
$file->moveTo($targetPath);

請(qǐng)求上下文

請(qǐng)求當(dāng)中需要保存一些信息,比如:會(huì)話、JWT載荷等。

方法名稱 描述
ctx?>set(stringctx?>set(stringkey, $value): void 設(shè)置值
ctx?>get(stringctx?>get(stringkey): mixed or null 獲取值
ctx?>mustGet(stringctx?>mustGet(stringkey): mixed or throws 獲取值或拋出異常

中斷執(zhí)行

abort?執(zhí)行后,會(huì)停止執(zhí)行后面的全部代碼,包括中間件。

方法名稱 描述
$ctx->abort(): void 中斷,需自行處理響應(yīng)
ctx?>abortWithStatus(intctx?>abortWithStatus(intcode): void 中斷并響應(yīng)狀態(tài)碼
ctx?>abortWithStatusJSON(intctx?>abortWithStatusJSON(intcode, $data): void 中斷并響應(yīng)JSON
$vega = new Mix\Vega\Engine();
$vega->handle('/users/{id}', function (Mix\Vega\Context $ctx) {
    if (true) {
        $ctx->string(401, 'Unauthorized');
        $ctx->abort();
    }
    $ctx->string(200, 'hello, world!');
})->methods('GET');

響應(yīng)處理

方法名稱 描述
ctx?>status(intctx?>status(intcode): void 設(shè)置狀態(tài)碼
ctx?>setHeader(stringctx?>setHeader(stringkey, string $value): void 設(shè)置header
ctx?>setCookie(stringctx?>setCookie(stringname, string?value,intvalue,intexpire = 0, ...): void 設(shè)置cookie
ctx?>redirect(stringctx?>redirect(stringlocation, int $code = 302): void 重定向

JSON 請(qǐng)求與輸出

獲取 JSON 請(qǐng)求數(shù)據(jù)

$vega = new Mix\Vega\Engine();
$vega->handle('/users', function (Mix\Vega\Context $ctx) {
    $obj = $ctx->getJSON();
    if (!$obj) {
        throw new \Exception('Parameter error');
    }
    var_dump($obj);
    $ctx->JSON(200, [
        'code' => 0,
        'message' => 'ok'
    ]);
})->methods('POST');

mustGetJSON?自帶有效性檢查,以下代碼等同于上面

$vega = new Mix\Vega\Engine();
$vega->handle('/users', function (Mix\Vega\Context $ctx) {
    $obj = $ctx->mustGetJSON();
    var_dump($obj);
    $ctx->JSON(200, [
        'code' => 0,
        'message' => 'ok'
    ]);
})->methods('POST');

JSONP 處理

$vega = new Mix\Vega\Engine();
$vega->handle('/jsonp', function (Mix\Vega\Context $ctx) {
    $ctx->JSONP(200, [
        'code' => 0,
        'message' => 'ok'
    ]);
})->methods('GET');

HTML 視圖渲染

創(chuàng)建視圖文件?foo.php

id: $id ?>, name: $name ?>

friends:

    foreach($friends as $name): ?>
  • $name ?>
  • endforeach; ?>

配置視圖路徑,并響應(yīng)html

$vega = new Mix\Vega\Engine();
$vega->withHTMLRoot('/data/project/views');
$vega->handle('/html', function (Mix\Vega\Context $ctx) {
    $ctx->HTML(200, 'foo', [
        'id' => 1000,
        'name' => '小明',
        'friends' => [
            '小花',
            '小紅'
        ]
    ]);
})->methods('GET');

靜態(tài)文件處理

基于?sendfile?零拷貝,不支持在?PHP-FPM?中使用

$vega = new Mix\Vega\Engine();
$vega->static('/static', '/data/project/public/static');
$vega->staticFile('/favicon.ico', '/data/project/public/favicon.ico');

設(shè)置中間件

給某個(gè)路由配置中間件,可配置多個(gè)

$vega = new Mix\Vega\Engine();
$func = function (Mix\Vega\Context $ctx) {
    // do something
    $ctx->next();
};
$vega->handle('/hello', $func, function (Mix\Vega\Context $ctx) {
    $ctx->string(200, 'hello, world!');
})->methods('GET');

配置全局中間件,即便沒(méi)有匹配到路由也會(huì)執(zhí)行

$vega = new Mix\Vega\Engine();
$vega->use(function (Mix\Vega\Context $ctx) {
    $ctx->next();
});

前置中間件

$vega->use(function (Mix\Vega\Context $ctx) {
    // do something
    $ctx->next();
});

后置中間件

$vega->use(function (Mix\Vega\Context $ctx) {
    $ctx->next();
    // do something
});

404 自定義

$vega = new Mix\Vega\Engine();
$vega->use(function (Mix\Vega\Context $ctx) {
    try{
        $ctx->next();
    } catch (Mix\Vega\Exception\NotFoundException $ex) {
        $ctx->string(404, 'New 404 response');
        $ctx->abort();
    }
});

500 全局異常捕獲

$vega = new Mix\Vega\Engine();
$vega->use(function (Mix\Vega\Context $ctx) {
    try{
        $ctx->next();
    } catch (\Throwable $ex) {
        if ($ex instanceof Mix\Vega\Abort || $ex instanceof Mix\Vega\Exception\NotFoundException) {
            throw $ex;
        }
        $ctx->string(500, 'New 500 response');
        $ctx->abort();
    }
});

License

Apache License Version 2.0,?http://www.apache.org/licenses/

?

下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評(píng)論

查看更多

下載排行

本周

  1. 1DD3118電路圖紙資料
  2. 0.08 MB   |  1次下載  |  免費(fèi)
  3. 2AD庫(kù)封裝庫(kù)安裝教程
  4. 0.49 MB   |  1次下載  |  免費(fèi)
  5. 3PC6206 300mA低功耗低壓差線性穩(wěn)壓器中文資料
  6. 1.12 MB   |  1次下載  |  免費(fèi)
  7. 4網(wǎng)絡(luò)安全從業(yè)者入門(mén)指南
  8. 2.91 MB   |  1次下載  |  免費(fèi)
  9. 5DS-CS3A P00-CN-V3
  10. 618.05 KB  |  1次下載  |  免費(fèi)
  11. 6海川SM5701規(guī)格書(shū)
  12. 1.48 MB  |  次下載  |  免費(fèi)
  13. 7H20PR5電磁爐IGBT功率管規(guī)格書(shū)
  14. 1.68 MB   |  次下載  |  1 積分
  15. 8IP防護(hù)等級(jí)說(shuō)明
  16. 0.08 MB   |  次下載  |  免費(fèi)

本月

  1. 1貼片三極管上的印字與真實(shí)名稱的對(duì)照表詳細(xì)說(shuō)明
  2. 0.50 MB   |  103次下載  |  1 積分
  3. 2涂鴉各WiFi模塊原理圖加PCB封裝
  4. 11.75 MB   |  89次下載  |  1 積分
  5. 3錦銳科技CA51F2 SDK開(kāi)發(fā)包
  6. 24.06 MB   |  43次下載  |  1 積分
  7. 4錦銳CA51F005 SDK開(kāi)發(fā)包
  8. 19.47 MB   |  19次下載  |  1 積分
  9. 5PCB的EMC設(shè)計(jì)指南
  10. 2.47 MB   |  16次下載  |  1 積分
  11. 6HC05藍(lán)牙原理圖加PCB
  12. 15.76 MB   |  13次下載  |  1 積分
  13. 7802.11_Wireless_Networks
  14. 4.17 MB   |  12次下載  |  免費(fèi)
  15. 8蘋(píng)果iphone 11電路原理圖
  16. 4.98 MB   |  6次下載  |  2 積分

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935127次下載  |  10 積分
  3. 2開(kāi)源硬件-PMP21529.1-4 開(kāi)關(guān)降壓/升壓雙向直流/直流轉(zhuǎn)換器 PCB layout 設(shè)計(jì)
  4. 1.48MB  |  420064次下載  |  10 積分
  5. 3Altium DXP2002下載入口
  6. 未知  |  233089次下載  |  10 積分
  7. 4電路仿真軟件multisim 10.0免費(fèi)下載
  8. 340992  |  191390次下載  |  10 積分
  9. 5十天學(xué)會(huì)AVR單片機(jī)與C語(yǔ)言視頻教程 下載
  10. 158M  |  183342次下載  |  10 積分
  11. 6labview8.5下載
  12. 未知  |  81588次下載  |  10 積分
  13. 7Keil工具M(jìn)DK-Arm免費(fèi)下載
  14. 0.02 MB  |  73815次下載  |  10 積分
  15. 8LabVIEW 8.6下載
  16. 未知  |  65989次下載  |  10 積分