zoukankan      html  css  js  c++  java
  • Laravel v7.7 发布 容器支持可变参数

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

    修复

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

    更改

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

     

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

    更多学习内容请访问:

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

  • 相关阅读:
    jsonp
    web系统中上下移动功能的实现
    重载的目的是什么
    重写和重载
    final和static
    static的应用
    shiro认证
    做阉割版Salesforce难成伟大的TOB企业
    Go语言在国产CPU平台上应用前景的探索与思考
    101 More Security Best Practices for Kubernetes
  • 原文地址:https://www.cnblogs.com/a609251438/p/12760514.html
Copyright © 2011-2022 走看看