Understanding PSR — Part 1 What Does PSR means?

I keep seeing young developers these days completely depended on Frameworks, while it provides a way to finish our work faster but you won’t learn until get inside their core. when it comes to basic of understanding, it starts with how files are loaded and how various internal libraries are linked to each and easily retrieved with just using a Namespace Keyword. There it comes in Understanding PHP PSR first.

Understanding PHP PSR Means?

PSR or PHP Standards Recommendations (or sometimes called Proposed Standards Recommendation), is an attempt to standardise the way people use PHP. As the growth of frameworks has been increasing dramatically, there comes the need for “Interoperability” between these framework. So one can you other packages/plugins/modules are whatever without any trouble.

Just think about it, if each frameworks are written in different styles (like coding styles, use of including file set, linting, logging, etc) it be a hell for other developers to understand and how to use it. There comes the need for developers (Since PHP is Open Source) to come point to finding a neat way, i.e rules or proposed “standard” of how to write PHP.

I remember my time when started out programming in PHP like 7 years back, there always comes a need to use third party vendor packages, what i did was download from the web, extract and put it somewhere and use ‘require’ to load. I had no idea about standards or proper convention of how to use a component and also I put up ‘require’ in all my classes and create instance in same manner, now i look into it, it’s so stupid. Its like 5 or 10 vendor components are download and extract and placed in everywhere. When sharing with collaborators, I just blindly commit these extracted packages in my repo. Even if i dynamically include these packages, each plugin requires different ways to load in runtimes. Its like Hell, until i found it there is something called PSR and Composer.

How it Started?

  • Started as “PHP Standards Group” after a initial conference in 2009 (according to http://code.tutsplus.com/tutorials/psr-huh–net-29314)
  • Later changed to “Framework Interoperability Group” or simply FIG, as former wasn’t clear about the intention of creating such a group.

How FIG Work?

  • The whole thing is based on Voting by PSR Workflow ByLaw (http://www.php-fig.org/bylaws/psr-workflow/)
  • Proposal are made in FIG and voted for acceptance
  • Status change over from Accepted, Review, Draft and deprecated
    • Unless a PSR is marked as “Accepted” it is subject to change.
    • Also we should not use Draft which can change drastically,
    • Review will only have minor changes.
  • The above FIG has group people voters from varity of projects/frameworks Like Symfony, CakePHP and also from phpDocumentor, Composer (ofcourse!) http://www.php-fig.org/members/
  • Now hopefully we’ve understand what does PSR means. Now, lets see what are PSR accepted/approved standards. Each PSR are represented by PSR-N, where N is PSR version number.

PSR Approved/Accepted Standards:

  1. Basic Coding Standard – PSR-1
  2. Coding Style Guide – PSR-2
  3. Logger Interface – PSR-3
  4. Autoloading Standard – PSR-4
  5. Caching Interface – PSR-6
  6. HTTP Message Interface – PSR-7

In our next blog we’ll see about how to use “PSR-4” Autoloading standard and “PSR-1, PSR-2” Coding standards.

CakePHP — Fixing Mod Rewrite Issue in Ubuntu

Here we are going to take about how to fix ” Fixing Mod Rewrite Issue” in CakePHP. I’m sure if you have(tried) installed CakePHP in Ubuntu, you definitely would have seen this message.

” URL rewriting is not properly configured on your server.”

And the darn page opens without any css and no URL rewriting (ofcourse, duh!)

Just follow the below checklist, I’m sure you might have missed any one of’em(like i did now ^^”)

Following are the Checklist for Fixing Mod Rewrite Issue

1. Verify all three .htaccess. (yep, three!)

~/projects/cakephp/.htaccess

~/projects/cakephp/app/.htaccess

~/projects/cakephp/app/webroot/.htaccess

(Important: If you have tried unzip the content of CakePHP source, somehow, .htaccess in ~/projects/cakephp/ got left out… damn!!!)

2. Enable mod rewrite ofcourse! (just double check it :P)

3. Proper permission for /tmp and /webroot

4. Enable “AllowOverride” in Apache

5. Check for `cake.generic.css’ (Seriously, crazy fix!!!)

CakePHP guys showing the URL rewriting issue if the css is not present. sheessh!!! (pss: I’m using CakePHP 1.3, my favorite!!!)

Well,  Thats it for Fixing Mod Rewrite Issue!!!! I’m sure one em will help you fellas or else you will ended up spending hours scratching your head!! xD