Laravel v7.7 发布 容器支持可变参数

Laravel v7.7 发布 容器支持可变参数,第1张

概述Laravel 团队昨天发布了 v7.7.0,其中包含容器支持的构造函数支持可变参数,一些新的 HTTP 客户端功能,Blueprint 新增 rawIndex() 方法以及 7.x 分支中的所有最新

Laravel 团队昨天发布了 v7.7.0,其中包含容器支持的构造函数支持可变参数,一些新的 http 客户端功能,Blueprint 新增 rawIndex() 方法以及 7.x 分支中的所有最新功能,修复和更改 :

http 客户端 GET 请求 支持数组

DanIEl Mason 贡献了 http 客户端支持数组的功能:

http::get('http://foo.com',['foo' => 'bar']);http::assertSent(function (Request $request) {    return $request->url() === 'http://foo.com/get?foo=bar'        && $request['foo'] === 'bar';});
http 客户端新增 assertSentCount 断言

Christoph Rumpel 为 http 客户端新增了 assertSentCount 断言,这对断言发送的预期请求值很有用:

$this->factory->fake();$this->factory->assertSentCount(0);$this->factory->post('http://foo.com/form',[       'name' => 'Taylor',]);$this->factory->assertSentCount(1);$this->factory->post('http://foo.com/form',[       'name' => 'Jim',]);$this->factory->assertSentCount(2);
“rawIndex” 方法可以使用表达式创建索引

Jonathan Reinink 贡献了 rawIndex 方法, 允许我们使用自定义 sql 表达式创建索引:

// BeforeSchema::create('users',function (Blueprint $table) {    $table->ID();    $table->string('name');    $table->date('birth_date')->nullable();    $table->timestamps();});DB::statement('ALTER table users ADD INDEX birthday_index ((date_format(birth_date,"%m-%d")))');// AfterSchema::create('users',function (Blueprint $table) {    $table->ID();    $table->string('name');    $table->date('birth_date')->nullable();    $table->timestamps();    $table->rawIndex('(date_format(birth_date,"%m-%d"))','birthday_index');});
容器构造函数支持可变参数

Beau Simensen 为容器新增了可变参数功能,下面是个简单的使用案例:

// Beforeapp()->singleton(Logger::class,MyLogger::class);app()->bind(Firewall::class,function ($c) {    return new Firewall(        $c->make(Logger::class),...[            $c->make(NullFilter::class),$c->make(ProfanityFilter::class),$c->make(ToolongFilter::class),]    );});// Afterapp()->singleton(Logger::class,MyLogger::class);app()    ->when(Firewall::class)    ->needs(Filter::class)    ->give([        NullFilter::class,ProfanityFilter::class,ToolongFilter::class,]);

就像 pull request 中的描述一样, 您也可以将闭包传递给 give 方法:

app()->singleton(Logger::class,MyLogger::class);app()    ->when(Firewall::class)    ->needs(Filter::class)    ->give(function ($c) {        return [            $c->make(NullFilter::class),];    });

pull request 包含所有详细信息,和其他可以解决的问题。

 

http 客户端新增 “hasheaders” 断言

Matt Kingshott 为 http 客户端 新增了 hasheaders() 方法,该方法可以让您使用一些语法糖检查存在的请求头或值:

$headers = [    'X-Test-header' => 'foo','X-Test-Arrayheader' => ['bar','baz'],];http::withheaders($headers);// ...http::assertSent(function ($request) use ($headers) {    return $request->hasheaders($headers);});
发行说明

您可以在 Github 查看一些新的功能和 7.6.0 和 7.7.0 之间的区别。完整的发行说明可以在 v7 changelog 看到:

v7.7.0

 

新增http 客户端 GET 请求支持数组 (#32401)新增 Illuminate\http\ClIEnt\Factory::assertSentCount() (#32407)新增 Illuminate\Database\Schema\Blueprint::rawIndex() (#32411)Eloquent builder 新增 getGrammar 到 passthru 中 (#32412)storage:link 命令新增 --relative 参数 (#32457, 24b705e)外键约束新增动态 column key (#32449)容器新增可变参数支持 (#32454, 1dd6db3)新增 Illuminate\http\ClIEnt\Request::hasheaders() (#32462)修复修复带有主键模型的 MorPHPivot::delete() 功能 BUG (#32421)容器调用缺少必要参数会抛出异常 (#32439, 44c2a8d)修复 http 客户端 multipart 请求 (#32428, 1f163d4)修复 Illuminate\Support\Stringable::isEmpty() (#32447)修复 whereNull/whereNotNull 支持 MysqL 的 Json 字段 (#32417, d3bb329)修复 Collection::orderBy() 使用回调 (#32471)更改CompiledRouteCollection 重新启用 Router::newRoute() (#32416)更高 Illuminate\Queue\InteractsWithQueue.PHP::$job 为 public (2e272ee)计划任务运行期间捕获并报告异常 (#32461)

 

原文地址:https://laravel-news.com/laravel-7-7-rel...
译文地址:https://learnku.com/laravel/t/43581

更多学习内容请访问:

腾讯T3-T4标准精品PHP架构师教程目录大全,只要你看完保证薪资上升一个台阶(持续更新)

 

总结

以上是内存溢出为你收集整理的Laravel v7.7 发布 容器支持可变参数全部内容,希望文章能够帮你解决Laravel v7.7 发布 容器支持可变参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1240556.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存