• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Php psr standard 2014 01-22
 

Php psr standard 2014 01-22

on

  • 2,613 views

 

Statistics

Views

Total Views
2,613
Views on SlideShare
2,613
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Php psr standard 2014 01-22 Php psr standard 2014 01-22 Presentation Transcript

    • PHP for Enterprise PSR Introduction
    • Võ Duy Tuấn CEO/Founder @ spiral.vn  PHP 5 Zend Certified Engineer  Mobile App Developer  Web Developer & Designer  Interest: o PHP o Large System & Data Mining o Web Performance Optimization o Mobile Development
    • AGENDA Why Standard? How case-sensitive server kills PSR-0? Question & Answer
    • 1. Why Standard?
    • PSR FAMILY (http://www.php-fig.org/) • • • • • PSR-0 PSR-1 PSR-2 PSR-3 PSR-4
    • PSR-0 : Autoloading • • • • • • • A fully-qualified namespace and class must have the following structure <Vendor Name>(<Namespace>)*<Class Name> Each namespace must have a top-level namespace ("Vendor Name"). Each namespace can have as many sub-namespaces as it wishes. Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system. Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no special meaning in the namespace. The fully-qualified namespace and class is suffixed with .php when loading from the file system. Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case.
    • PSR-1 : Basic Coding Standard • Files MUST use only <?php and <?= tags. • Files MUST use only UTF-8 without BOM for PHP code. • Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both. • Namespaces and classes MUST follow PSR-0. • Class names MUST be declared in StudlyCaps. • Class constants MUST be declared in all upper case with underscore separators. • Method names MUST be declared in camelCase.
    • PSR-2 : Coding Style Guide • • • • • • • • • • Code MUST follow PSR-1. Code MUST use 4 spaces for indenting, not tabs. There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less. There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations. Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body. Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body. Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility. Control structure keywords MUST have one space after them; method and function calls MUST NOT. Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body. Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.
    • 2. How Case-sensitive server kills PSR-0 ?
    • PSR-0 PROBLEM • If user type: http://abc.com/admin/product -> Most framework rewrite engine will parsing URL and return information about included controller: - Module: admin - Controller: product - Action: index (default)
    • PSR-0 PROBLEM (cont..) • If follow PSR-0, your autoloader will include controller file somewhere like: …/controller/admin/product.php • And, your controller class must be something like : <?php namespace controlleradmin; class product extends basecontroller { … }
    • Where is Problem ?!
    • PSR-0 PROBLEM (cont..) • If follow PSR-1, your Class name must be something like: Product not product • And, if your classname is Product, your controller file must be: …/controller/admin/Product.php • So that, for autoloader works, your URL must be: http://abc.com/admin/Product • So, you MUST change all URL structure of your website 
    • Solution…
    • CLASSMAP • Hook before autoloader include controller file, something like this: … 'controlleradminproduct' => 'Controller/Admin/Product.php' …
    • Thank you! CONTACT ME: tuanmaster2002@yahoo.com 0938 916 902 http://bloghoctap.com/