Slide 1

Slide 1 text

PHP & standards @mheap (at) #phptek

Slide 2

Slide 2 text

About Me

Slide 3

Slide 3 text

About Me Michael

Slide 4

Slide 4 text

About Me @mheap

Slide 5

Slide 5 text

About Me @DataSift

Slide 6

Slide 6 text

History

Slide 7

Slide 7 text

Composer

Slide 8

Slide 8 text

The FIG

Slide 9

Slide 9 text

History

Slide 10

Slide 10 text

Agavi - David Zülke Cake - Nate Abele PEAR - Brett Bieber, David Coallier, Helgi Þormar Þorbjörnsson, Travis Swicegood, Phing - Travis Swicegood Solar - Paul Jones Symfony - Stefan Koopmanschap Zend Framework - Matthew Weier O'Phinney and the always amiable (i.e., at-large community member), Cal Evans. May 21st, 2009

Slide 11

Slide 11 text

Current Members

Slide 12

Slide 12 text

Accepted

Slide 13

Slide 13 text

PSR-0 Autoloading

Slide 14

Slide 14 text

Slide 15

Slide 15 text

Slide 16

Slide 16 text

Slide 17

Slide 17 text

Slide 18

Slide 18 text

Tek_Demo_Example => Tek/Demo/Example.php Tek_Demo_Foo => Tek/Demo/Foo.php Tek_Something => Tek/Something.php

Slide 19

Slide 19 text

Tek_Demo_Example => Tek/Demo/Example.php Tek_Demo_Foo => Tek/Demo/Foo.php Tek_Something => Tek/Something.php Datasift\Filter\Sentiment => Datasift/Filter/Sentiment.php Datasift\Service\Auth => Datasift/Service/Auth.php Datasift\User => Datasift/User.php

Slide 20

Slide 20 text

Tek_Demo_Example => Tek/Demo/Example.php Tek\Demo\Example => Tek/Demo/Example.php Tek\Demo_File\Example => Tek/Demo_File/Example.php Tek\Demo\Example_Foo => Tek/Demo/Example/Foo.php Demo => Demo.php

Slide 21

Slide 21 text

Using PSR-0

Slide 22

Slide 22 text

PSR-0 Autoloading

Slide 23

Slide 23 text

PSR-1 Basic Coding Standard

Slide 24

Slide 24 text

Use Tabs Or Spaces

Slide 25

Slide 25 text

Requires PSR0

Slide 26

Slide 26 text

echo "Hello World";

Slide 27

Slide 27 text

class AdminUser { const PERMISSION_LIST = array("add", "delete"); function createAnnouncement() { } }

Slide 28

Slide 28 text

PSR-1 Basic Coding Standard

Slide 29

Slide 29 text

PSR-2 Coding Style Guide

Slide 30

Slide 30 text

http://bit.ly/1PWqjOK

Slide 31

Slide 31 text

One Statement Per Line

Slide 32

Slide 32 text

No Trailing Whitespace

Slide 33

Slide 33 text

Function Visibility Must Be Declared

Slide 34

Slide 34 text

4 Spaces For Indentation

Slide 35

Slide 35 text

Property Names No Leading Underscore

Slide 36

Slide 36 text

There MUST be one space after the control structure keyword There MUST NOT be a space after the opening parenthesis There MUST NOT be a space before the closing parenthesis There MUST be one space between the closing parenthesis and the opening brace

Slide 37

Slide 37 text

# Breaks PSR2 if ('awesome' == $tek){ } # Valid. Adds the space # before the opening brace if ('awesome' == $tek) { }

Slide 38

Slide 38 text

Recommendations Not Demands

Slide 39

Slide 39 text

Using PSR-2

Slide 40

Slide 40 text

PHPCS phpcs --standard=psr2

Slide 41

Slide 41 text

PHPCBF phpcbf --standard=psr2

Slide 42

Slide 42 text

PSR-2 Coding Style Guide

Slide 43

Slide 43 text

PSR-3 Logger Interface

Slide 44

Slide 44 text

18 Yes 0 No

Slide 45

Slide 45 text

RFC 5424 Syslog

Slide 46

Slide 46 text

Emergency – the system is unusable Alert – immediate action is required Critical – critical conditions Error – errors that do not require immediate attention but should be monitored Warning – unusual or undesirable occurrences that are not errors Notice – normal but significant events Info – interesting events Debug – detailed information for debugging purposes

Slide 47

Slide 47 text

$logger->info( "This is an informational message” );

Slide 48

Slide 48 text

$logger->alert( "This is an alert message” );

Slide 49

Slide 49 text

$logger->alert( "This is an alert message", array("user" => $user->id) );

Slide 50

Slide 50 text

Using PSR-3

Slide 51

Slide 51 text

Monolog

Slide 52

Slide 52 text

Analog

Slide 53

Slide 53 text

KLogger

Slide 54

Slide 54 text

PSR-3 Logger Interface

Slide 55

Slide 55 text

PSR-4 Autoloader (again)

Slide 56

Slide 56 text

Replaces PSR-0

Slide 57

Slide 57 text

No More _

Slide 58

Slide 58 text

vendor/ vendor_name/ package_name/ src/ Vn/ Pn/ ClassName.php composer.json: "autoload": { "psr-0": { "Vn\\Pn\\": "src/" } }

Slide 59

Slide 59 text

vendor/ vendor_name/ package_name/ src/ ClassName.php composer.json: "autoload": { "psr-4": { "Vn\\Pn\\": "src/" } }

Slide 60

Slide 60 text

vendor/ vendor_name/ package_name/ src/ Vn/ Pn/ ClassName.php composer.json: "autoload": { "psr-4": { "Vn\\Pn\\": "src/Vn/Pn/" } }

Slide 61

Slide 61 text

Using PSR-4

Slide 62

Slide 62 text

PSR-4 Autoloader (again)

Slide 63

Slide 63 text

PSR-7 HTTP Message

Slide 64

Slide 64 text

POST /path HTTP/1.1 Host: example.com foo=bar&baz=bat

Slide 65

Slide 65 text

HTTP/1.1 200 OK Content-Type: text/plain This is the response body

Slide 66

Slide 66 text

HttpFoundation

Slide 67

Slide 67 text

Zend\Http

Slide 68

Slide 68 text

$otherFramework

Slide 69

Slide 69 text

PSR-7

Slide 70

Slide 70 text

Requests

Slide 71

Slide 71 text

Responses

Slide 72

Slide 72 text

Streaming

Slide 73

Slide 73 text

File Uploads

Slide 74

Slide 74 text

HTTP

Slide 75

Slide 75 text

Psr\Http\Message\MessageInterface Psr\Http\Message\RequestInterface Psr\Http\Message\ServerRequestInterface Psr\Http\Message\ResponseInterface Psr\Http\Message\StreamInterface Psr\Http\Message\UriInterface Psr\Http\Message\UploadedFileInterface

Slide 76

Slide 76 text

PSR-7 HTTP Message

Slide 77

Slide 77 text

PSR-0 PSR-1 PSR-2 PSR-3 PSR-4 PSR-7 Autoloading Basic Coding Coding Style Guide Logger Interface Autoloading HTTP Message Interface

Slide 78

Slide 78 text

Proposed

Slide 79

Slide 79 text

PSR-5 PHPDoc

Slide 80

Slide 80 text

PSR-6 Cache

Slide 81

Slide 81 text

PSR-8 Huggable Interface

Slide 82

Slide 82 text

PSR-9 Security Disclosure

Slide 83

Slide 83 text

PSR-10 Security Advisories

Slide 84

Slide 84 text

@mheap joind.in/13759