HPCloud-PHP
1.2.0
PHP bindings for HPCloud and OpenStack services.
|
This guide explain coding style, coding structure, and documentation style.
The code in this package rigidly conforms to a given coding standard. The standard we use is published here and is based on the Drupal coding standards, the PEAR coding standards, and several other popular standards.
Important highlights:
Please do your best to follow coding standards when submitting patches.
We have chosen to give the library a strongly object-oriented flavor. However, the stream wrapper integration provides a procudural interface to some of the services.
Where applicable, we use established coding patterns and practices. Some are PHP specific (like stream wrappers), while most enjoy broader industry support.
There are a few things a developer should be aware of:
Accessors and Mutators: The naming convention for methods on an object are as follows:
Pillow
object may be accessed using Pillow::color()
.Pillow::changeColor()
, Pillow::setColor()
, and Pillow::fight()
may all be appropriate mutator names.Constructor Functions: PHP does not support method overloading (that is, declaring multiple methods with the same name, but different signatures). While some languages (viz. Java, C++, C#) allow more than one constructor, PHP limits you to just one constructor.
One strategy for working around this is to create constructors that take vague or generic parameters, and then perform various inspection tasks to figure out what the parameters are:
The above quickly degenerates into code that is both slow (because of the inspection tasks) and difficult to read and use.
Another option, following Objective-C and Vala, is to create constructor functions. These are static functions (in PHP, at least) that can build instances. Constructor functions have signatures like Pillow::newFromJSON()
and Pillow::newFromXML()
.
This library uses constructor functions. Generally, a very basic constructor is provided for cases where it is needed, but more complex cases are handled with specialized constructor functions.
Namespaces: The library has been divided up into namespaces according to the following principles:
Otherwise, we have attempted to keep the namespace relatively shallow.
Any network-based library must struggle with the inefficiencies of working over a network. This library is no exception. We've done our best to straddle the line between keeping load times down and making the code simple and elegant. Doubtless we have sometimes failed. Please feel free to suggest improvements on either side of the scales.
This project is documented with Doxygen, and the configuration file used is available in ./config.doxy in this project.
The following conventions are used:
Since Doxygen 1.8.0, Doxygen boasts native support for Markdown. Where possible, we write documentation in Markdown, which makes it both readable in the source code form, and also a fully integrated part of the API documentation.