加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 19:33:29 所属栏目:大数据 来源:网络整理
导读:Laravel 团队昨天发布了 v7.7.0,其中包含容器支持的构造函数支持可变参数,一些新的 HTTP 客户端功能,Blueprint 新增 rawIndex() 方法以及 7.x 分支中的所有最新功能,修复和更改 : HTTP 客户端 GET 请求 支持数组 Daniel Mason 贡献了 HTTP 客户端支持数

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 表达式创建索引:

// Before
Schema::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")))');

// After
Schema::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 为容器新增了可变参数功能,下面是个简单的使用案例:

// Before
app()->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),]
    );
});

// After
app()->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)
  • 新增?IlluminateHttpClientFactory::assertSentCount()?(#32407)
  • 新增?IlluminateDatabaseSchemaBlueprint::rawIndex()?(#32411)
  • Eloquent builder 新增 getGrammar 到 passthru 中 (#32412)
  • storage:link?命令新增?--relative?参数 (#32457,?24b705e)
  • 外键约束新增动态?column?key (#32449)
  • 容器新增可变参数支持 (#32454,?1dd6db3)
  • 新增?IlluminateHttpClientRequest::hasHeaders()?(#32462)

修复

  • 修复带有主键模型的?MorphPivot::delete()?功能 BUG (#32421)
  • 容器调用缺少必要参数会抛出异常 (#32439,?44c2a8d)
  • 修复 HTTP 客户端 multipart 请求 (#32428,?1f163d4)
  • 修复?IlluminateSupportStringable::isEmpty()?(#32447)
  • 修复?whereNull/whereNotNull?支持 MySQL 的 json 字段 (#32417,?d3bb329)
  • 修复?Collection::orderBy()?使用回调 (#32471)

更改

  • CompiledRouteCollection?重新启用?Router::newRoute()?(#32416)
  • 更高?IlluminateQueueInteractsWithQueue.php::$job?为 public (2e272ee)
  • 计划任务运行期间捕获并报告异常 (#32461)

?

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

更多学习内容请访问:

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

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读