Laravel10 正式版发布

640次阅读
没有评论

共计 1699 个字符,预计需要花费 5 分钟才能阅读完成。

2023 年情人节当天,Laravel10 正式版发布了!

Laravel 10 通过引入参数和返回类型到所有应用程序核心方法,,延续了 Laravel 9 中所做的改进。此外,还引入了一个新的、对开发人员友好的抽象层,用于启动和与外部进程交互。另外,引入了 Laravel Penant,以提供一种管理应用程序“功能标志”的绝佳方法。

要获得有关此版本的所有细节,请查看官方 发行说明 升级指南。下面介绍一些新版本的新特性:

方法签名 + 返回类型

<?php

namespace App\Http\Controllers;

use App\Models\Flight;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class FlightController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index(): Response
    {//}

    /**
     * Display the specified resource.
     */
    public function show(Flight $flight): Response
    {//}

    // ...

}

此特性完全向后兼容现有应用程序。因此,没有这些类型提示的现有应用程序将继续正常运行。

Laravel Pennant

新的集成软件包 Laravel Penant 已经发布。Laravel Penant 提供了一种轻量级、简化的方法来管理应用程序的功能标志。开箱即用,Pennant 包括一个内存数组驱动程序和一个用于持久功能存储的数据库驱动程序。

该特性可以通过 Feature::define 方法轻松定义:

use Laravel\Pennant\Feature;
use Illuminate\Support\Lottery;

Feature::define('new-onboarding-flow', function () {return Lottery::odds(1, 10);
});

定义功能后,您可以轻松确定当前用户是否可以访问给定功能:

if (Feature::active('new-onboarding-flow')) {// ...}

当然,为了方便起见,Blade 指令也可用:

@feature('new-onboarding-flow')
    <div>
        <!-- ... -->
    </div>
@endfeature

更多信息请参考详细文档介绍:comprehensive Pennant documentation.

进程交互

Laravel 10. x 引入了一个很好用的抽象层,用于通过新的 Process 方法启动外部进程并与之交互:

use Illuminate\Support\Facades\Process;

$result = Process::run('ls -la');

return $result->output();

进程甚至可以在池中启动,从而方便地执行和管理并发进程:

use Illuminate\Process\Pool;
use Illuminate\Support\Facades\Pool;

[$first, $second, $third] = Process::concurrently(function (Pool $pool) {$pool->command('cat first.txt');
    $pool->command('cat second.txt');
    $pool->command('cat third.txt');
});

return $first->output();

此外,为了方便测试,也可以虚拟一个进程:

Process::fake();

// ...

Process::assertRan('ls -la');

更多进程介绍详见文档:comprehensive process documentation.

Horizon / Telescope 改进

Horizon and Telescope 已经更新了一个新的,现代的外观,包括改进的排版,行间距和设计:

Laravel10 正式版发布
正文完
加入官方交流QQ群:778957856
post-qrcode
 0
clark
版权声明:本站原创文章,由 clark 2023-02-15发表,共计1699字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)