SlideShare une entreprise Scribd logo
1/37 | PHP_FIG-14D02 | © 2014 OSInet
PHP-FIG / PSR
Frédéric G. Marand
2/37 | PHP_FIG-14D02 | © 2014 OSInet
« Interopérabilité des frameworks »
Paris, 02/04/2014
3/37 | PHP_FIG-14D02 | © 2014 OSInet
4/37 | PHP_FIG-14D02 | © 2014 OSInet
Le PHP-FIG
Les PSR en vigueur
Les PSR en cours
Les autres PSR
5/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: Ordre de Mission
● En une phrase:
●
faciliter l'interop rabilité é
●
des frameworks
● entre eux
● Pas concern par:é
● le fonctionnement interne des frameworks
● les sites et applications livrables
● le fonctionnement de PHP (internals)
6/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: objectifs initiaux
● Utilisation des namespaces
● En 2009: nouveauté
● Nommage en POO
● Classes, interfaces, classes de bases abstraites
● Pas de traits: introduits en PHP 5.4 (2010)
● Utilisation des exceptions
http://news.php.net/php.standards/2
7/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: structure
● 19-22/05/09: php-tek Chicago
● R union inopin eé é
● Agavi, CakePHP, PEAR, Phing, Solar, Symfony, Zend Framework, «community-at-large»
● 23/05: Cr ation de la liste priv e «php-standards»é é
● D but des malentendus avec la communauté é
● 02/06: premier membre non fondateur
● Drupal demande participerà
● 09/06: Ouverture de la liste
● Sous la pression de Rasmus Lerdorf
● Aujourd'hui, 38 projets participants
http://news.php.net/php.standards/29
8/37 | PHP_FIG-14D02 | © 2014 OSInet
9/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: organisation
● Membres = projets, != personnes
● 1 projet = 1 voix
● 32k devs Drupal == 37 devs Contao
● S lection des nouveaux entrantsé
● n projets = 1 voix
● Aura/Solar, Composer/Packagist, [Media]Wiki[data] ...
● Assetic/Buzz, Silex/Symfony
● Tous les autres projets = 1 voix
https://groups.google.com/forum/#!topic/php-fig/-twbCjA6EPM
10/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: membres non votants
● Chacun peut participer
● La participation est vraiment prise en
compte
● Ex: Beau Simensen (Sculpin, Silex)
● Ex: PSR-3 :
– inspir par Monologé
– tendu par 3 membres de Drupal mais 1 seule voixé
11/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: pour qui ?
● Les frameworks PHP
● Rapidement tendu aux CMS et bases d'applicationsé
● Focus sur l'interop rabilité é
● Pas pour tous
● Pas les utilisateurs PHP en g n ralé é
– Mais ils sont impact s par les choix de leurs outilsé
● Le rejet l' poque «standards»à é
● Pas les d veloppeurs d'extensions PHPé
12/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: les livrables
● PHP Standards Recommendation
● https://github.com/php-fig/fig-standards/tree/master/accepted
● Licence texte: CC BY 3.0
● Licence code: MIT
● Formalisme: RFC 2119
● Traductions: officielles
● Application
● M me les membres ne sont pas li s par les PSRê é
13/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: gouvernance
● Formalis e, publiqueé
● https://github.com/php-fig/fig-standards/tree/master/bylaws
● Adh sion: «sponsor»é
● PSR:
● discussions ouvertes
● vote ferm de longue dur eé é
● exemple: le retrait de PSR-4
14/37 | PHP_FIG-14D02 | © 2014 OSInet
FIG: ressources
● Mailing-list:
● https://groups.google.com/forum/#!forum/php-fig
● http://news.php.net/php.standards (historique)
● Sites:
● http://www.php-fig.org/
● https://github.com/php-fig/fig-standards
● IRC:
● Freenode #phpfig
15/37 | PHP_FIG-14D02 | © 2014 OSInet
Le PHP-FIG
Les PSR en vigueur
Les PSR en cours
Les autres PSR
16/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR: publi esé
● PSR-0: autoloader historique
● PSR-1: conventions utiles
● PSR-2: conventions futiles
● PSR-3: logger
● PSR-4: autoloader orient packageé
17/37 | PHP_FIG-14D02 | © 2014 OSInet
Le PHP-FIG
Les PSR en vigueur
Les PSR en cours
Les autres PSR
18/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-0: probl me sansè
● le probl meè
● gestion des inclusions
● limitations d'_autoload() spl_autoload_register()→
● que mettre dans la stack de spl_autoload_register()
● les principales solutions
● mapping (registry): cf Drupal 6/7, Phing
● name path→
– complet: PSR-0
– par package: PSR-4
19/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-0: sp c. en brefé
● VendorNameSpaceSymbol
● vendor/name/space/symbol
● PEAR-compatible pour PHP < 5.3
● FooBar_Baz_Quux
● 1 symbole par fichier
● Extension .php
20/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-0: probl mes avecè
● Longs chemins r p titifsé é
● Exemple Drupal 8 pre-PSR4:
● DrupalbookPluginBlockBookNavigationBlock
● (drupal)/core/modules/book/lib/Drupal/book/Plugin
/Block/BookNavigationBlock.php
● Nombre de fichiers: exceptions
● 1 fichier par classe d'exception, 0 ligne de code
● traitement des retours et exceptions
21/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-0: Composer
● Composer
● Est conforme PSR-0
● Est plus efficace que l'exemple standard
● Supporte aussi l'autoload par mapping
● Composer + Packagist
● La «killer app» qui a modernis et relanc PHPé é
● Prise de conscience de l'int r t de PSR-0é ê
22/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-1: basic coding
● Requiert PSR-0 (meta) PSR-4:→
● Format fichiers
● UTF-8 sans BOM
● Tags <?php et <?=, rien d'autre
● Symboles OU effets de bord
● Un (tout petit) peu de style
23/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-2: coding style
● Requiert PSR-1
● Format du code:
● visibilit sp cifi e obligatoireé é é
● switch case sans break autoris , commentaire requisé
● h ritage du pseudo-prot g par «_», d conseillé é é é é
● abstract|final <visibility> static
● 1 instruction/ligne, minuscules, 1 use par import
● multilignes: d finition/appel fonctionsé
24/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-2: coding style (2/2)
● Format de l'espace blanc
● fins de lignes LF, pas d'espaces avant
● LF terminal de fichier
● absence de ?> de fin
● indentation 4 SP, longueur lignes 80/120, bracing K&R
● lignes vierges minimales, extra autoris sé
● Non sp cifié é
● d clarations, alignement, commentairesé
● nommages, bonnes pratiques
25/37 | PHP_FIG-14D02 | © 2014 OSInet
Interm de: PSR-1/2è
26/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-3: logging
● Pour tous: RFC5424 (syslog)
● LogLevel: les niveaux
● LoggerInterface: 1 m thode/niveau + logé
● log($level, $message, $context)
● exception sur niveau invalide
● messsage:
– support au moins de string et object::__toString()
– pas de moyen de le faire savoir aux clients
● les{Place.holders} {_sONt} {4utor1s3s}, ASCII only
27/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-3: logging
● tableau $context
● valeurs des placeholders
● l'impl mentation doit tout accepter sauf des exceptionsé
● sauf dans la clef 'exception', qui peut aussi contenir autre chose
● en pr sence d'erreurs/inconnu:é
– pas de throw
– pas d'erreur
● utilisation des m thodes:é
● toujours passer les param tres, ne pas substituerè
● cf Drupal watchdog()
28/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-3: pour les loggers
● AbstractLogger
● Les 8 m thodes, invoque log()é
● LoggerTrait
● ne dispense pas de d clarer l'interfaceé
● … un trait n'expose pas l'interface qu'il impl menteé
29/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-3: pour les frameworks
● NullLogger
● Pour taire le logger sans avoir testerà
● Pas forc ment une bonne id e: co t du contexteé é û
● LoggerAwareInterface
● Pour la Setter Injection
● LoggerAwareTrait
● impl mente LoggerAwareInterfaceé
● inclut une prior t $loggeré é
30/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-4: package autoloader
● Comme PSR-0, mais
● d marre un point de base du namespaceé à
● VendorNameSpaceSymbol
● space/symbol
● Les «_» n'ont plus de signification
● Casse libre, mais significative
● Throw, erreur et retour de chargeur interdits
– classe non trouv e == erreur d'ex cution du chargeuré é
31/37 | PHP_FIG-14D02 | © 2014 OSInet
PSR-4: le ons de PSR-0ç
● Soutien des filesystems non UNIX
● Z ro codeé
● Trop souvent utilis comme version de r f renceé é é
● Compatibilit Composer PSR-0 et 4é
● http://blog.riff.org/2014_01_04_psr4_really
● R trofit PSR-1: meta-documentsé
32/37 | PHP_FIG-14D02 | © 2014 OSInet
Le PHP-FIG
Les PSR en vigueur
Les PSR en cours
Les autres projets
33/37 | PHP_FIG-14D02 | © 2014 OSInet
Autre: PSR en cours
● PSR en cours:
● PSR-5 PHPdoc
● PSR-6 Cache
– en discussion depuis 02/2012
– minimaliste, mais d saccord sur des bases comme TTL, clear()é
– split base + extensions (CAS, inc...)
● HTTP
– Client, depuis 03/2012, ne parvient pas passerà
– Message, reboot en 01/2014
34/37 | PHP_FIG-14D02 | © 2014 OSInet
Autre: projets rejet sé
● AOP
● Coding style++
● Form
● DB abstraction
● Collections
● EventDispatcher
● GoPHP55
● error_handler
● interpolation
● PSR-R (location)
● PSR-X (PSR-R loader)
● PSR-8 Mutually
Assured Hug
35/37 | PHP_FIG-14D02 | © 2014 OSInet
Autre: container_interop
● Standardiser les DIC
● Difficile
● int r t peu partagé ê é
● mais intense: initiative s par eé é
● Derni rement relanc par...è é
● David N grier :-)é
36/37 | PHP_FIG-14D02 | © 2014 OSInet
Questions ?
37/37 | PHP_FIG-14D02 | © 2014 OSInet
Drupal, faster
http://www.osinet.fr/

Contenu connexe

PDF
Cours.langage c
PDF
Cours de c
PDF
de l'art binaire: des PEs explosifs fait main
PDF
PHPTour-2011-PHP_Extensions
PDF
IDENTIFICATION DES BESOINS DE RENFORCEMENT INSTITUTIONNEL A L'UNIVERSITE D'ET...
PPTX
Cloud
PPT
Questions (1)
PPT
Présentation 2 avril
Cours.langage c
Cours de c
de l'art binaire: des PEs explosifs fait main
PHPTour-2011-PHP_Extensions
IDENTIFICATION DES BESOINS DE RENFORCEMENT INSTITUTIONNEL A L'UNIVERSITE D'ET...
Cloud
Questions (1)
Présentation 2 avril

En vedette (20)

PDF
Pneumologie angiostrongylose chez une jeune chienne
PPTX
Présentation1
KEY
Commands
PPTX
латинский квартал пантеон набережные сены
PDF
Ouverture du Centre PMA (Procréation Médicalement Assistée)
PPT
Sug bordeaux 20120515
PPTX
Fondation Marocaine de l'Etudiant
PPT
Tableaux Cezanne
PPT
PPT
Mon village natal vylgort
PPTX
Attractyouraudience
DOCX
Pneumologie affections respiratoires ovines
PPTX
Part con conv 2012 asset management lynn melna french
PPTX
Colloque CIRCUIT ME Mathieu Phd v1.1
PDF
La Tribune, Panorama des classements des grandes écoles
PPT
Projet de naissance-110525152259-phpapp02
PDF
Naive Data Discovery MsTechdays Data of Interest
PPS
Carnaval de-nice-2011-stelaspinoie
PDF
Login People The Digital Dna Brochure Fr
PPTX
Évaluation de la politique de subvention des SONU au Burkina Faso
Pneumologie angiostrongylose chez une jeune chienne
Présentation1
Commands
латинский квартал пантеон набережные сены
Ouverture du Centre PMA (Procréation Médicalement Assistée)
Sug bordeaux 20120515
Fondation Marocaine de l'Etudiant
Tableaux Cezanne
Mon village natal vylgort
Attractyouraudience
Pneumologie affections respiratoires ovines
Part con conv 2012 asset management lynn melna french
Colloque CIRCUIT ME Mathieu Phd v1.1
La Tribune, Panorama des classements des grandes écoles
Projet de naissance-110525152259-phpapp02
Naive Data Discovery MsTechdays Data of Interest
Carnaval de-nice-2011-stelaspinoie
Login People The Digital Dna Brochure Fr
Évaluation de la politique de subvention des SONU au Burkina Faso
Publicité

Similaire à Le groupe PHP-FIG et les standards PSR (20)

PDF
Bonnes pratiques de developpement en PHP
PPTX
PHP5: Endgame
PDF
PHP et Performances - AFUP 2005
PDF
Php 7 Think php7
ODP
Introduction à PHP - Forum PHP 2010 - AFUP
PDF
Etat de l'art des systèmes embarqués, utilisation du logiciel libre
ODP
Formation Linux lpi 101
PDF
C1 linux et intro c
PDF
C1 linux et intro c
PDF
Monitoring d'applications/environnements PHP : APM et Pinba
ODP
Cours PHP 1/4 - Pierre Rudloff
ODP
Cours PHP 1
PDF
Nouveautés php 7
PDF
PHP Tour 2012 - Conférence FuelPHP
PDF
Fuel php nantes 2012
PDF
Formation GIT gratuite par ippon 2014
PDF
Sizing PoC LSF & PowerAI for Engineers schools workloads
PDF
Présentation de PHP
PDF
Audit openERP 7.0: Mise en place &Optimisation de Performances
PDF
Architecture d'annuaire hautement disponible avec OpenLDAP
Bonnes pratiques de developpement en PHP
PHP5: Endgame
PHP et Performances - AFUP 2005
Php 7 Think php7
Introduction à PHP - Forum PHP 2010 - AFUP
Etat de l'art des systèmes embarqués, utilisation du logiciel libre
Formation Linux lpi 101
C1 linux et intro c
C1 linux et intro c
Monitoring d'applications/environnements PHP : APM et Pinba
Cours PHP 1/4 - Pierre Rudloff
Cours PHP 1
Nouveautés php 7
PHP Tour 2012 - Conférence FuelPHP
Fuel php nantes 2012
Formation GIT gratuite par ippon 2014
Sizing PoC LSF & PowerAI for Engineers schools workloads
Présentation de PHP
Audit openERP 7.0: Mise en place &Optimisation de Performances
Architecture d'annuaire hautement disponible avec OpenLDAP
Publicité

Plus de OSInet (15)

PPTX
Interface texte plein écran en Go avec TView
PDF
Scaling up and accelerating Drupal 8 with NoSQL
PDF
Mon site web est hacké ! Que faire ?
PDF
Faster Drupal sites using Queue API
PDF
Life after the hack
PDF
Delayed operations with queues for website performance
PDF
Drupal 8 : regards croisés
PDF
Cache speedup with Heisencache for Drupal 7 and Drupal 8
PDF
Recueil des mauvaises pratiques constatées lors de l'audit de sites Drupal 7
PDF
Les blocs Drupal de drop.org à Drupal 8
ODP
Utiliser drupal
ODP
Equipe drupal
ODP
Pourquoi choisir un CMS Open Source ?
PDF
Drupal et le NoSQL - drupagora 2011
ODP
Drupal Views development
Interface texte plein écran en Go avec TView
Scaling up and accelerating Drupal 8 with NoSQL
Mon site web est hacké ! Que faire ?
Faster Drupal sites using Queue API
Life after the hack
Delayed operations with queues for website performance
Drupal 8 : regards croisés
Cache speedup with Heisencache for Drupal 7 and Drupal 8
Recueil des mauvaises pratiques constatées lors de l'audit de sites Drupal 7
Les blocs Drupal de drop.org à Drupal 8
Utiliser drupal
Equipe drupal
Pourquoi choisir un CMS Open Source ?
Drupal et le NoSQL - drupagora 2011
Drupal Views development

Le groupe PHP-FIG et les standards PSR

  • 1. 1/37 | PHP_FIG-14D02 | © 2014 OSInet PHP-FIG / PSR Frédéric G. Marand
  • 2. 2/37 | PHP_FIG-14D02 | © 2014 OSInet « Interopérabilité des frameworks » Paris, 02/04/2014
  • 3. 3/37 | PHP_FIG-14D02 | © 2014 OSInet
  • 4. 4/37 | PHP_FIG-14D02 | © 2014 OSInet Le PHP-FIG Les PSR en vigueur Les PSR en cours Les autres PSR
  • 5. 5/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: Ordre de Mission ● En une phrase: ● faciliter l'interop rabilité é ● des frameworks ● entre eux ● Pas concern par:é ● le fonctionnement interne des frameworks ● les sites et applications livrables ● le fonctionnement de PHP (internals)
  • 6. 6/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: objectifs initiaux ● Utilisation des namespaces ● En 2009: nouveauté ● Nommage en POO ● Classes, interfaces, classes de bases abstraites ● Pas de traits: introduits en PHP 5.4 (2010) ● Utilisation des exceptions http://news.php.net/php.standards/2
  • 7. 7/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: structure ● 19-22/05/09: php-tek Chicago ● R union inopin eé é ● Agavi, CakePHP, PEAR, Phing, Solar, Symfony, Zend Framework, «community-at-large» ● 23/05: Cr ation de la liste priv e «php-standards»é é ● D but des malentendus avec la communauté é ● 02/06: premier membre non fondateur ● Drupal demande participerà ● 09/06: Ouverture de la liste ● Sous la pression de Rasmus Lerdorf ● Aujourd'hui, 38 projets participants http://news.php.net/php.standards/29
  • 8. 8/37 | PHP_FIG-14D02 | © 2014 OSInet
  • 9. 9/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: organisation ● Membres = projets, != personnes ● 1 projet = 1 voix ● 32k devs Drupal == 37 devs Contao ● S lection des nouveaux entrantsé ● n projets = 1 voix ● Aura/Solar, Composer/Packagist, [Media]Wiki[data] ... ● Assetic/Buzz, Silex/Symfony ● Tous les autres projets = 1 voix https://groups.google.com/forum/#!topic/php-fig/-twbCjA6EPM
  • 10. 10/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: membres non votants ● Chacun peut participer ● La participation est vraiment prise en compte ● Ex: Beau Simensen (Sculpin, Silex) ● Ex: PSR-3 : – inspir par Monologé – tendu par 3 membres de Drupal mais 1 seule voixé
  • 11. 11/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: pour qui ? ● Les frameworks PHP ● Rapidement tendu aux CMS et bases d'applicationsé ● Focus sur l'interop rabilité é ● Pas pour tous ● Pas les utilisateurs PHP en g n ralé é – Mais ils sont impact s par les choix de leurs outilsé ● Le rejet l' poque «standards»à é ● Pas les d veloppeurs d'extensions PHPé
  • 12. 12/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: les livrables ● PHP Standards Recommendation ● https://github.com/php-fig/fig-standards/tree/master/accepted ● Licence texte: CC BY 3.0 ● Licence code: MIT ● Formalisme: RFC 2119 ● Traductions: officielles ● Application ● M me les membres ne sont pas li s par les PSRê é
  • 13. 13/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: gouvernance ● Formalis e, publiqueé ● https://github.com/php-fig/fig-standards/tree/master/bylaws ● Adh sion: «sponsor»é ● PSR: ● discussions ouvertes ● vote ferm de longue dur eé é ● exemple: le retrait de PSR-4
  • 14. 14/37 | PHP_FIG-14D02 | © 2014 OSInet FIG: ressources ● Mailing-list: ● https://groups.google.com/forum/#!forum/php-fig ● http://news.php.net/php.standards (historique) ● Sites: ● http://www.php-fig.org/ ● https://github.com/php-fig/fig-standards ● IRC: ● Freenode #phpfig
  • 15. 15/37 | PHP_FIG-14D02 | © 2014 OSInet Le PHP-FIG Les PSR en vigueur Les PSR en cours Les autres PSR
  • 16. 16/37 | PHP_FIG-14D02 | © 2014 OSInet PSR: publi esé ● PSR-0: autoloader historique ● PSR-1: conventions utiles ● PSR-2: conventions futiles ● PSR-3: logger ● PSR-4: autoloader orient packageé
  • 17. 17/37 | PHP_FIG-14D02 | © 2014 OSInet Le PHP-FIG Les PSR en vigueur Les PSR en cours Les autres PSR
  • 18. 18/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-0: probl me sansè ● le probl meè ● gestion des inclusions ● limitations d'_autoload() spl_autoload_register()→ ● que mettre dans la stack de spl_autoload_register() ● les principales solutions ● mapping (registry): cf Drupal 6/7, Phing ● name path→ – complet: PSR-0 – par package: PSR-4
  • 19. 19/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-0: sp c. en brefé ● VendorNameSpaceSymbol ● vendor/name/space/symbol ● PEAR-compatible pour PHP < 5.3 ● FooBar_Baz_Quux ● 1 symbole par fichier ● Extension .php
  • 20. 20/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-0: probl mes avecè ● Longs chemins r p titifsé é ● Exemple Drupal 8 pre-PSR4: ● DrupalbookPluginBlockBookNavigationBlock ● (drupal)/core/modules/book/lib/Drupal/book/Plugin /Block/BookNavigationBlock.php ● Nombre de fichiers: exceptions ● 1 fichier par classe d'exception, 0 ligne de code ● traitement des retours et exceptions
  • 21. 21/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-0: Composer ● Composer ● Est conforme PSR-0 ● Est plus efficace que l'exemple standard ● Supporte aussi l'autoload par mapping ● Composer + Packagist ● La «killer app» qui a modernis et relanc PHPé é ● Prise de conscience de l'int r t de PSR-0é ê
  • 22. 22/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-1: basic coding ● Requiert PSR-0 (meta) PSR-4:→ ● Format fichiers ● UTF-8 sans BOM ● Tags <?php et <?=, rien d'autre ● Symboles OU effets de bord ● Un (tout petit) peu de style
  • 23. 23/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-2: coding style ● Requiert PSR-1 ● Format du code: ● visibilit sp cifi e obligatoireé é é ● switch case sans break autoris , commentaire requisé ● h ritage du pseudo-prot g par «_», d conseillé é é é é ● abstract|final <visibility> static ● 1 instruction/ligne, minuscules, 1 use par import ● multilignes: d finition/appel fonctionsé
  • 24. 24/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-2: coding style (2/2) ● Format de l'espace blanc ● fins de lignes LF, pas d'espaces avant ● LF terminal de fichier ● absence de ?> de fin ● indentation 4 SP, longueur lignes 80/120, bracing K&R ● lignes vierges minimales, extra autoris sé ● Non sp cifié é ● d clarations, alignement, commentairesé ● nommages, bonnes pratiques
  • 25. 25/37 | PHP_FIG-14D02 | © 2014 OSInet Interm de: PSR-1/2è
  • 26. 26/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-3: logging ● Pour tous: RFC5424 (syslog) ● LogLevel: les niveaux ● LoggerInterface: 1 m thode/niveau + logé ● log($level, $message, $context) ● exception sur niveau invalide ● messsage: – support au moins de string et object::__toString() – pas de moyen de le faire savoir aux clients ● les{Place.holders} {_sONt} {4utor1s3s}, ASCII only
  • 27. 27/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-3: logging ● tableau $context ● valeurs des placeholders ● l'impl mentation doit tout accepter sauf des exceptionsé ● sauf dans la clef 'exception', qui peut aussi contenir autre chose ● en pr sence d'erreurs/inconnu:é – pas de throw – pas d'erreur ● utilisation des m thodes:é ● toujours passer les param tres, ne pas substituerè ● cf Drupal watchdog()
  • 28. 28/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-3: pour les loggers ● AbstractLogger ● Les 8 m thodes, invoque log()é ● LoggerTrait ● ne dispense pas de d clarer l'interfaceé ● … un trait n'expose pas l'interface qu'il impl menteé
  • 29. 29/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-3: pour les frameworks ● NullLogger ● Pour taire le logger sans avoir testerà ● Pas forc ment une bonne id e: co t du contexteé é û ● LoggerAwareInterface ● Pour la Setter Injection ● LoggerAwareTrait ● impl mente LoggerAwareInterfaceé ● inclut une prior t $loggeré é
  • 30. 30/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-4: package autoloader ● Comme PSR-0, mais ● d marre un point de base du namespaceé à ● VendorNameSpaceSymbol ● space/symbol ● Les «_» n'ont plus de signification ● Casse libre, mais significative ● Throw, erreur et retour de chargeur interdits – classe non trouv e == erreur d'ex cution du chargeuré é
  • 31. 31/37 | PHP_FIG-14D02 | © 2014 OSInet PSR-4: le ons de PSR-0ç ● Soutien des filesystems non UNIX ● Z ro codeé ● Trop souvent utilis comme version de r f renceé é é ● Compatibilit Composer PSR-0 et 4é ● http://blog.riff.org/2014_01_04_psr4_really ● R trofit PSR-1: meta-documentsé
  • 32. 32/37 | PHP_FIG-14D02 | © 2014 OSInet Le PHP-FIG Les PSR en vigueur Les PSR en cours Les autres projets
  • 33. 33/37 | PHP_FIG-14D02 | © 2014 OSInet Autre: PSR en cours ● PSR en cours: ● PSR-5 PHPdoc ● PSR-6 Cache – en discussion depuis 02/2012 – minimaliste, mais d saccord sur des bases comme TTL, clear()é – split base + extensions (CAS, inc...) ● HTTP – Client, depuis 03/2012, ne parvient pas passerà – Message, reboot en 01/2014
  • 34. 34/37 | PHP_FIG-14D02 | © 2014 OSInet Autre: projets rejet sé ● AOP ● Coding style++ ● Form ● DB abstraction ● Collections ● EventDispatcher ● GoPHP55 ● error_handler ● interpolation ● PSR-R (location) ● PSR-X (PSR-R loader) ● PSR-8 Mutually Assured Hug
  • 35. 35/37 | PHP_FIG-14D02 | © 2014 OSInet Autre: container_interop ● Standardiser les DIC ● Difficile ● int r t peu partagé ê é ● mais intense: initiative s par eé é ● Derni rement relanc par...è é ● David N grier :-)é
  • 36. 36/37 | PHP_FIG-14D02 | © 2014 OSInet Questions ?
  • 37. 37/37 | PHP_FIG-14D02 | © 2014 OSInet Drupal, faster http://www.osinet.fr/