Laravel - 为 WEB 艺术家创造的 PHP 框架。

PHP THAT DOESN'T HURT. CODE HAPPY & ENJOY THE FRESH AIR.

Laravel logo

Laravel 5.1 LTS 版本正式发布

Laravel 于6月9日正式发布了 5.1 最新 LTS 版本。这是 Laravel 历史上第一个提供 LTS(长期支持 - long-time support) 支持的版本。下面就来看看这个版本带来了哪些新特性吧。还有 Taylor Otwell 访谈。

长期支持(Long Term Support)

从 2011 年 Laravel 首次发布开始,Laravel 就一直遵守“早发布,常发布”的版本发布准则,这也是开源界常通常的做法。随着 Laravel 成为一个最流行 的 PHP 发框架,我们必须考虑大型企业和关键应用上对安全和版本稳定性的需求。现在,Laravel 5.1 将首次提供为期3年的安全补丁支持。

长期支持(long-term support)毫无疑问是 5.1 版本的最大亮点,不过,新版本还有其他一些特性值得关注。

新的文档

为了让表达和措辞更清晰、解释更有深度、组织更合理,我们重写了 Laravel 文档。这次重写我们倾注了巨大的心血和无数的时间。

当 Taylor 被问及花费如此多的时间来重写文档是否值得时,他说宁愿延迟整个 Laravel 的发布时间也不希望给到大家的是一份糟糕的文档。文档的另一个亮点就是带有自动补全的实时搜索功能。

新增的文档搜索功能

新增的文档搜索功能。

支持 PSR-2

app 和生成器被调整为支持 PSR-2 标准。Laravel 代码最大的改变就是将 tab 锁进改为了空格缩进,和控制结构(if、else 之类)在同一行排版.

从 blade 模版中解析服务(service)

Y现在可以直接从 Blade 模版中解析服务(service)了:

@extends('layouts.app')
@inject('stats', 'StatisticsService')
<div>{{ $stats->getCustomerCount() }}</div>

事件广播

Laravel 已经包含了一个强大的事件系统,5.1 版本中的新特性就是基于这个事件系统之上的。现在你可以通过 websocket 广播事件然后由消费者接收这些事件。这一新特性带来的好处是简化了实时应用的开发。

更好的单元测试

由于新版本包含了 Laracast 的集成测试包,单元测试比以前更简单了。

public function testNewUserRegistration()
{
    $this->visit('/register')
         ->type('Taylor', 'name')
         ->check('terms')
         ->press('Register')
         ->seePageIs('/dashboard');
}

如果需要深入了解这些新特性,可以看一下 Laracasts 推出的系列视频Matt Stauffer 撰写的文章。


Taylor Otwell 访谈

Taylor Otwell 在 PHP 世界大会

I had a chance to sit down with Taylor Otwell and ask him about this release and what it means for us Laravel developers:

One of the biggest changes in 5.1 is this will be Laravel’s first LTS version. Can you tell us how that’s going to work?

This is the very first LTS (long term support) release for Laravel. This means that that Laravel 5.1 will receive 2 years of bug fixes and 3 years of security fixes. LTS releases will be released every 2 years, meaning the next LTS release will be in May of 2017. Laravel releases with long term support provide more peace of mind to development shops or clients that need assurance of continued bug fixes for several years.

You’ve spent a tremendous amount of time on rewriting the entire documentation. Do you think this will help drive Laravel adoption?

Good documentation is one of the most crucial aspects of any open-source project. Yet, it’s so often neglected or delayed until after release. If I could give project maintainers a single piece of advice, it would be to never release anything that isn’t well documented. I would delay an entire Laravel release rather than release something with poor documentation. I think the improved documentation will drive even more adoption of Laravel. Of course, I always have tricks up my sleeve and I have even more to announce in this space soon. Continuing to make Laravel enjoyable to learn is one of my biggest passions.

Out of all the new features which one are you most proud of and which one do you think is the most important?

Honestly, I think the documentation is the “feature” of Laravel 5.1 I’m most proud of. It’s just so much better. As far as technical features go, I love event broadcasting. It didn’t take much code to implement, but it’s just so convenient to use and makes it simpler to get started building real-time applications. Middleware parameters are another great addition to Laravel 5.1, and were actually implemented by a community member. Again, that’s a feature that did not take much code to implement but will make a lot of users very happy.

Laravel 5.1 also introduces PSR-2. A lot of people have complained this should have been done sooner. What are your thoughts on that?

It’s very hard to introduce a new coding style in a project with a lot of contribution activity. Before I started working full-time on Laravel, it was routine for there to be several hundred open pull requests. Converting the entire project to PSR-2 at that time would have meant rebasing every single open pull request. Now that I work full-time on the project, there may only be 20-30 open pull requests at a time across the entire Laravel GitHub organization, which is much easier to manage. So, this is the perfect opportunity to adopt PSR-2, and I’m already loving being able to run a simple Sublime Text build command to format all of my code.

Are you still staying true to your original goals when you first created Laravel?

Out of all of the Laravel releases, I think Laravel 5.1 is my favorite. It streamlines and improves much of what was introduced in Laravel 5.0. Firstly, I think it makes the folder structure more “human friendly” by renaming “Commands” to “Jobs”, and moves away from the complicated “Handlers” directory structure to a simple, single “Listeners” directory for event listeners. Event broadcasting is a classic Laravel feature. To broadcast your events over Pusher or Redis you simply add a “ShouldBroadcast” interface to your event class. That’s it. I love small features that are simple and elegant. Middleware parameters improves the original middleware introduced in 5.0 and makes them just as powerful as the Laravel 4.x route “filters”.

I’m sure with the umbrella of Laravel products it takes a lot of your time, but now that 5.1 is out, what are you plans for the rest of the year?

My immediate plans are to improve a few Forge features. I would like to bake-in AWS support as well as improve the environment variable management to make it more like Envoyer’s. I’m also working on a few things to make Laravel even easier to learn.

关于作者 王赛
源码面前,了无秘密。