Home  >  Article  >  ThinkPHP6.0 is officially released today

ThinkPHP6.0 is officially released today

藏色散人
藏色散人forward
2019-10-24 10:41:524806browse

Released on October 24, 2019

The official ThinkPHP 6.0 version, which took more than a year to build, is officially released. This version is based on the two principles of streamlined core and unified usage. On the basis of 5.1, the underlying architecture has been further optimized and improved, and it has been more standardized.

Due to the introduction of some new features, the ThinkPHP6.0 operating environment requires PHP7.1 (PHP7.3 is recommended) and does not support seamless upgrades to 5.1 (official upgrade guidance is provided).

Recommended video tutorial: "ThinkPHP6.0 Quick Start"

Main features:

● Use PHP7 strong typing ( Strict mode)

● Support more PSR specifications

● Multi-application support

● ORM component independence

● Improved middleware mechanism

● Servitization of core architecture

● Brand new event system

● Container function enhancement

● Template engine component independence

● Internal functions Middlewareization

● SESSION mechanism improvement

● Cache and log support multi-channel

● Introduction of Filesystem component

● Improvement of Swoole and coroutine support

● More friendly to IDE

● Unify and streamline a large number of usages

Strong typing and strict mode

In mainstream frameworks , ThinkPHP6.0 is the first to adopt PHP7 strict mode. All core files have strict mode type constraints turned on, so if any variable type does not match, an exception will be thrown, which is helpful to standardize the variable types in the code and detect potential problems in advance.

Multi-application mode

The new version of the framework provides multi-application mode support. The default installation is a single application. You only need to install a multi-application mode extension to make it easier. Deploy multiple applications without repeatedly installing dependent components. Each application supports independent portal access and domain name binding. You can also use one portal file to implement automatic multi-application deployment. And the automatic multi-application mode supports intelligent identification, and will automatically switch to the single-application mode for matching when accessing non-existent applications. It also supports application mapping and access prohibition mechanisms.

The design of multi-application mode can make development more modular, because the configuration, routing and views of each application can be included in the application directory, so it is more convenient to modularize applications, and even introduce composer applications.

Containers and Services

The new version of containers supports the PSR-11 specification. The functional features of the container class mainly include:

● Binding classes and objects Instance, interface to container

● Create an instance of the class (get it directly if it exists)

● Container object binding alias

● Support container object (instantiation) callback

● Obtain the container object instance

● Delete the object instance in the container

● Provide dependency injection and facade implementation support

● Call the method of the container object instance (or closure)

● Provide ArrayAccess support for container objects

Event system

The new version of the event system can be regarded as the 5.1 version behavior system An upgraded version, the event system is more powerful than the behavioral system in that the event itself can be a class and can better support event subscribers. Supports event smart subscription and uses reflection mechanism to identify the events that current subscribers want to subscribe to.

The advantage of events compared to middleware is that events are more accurately positioned (or more granular) than middleware, and are more suitable for the expansion of some business scenarios. For example, we usually encounter users who need to perform a series of operations after registering or logging in. Through the event system, we can complete the login operation expansion without invading the original code, which not only reduces the coupling of the system, but also reduces the possibility of BUG. .

Middleware support is perfect

Middleware is divided into global middleware, application middleware, routing middleware and controller middleware. These four middleware groups are completely Execute independently, but middleware in the same group will not be executed repeatedly. The middleware method performs dependency injection and a callback mechanism for request completion.

Many core functions are completed based on middleware, including multi-application mode, which is also executed using the middleware mechanism.

Routing and requests

The new version of routing streamlines many unnecessary functions, the routing definition is more standardized and semantic, and the routing definition file supports inclusion in the application directory. Facilitates modular development. The routing annotation function is independent of the think-annotation library, and its use is more standardized and supports IDE prompts.

The new version of the request object is easier to expand. The system provides an app\Request class after default installation. You can directly customize the request object in the application and add necessary attributes and methods. But it will not affect dependency injection and facade calls to think\Request.

system service

Since the core framework adopts a service-oriented design, you can register the required services in your extension or application. Register an object in the system service to the container, or perform related dependency injection on certain objects. Due to the execution priority of system services, it can be ensured that relevant components have completed relevant dependency injection when executing. A service class usually includes registration and boot methods for execution at different stages.

ORM componentization

The built-in ORM function has been completely independent as a think-orm component and can be used independently. ThinkPHP6.0 relies on this component to be installed by default, so keep the usage. While remaining unchanged, the query function has been enhanced.

Template engine componentization

The core no longer has any built-in template engine, and only provides PHP template support. The official template engine has been independent as think-template template engine, and Depends on installation by default. You can use third-party template engines more conveniently.

Log system

The log supports multiple channels, and unifies the command line and WEB log formats, mainly including:

● The log adds multi-channel support, Multiple channels can be written at the same time or switched

● The logging formats of WEB and CLI are unified, and log formatting is supported

● Improvements to JSON log format

● Support log writing events

Session mechanism improvement

The Session mechanism of version 6.0 has been completely rewritten, and the built-in Session mechanism of PHP is no longer used, and a new implementation is implemented Session mechanism can better support Swoole/Workerman and other environments.

So PHP's built-in session_*** series of functions are no longer supported, nor is it supported to use $_SESSION to read session data. You must operate through the Session class or facade provided by the framework, and the Request class is also encapsulated Reading of session data.

Session supports cross-application reading and custom serialization mechanisms. By default, the file type is used to record Session data. Due to the shared cache mechanism, you can also use any supported cache type to record Session data.

Introducing the Filesystem component

The new version adds the Filesystem class library to strengthen support for the file system, and can easily support various cloud storages, including Alibaba Cloud and Seven Niu Yun.

Swoole extension improvements

Swoole extension supports both HTTP and Socket services, supports database and cache connection pool functions, and RPC functions.

Debugging tool update

The original built-in page Trace debugging tool has been changed to an extension mode, and the think-trace extension has been installed instead. If the application is installed through composer, The topthink/think-trace extension is installed by default.

The basic usage remains the same as before, but no additional configuration is required. By default, it is displayed in html mode. It still supports browser console display and is only valid in debugging mode.

At the same time, a debugging extension think-debugbar based on debugbar has been added, which needs to be installed separately before it can be used.

composer require topthink/think-debugbar

Unify and streamline a large number of usages

The new version streamlines and unifies many usages to avoid the confusion of inconsistent specifications during the development process.

Development Manual

For more information, you can view ThinkPHP6.0's "TP6 Complete Development Manual"

Holding a With original intention and persistence, ThinkPHP has always insisted on improving and updating, and has continuously released multiple major versions in the past 13 years. In fact, all major versions of ThinkPHP in history have provided support and maintenance for more than 18 months. The current maintenance plan announcement for major versions of ThinkPHP is as follows:

ThinkPHP6.0 is officially released today

ThinkPHP6. 0 GitHub address:

https://github.com/top-think/think?tdsourcetag=s_pctim_aiomsg

https://github .com/top-think/framework?tdsourcetag=s_pctim_aiomsg

Statement:
This article is reproduced at:thinkphp. If there is any infringement, please contact admin@php.cn delete