当前位置: 移动技术网 > IT编程>开发语言>PHP > Laravel v7.7 发布 容器支持可变参数

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

2020年04月23日  | 移动技术网IT编程  | 我要评论

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),
            $c->make(profanityfilter::class),
            $c->make(toolongfilter::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 参数 (#3245724b705e)
  • 外键约束新增动态 column key (#32449)
  • 容器新增可变参数支持 (#324541dd6db3)
  • 新增 illuminate\http\client\request::hasheaders() (#32462)

修复

  • 修复带有主键模型的 morphpivot::delete() 功能 bug (#32421)
  • 容器调用缺少必要参数会抛出异常 (#3243944c2a8d)
  • 修复 http 客户端 multipart 请求 (#324281f163d4)
  • 修复 illuminate\support\stringable::isempty() (#32447)
  • 修复 wherenull/wherenotnull 支持 mysql 的 json 字段 (#32417d3bb329)
  • 修复 collection::orderby() 使用回调 (#32471)

更改

  • compiledroutecollection 重新启用 router::newroute() (#32416)
  • 更高 illuminate\queue\interactswithqueue.php::$job 为 public (2e272ee)
  • 计划任务运行期间捕获并报告异常 (#32461)

 

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

更多学习内容请访问:

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

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网