by Devin Yang
(This article was automatically translated.)

Published - 7 years ago ( Updated - 7 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


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

Use PHP to clear HiBox's inbox via IMAP

The mailbox for receiving letters has exploded, and I don't want all the letters. Use PHP to clear the inbox. The following is the sample program I copied, with minor adjustments.

docker,phpenv

Unable to ping host.docker.internal on Linux

You can check with docker version, confirm that the version is Docker v20.10+, you can add extra_hosts as follows: