Symfony-2
From Officience
Revision as of 03:18, 12 May 2015 by Huu Binh Nguyen (talk | contribs) (Created page with "= Symfony Checklist = == Development Checklist == === Structure === * Add a single space after each comma delimiter; * Add a single space around binary operators (==, &&, ...)...")
Contents
Symfony Checklist
Development Checklist
Structure
- Add a single space after each comma delimiter;
- Add a single space around binary operators (==, &&, ...), with the exception of the concatenation (.) operator;
- Place unary operators (!, --, ...) adjacent to the affected variable;
- Add a comma after each array item in a multi-line array, even after the last one;
- Add a blank line before return statements, unless the return is alone inside a statement-group (like an if statement);
- Use braces to indicate control structure body regardless of the number of statements it contains;
- Define one class per file (This does not apply to private helper classes that are not intended to be instantiated from the outside and thus are not concerned by the PSR-0 standard;T )
- Declare class properties before methods;
- Declare public methods first, then protected ones and finally private ones. (The exceptions to this rule are the class constructor and the setUp and tearDown methods of PHPUnit tests, which should always be the first methods to increase readability;)
- Use parentheses when instantiating classes regardless of the number of arguments the constructor has;
- Exception message strings should be concatenated using sprintf.
Naming Conventions
- Use camelCase, not underscores, for variable, function and method names, arguments;
- Use underscores for option names and parameter names;
- Use namespaces for all classes;
- Prefix abstract classes with Abstract. (Please note some early Symfony classes do not follow this convention and have not been renamed for backward compatibility reasons. However all new abstract classes must follow this naming convention;)
- Suffix interfaces with Interface;
- Suffix traits with Trait;
- Suffix exceptions with Exception;
- Use alphanumeric characters and underscores for file names;
- For type-hinting in PHPDocs and casting, use bool (instead of boolean or Boolean), int (instead of integer), float (instead of double or real);
Service Naming Conventions
- A service name contains groups, separated by dots;
- The DI alias of the bundle is the first group (e.g. fos_user);
- Use lowercase letters for service and parameter names;
- A group name uses the underscore notation;
- Each service has a corresponding parameter containing the class name, following the SERVICE NAME.class convention.
Documentation
- Add PHPDoc blocks for all classes, methods, and functions;
- Omit the @return tag if the method does not return anything;
- The @package and @subpackage annotations are not used.
License
- Symfony is released under the MIT license, and the license block has to be present at the top of every PHP file, before the namespace.
Deployment Checklist
- Install a PHP Accelerator (APC)
- Ensure that your production server is using a customized secret key (File: app/config/parameters.yml)
- Check the production server is ready to run website (php app/check.php)
- Use custom favicon (web/favicon.ico)
- Config monolog "config_prod.yml" (Send errors to the website administrator by email (logs of "error" level); Record all authentications, as these are logs of "info" level, that are not logged by default.)
- Query Cache (The Query Cache aims at caching the transformation of a DQL query to its SQL counterpart. In production, your requests won't change a bit so why not caching them.)
- Metadata Cache (The Metadata Cache aims at caching the parsed metadata from a few different sources like YAML, XML, Annotations, etc.)
- Result Cache (The result of your queries can be cached in order not to query the database again and again. As this is a finer tuning, you can't parameter it application-wide.)
- Ensure that Doctrine is actually using your APC cache (Check in file: app/cache/prod/appProdProjectContainer.php. If you can't find \Doctrine\Common\Cache\ApcCache, then you are not using APC.)
- Optimize the Autoloader
- Protect your forms (you could customize the token on a form-by-form basis, which is even better. You can do that by defining an intention option in your forms)
- Customize error pages (app/Resources/TwigBundle/views/Exception/errorXXX.html.twig)