sajad torkamani

What is PSR?

PSR stands for PHP Standards Recommendation and is a set of guidelines published by the PHP-FIG (PHP Framework Interop Group) to standardise things across PHP projects, especially libraries and frameworks.

What kind of standards does PSR define?

  • Coding style
    • PSR-1: Basic coding standards (e.g., class names must be StudlyCaps, files must use <?php, etc).
    • PSR-12: Standards for indentation, spacing, etc.
  • Autoloading
    • PSR-4: Defines autoloading standards using namespaces and directory structures.
    • PSR-0: The now deprecated autoloading standards.
  • Containers & Services
    • PSR-11: Defines standards for dependency injection containers (defines a common ContainerInterface).
  • HTTP messaging
    • PSR-7: HTTP message interfaces (defines RequestInterface, ResponseInterface).
    • PSR-15: HTTP middleware interface (defines how middleware should be written).
    • PSR-17: HTTP factory interfaces for creating PSR-7 compliant objects.
  • Logging & Caching
    • PSR-3 (GitHub repo): Logging interfaces (defines a LoggerInterface with particular levels like info, error, etc).
    • PSR-6: Low-level, pool-based acching interface.
    • PSR-16: Simplified caching interface (key-value style)
Tagged: PHP