by Devin Yang
(This article was automatically translated.)

Published - 6 years ago ( Updated - 6 years ago )

The full name of PSR is called "PHP Standards Recommendations" (PHP Standards Recommendations). A proposed specification by FIG (PHP Framework Interoperability Group),
This group was initiated by some framework developers in php|tek in 2009, from the first 5 to more than 20 now.

There are many numbers in the "PHP Standard Recommendations", each number represents a different specification .

E.g:
PHP standard recommendation number 1 ( PSR-1 ), the basic coding standard . For example, the name of the class (Class) must be declared as StudlyCaps, the name of the method (Method) must be declared as camelCase.. etc.
The PHP standard recommendation number 2 ( PSR-2 ) is an extension of PSR-1, which regulates the PHP coding style , such as extends or implements must be on the same line as the class name...etc.
PHP standard recommendation number 4 ( PSR-4 ) defines automatic loading ( Autoloader standard ), Composer is also a member of FIG ,
For example, in the current Laravel framework, his composer.json can see the trace of using PSR-4 automatic loading,
Because the automatic loading of PSR-0 has been listed as deprecated (DEPRECATED), but there is still support in composer , if you really want to use it.

In the table below, I list the approved specifications, and of course there are also those in the review and draft stages. If you are interested, please refer to the link on the right: Recommendations (PSRs)
Num Title Editor Coordinator Sponsors
1 Basic Coding Standard Paul M. Jones N/A N/A
2 Coding Style Guide Paul M. Jones N/A N/A
3 Logger Interface Jordi Boggiano N/A N/A
4 Autoloading Standard Paul M. Jones Phil Sturgeon Larry Garfield
6 Caching Interface Larry Garfield Paul Dragoonis Robert Hafner
7 HTTP Message Interface Matthew Weier O'Phinney Beau Simensen Paul M. Jones
11 Container Interface Matthieu Napoli, David Negrir Matthew Weier O'Phinney Korvin Szanto
13 Hypermedia Links Larry Garfield Matthew Weier O'Phinney Marc Alexander
16 Simple Cache Paul Dragoonis Jordi Boggiano Fabien Potencier
 
Take PSR-7 HTTP Message Interface as an example:
The reqeust and response objects in the Slim framework support the PSR-7 interface, which makes Slim very free to use any PSR-7 implementation.
E.g:
The route of the Slim program can not return the \Slim\Http\Response instance. It can return the \GuzzleHttp\Psr7\CachingStream instance,
Although Slim provides a PSR-7 implementation, we are free to change the default PSR 7 objects in Slim to other third-party implementations.
 
In the Laravel framework, we can obtain a PSR-7 instance reqeust instead of Laravel's request by installing a library.
composer require symfony/psr-http-message-bridge
composer require zendframework/zend-diactoros

Once we installed these kits, we were able to get the PSR-7 requirements.
use Psr\Http\Message\ServerRequestInterface;
Route::get('/', function (ServerRequestInterface $request) {
//
});


 

Tags: php

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


phpenv

phpenv database environment

This article describes how to pull out the database service of phpenv to an independent environment. PHPENV can define database services in SERVICE through environment variables. If necessary in the development environment, we can easily restart all services, nginx, fpm and db through commands such as ./start and ./restart. But if it is in online mode, I don't want to restart the website, even the entire DB is restarted. For example, when the php version is updated, the DB does not need to be restarted.

php,linux

WebShell Function Introduction and Precautions

I suddenly wanted to introduce what is WebShell, so I found one on the Internet. Its functions are quite good. But I still wanted some features, so I spent three nights making some small optimizations for him. If you haven't heard of WebShell yet, take a look at this video. If you like my optimized version, please give me a like, thank you.

php,docker,dlaravel

A brief introduction to the phpenv container environment I built

I don't have time to shoot an introduction video, so I'll just grab some pictures and introduce the container environment deviny/phpenv I use. https://github.com/DevinY/phpenvphpenv can be regarded as an evolutionary version of my previous D-Laravel open source project, conceptually extending the use of many Dlaravel operation methods. The update of the container tends to be controlled by the user to build his own image, so I am not very good at changing the version number. In fact, the php version number of D-Laravel seems to have not been changed for a long time:p