Daily Archives: August 21, 2012

Zend Framework Coding Standard

This topic provides guidelines for code formatting and documentation to individuals and teams. Especially in team project coding standing plays a vital role. Because once we follow the coding standard, it will be consistent and easy to understand by other developers. And it make the code with high quality.

PHP File Formatting:

General:

For files that contain only php code, closing tag ( ?> ) is not required by php, while omitting, it prevents the accidental injection of trailing white space into the response.

Indendation:

Indendation should consists only 4 spaces. Tabs are not allowed.

Line Length:

Minimum line length target by zend framework is 80 whereas maximum is 120.

Naming Conventions:

Classes:

  1. The names of the classes directly map to the directories in which they are stored.
  2.  Class names may only contain alphanumeric characters.Numbers are permitted in class names but are discouraged in most cases.
  3. Underscores are only permitted in place of the path separator; the filename “Zend/Db/Table.php” must map to the class name “Zend_Db_Table”.
  4. If a class name is comprised of more than one word, the first letter of each new word must be capitalized. Successive capitalized letters are not allowed, e.g. a class “Zend_PDF” is not allowed while “Zend_Pdf” is acceptable.

Abstract Classes:

  1. In general, abstract classes follow the same conventions as classes, with one additional rule: abstract class names must end in the term, “Abstract”, and that term must not be preceded by an underscore.
  2. As an example,

Invalid Name:  Zend_Controller_Plugin_Abstract

Valid Name:      Zend_Controller_PluginAbstract  (or)

Zend_Controller_Plugin_PluginAbstract.

Interfaces:

  1. In general, interfaces follow the same conventions as classes, with one additional rule: interface names may optionally end in the term, “Interface”, but that term must not be preceded by an underscore.
  2. As an example,

InValid Name:    Zend_Controller_Plugin_Interface

Valid Name:         Zend_Controller_PluginInterface  (or)

Zend_Controller_Plugin_PluginInterface.

File Names:

  1. Only alphanumeric characters, underscores, and the dash character (“-“) are permitted.
  2. Spaces are strictly prohibited.
  3. Any file that contains PHP code should end with the extension “.php“. Eg: db.php

Functions and Methods:

  1. Function names may only contain alphanumeric characters.
  2. Underscores are not permitted.
  3. Numbers are permitted in function names but are discouraged in most cases.
  4. Function names must always start with a lowercase letter. When a function name consists of more than one word, the first letter of each new word must be capitalized. This is commonly called “camelCase” formatting.
  5. Verbosity is generally encouraged. Function names should be as verbose as is practical to fully describe their purpose and behavior.

Variables:

  1. Variable names may only contain alphanumeric characters.
  2. Underscores are not permitted.
  3. Numbers are permitted in variable names but are discouraged in most cases.
  4. For instance variables that are declared with the “private” or “protected” modifier, the first character of the variable name must be a single underscore. This is the only acceptable application of an underscore in a variable name. Member variables declared “public” should never start with an underscore.
  5. Verbosity is generally encouraged.
  6. If a loop contains more than 20 lines of code, the index variables should have more descriptive names.

Constants:

  1. Constants may contain both alphanumeric characters and underscores.
  2. Numbers are permitted in constant names.
  3. All letters used in a constant name must be capitalized, while all words in a constant name must be separated by underscore characters.
  4. For example, EMBED_SUPPRESS_EMBED_EXCEPTION is permitted but EMBED_SUPPRESSEMBEDEXCEPTION is not.
  5. Constants must be defined as class members with the “const” modifier. Defining constants in the global scope with the “define” function is permitted but strongly discouraged.

 

Leave a comment

Filed under zend

About PHPJasperXML

 We initialize this project (Actually it is a class) because of we want to develop web report in php easily (The output of report is PDF/XLS because it platform indepent and printer friendly). This project allow php programmer or report designer design php web report easily. Even very junior PHP programmer able to design the PDF/EXCEL report with iReport (java based WYSIWYG report designer), but run natively in PHP. This project is completely difference from php-java bridge, a wrapper class will convered report element from jrxml and pass to tcpdf class.

 

Advantages:

  1. Develop PDF report with iReport, which is fast, flexible and effective
  2. Run natively in PHP, no integration with Java
  3. Integrate to your existing project easily
  4. You can submit whatever parameter into your PDF/EXCEL report easily, either with GET or POST
  5. Open sourced, you can change the library yourself.

Currently this project is consider stable but there are a lot of function in jasper report is not ready yet because compatibility issue between JAVA and PHP. However, you’ll found that it already can create a lot of reports easily.

Sample View : http://www.simit.com.my/download/samplePHPJasperXML.pdf

Why we want to create report in PDF/EXCEL

  1. Web based programming need a standard layout out report, which is fixed and printer friendly. Using traditional HTML method is really hard to design multipage, beautiful and cross platform report.
  2. PDF is industry standard, the font, layout, margin is fixed. No matter at server side, client side and printer it display same result.
  3. PDF working well in all platform
  4. PDF support hyperlink, image, encryption and etc function.
  5. PDF is well known in market, most of the software already pre-install PDF viewer.
  6. PDF support multi-language.

Installation

  1. Download and extract this project into you website root directory (I assume /var/www/PHPJasperXML)
  2. Import sampledb.sql into mysql database, in this project we assume your username=root, password=mysql, database = phpjasperxml. If you use difference user/password/database, you shall change setting in sample1.php and sample2.php.
  3. With your favorite web browser, browse into http://localhost/PHPJasperXML/index.php, test report you like.
  4. Finish.

How to Use This Class

  1. You can use iReport to edit the sample1.jrxml, sample jrxml and see the effect from web browser.
  2. You can use any text editor to edit sample1.php and sample2.php, you will found that integrate the report into your project is like peanut.

Join Development

Currently there is no any external programmer join into this project yet. If you feel interested into this project and willing to give your hand, simply create a topic in this forum: http://www.extraknowledge.org/forum/. Please take note this project use TCPDF heavily.

How To Edit The Report

  1. Download iReport
  2. Use iReport to open sample1.jrxml, sample2.jrxml, sample3.jrxml.
  3. Perform changes and preview the report in iReport.
  4. Preview the report at http://localhost/PHPJasperXML/sample<N>.php

 

1 Comment

Filed under php