Your SlideShare is downloading. ×
0
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Php psr standard 2014 01-22
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Php psr standard 2014 01-22

3,671

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,671
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHP for Enterprise PSR Introduction
  • 2. 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
  • 3. AGENDA Why Standard? How case-sensitive server kills PSR-0? Question & Answer
  • 4. 1. Why Standard?
  • 5. PSR FAMILY (http://www.php-fig.org/) • • • • • PSR-0 PSR-1 PSR-2 PSR-3 PSR-4
  • 6. 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.
  • 7. 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.
  • 8. 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.
  • 9. 2. How Case-sensitive server kills PSR-0 ?
  • 10. 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)
  • 11. 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 { … }
  • 12. Where is Problem ?!
  • 13. 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 
  • 14. Solution…
  • 15. CLASSMAP • Hook before autoloader include controller file, something like this: … 'controlleradminproduct' => 'Controller/Admin/Product.php' …
  • 16. Thank you! CONTACT ME: tuanmaster2002@yahoo.com 0938 916 902 http://bloghoctap.com/

×