There are numerous development tools available that we can use to develop Joomla! extensions. Most of these tools are not specific to Joomla!-like code and image editors or version control systems. Many can be found on the Joomla! extension directory at http://extensions.joomla.org/extensions/tools/development-tools.
When choosing an editor for modifying PHP source files, we recognize that it is important to ensure that the editor supports UTF-8 character encoding. Integrated Development Environments (IDE) such as the open source Eclipse and the commercial Adobe Dreamweaver are two of the more popular.
Open source image editors such as Gimp and Inkscape along with commercial products such as Adobe Photoshop, Illustrator, and Fireworks are frequent choices for manipulating web graphics.
An invaluable resource for developers is the developers' forge: http://www.joomlacode.org. This official site is used to host open source Joomla! projects. It provides third-party open-source Joomla! developers with free access to useful project development tools. This list details some of the tools JoomlaCode.org provides us:
If we intend to create an open source Joomla! project, we should consider using JoomlaCode.org to host the project, even if we do not intend to use all of the features it provides.
While you may not consider coding standards a tool, using a standardized format makes code easier to read and allows other developers to edit code more easily. Joomla! uses the PEAR coding standards. A complete guide to the PEAR coding standards is available at http://pear.php.net/manual/en/standards.php.
Here is a breakdown of the more common rules:
Indents are four spaces: \
{ // four space before me!
Control structures have one space between the name and first parenthesis:
if (true) {
Curly braces should be used even when they are optional.
Functions and methods are named using the camelCase standard with a lowercase first character.
Functions and method declarations have no spaces between the name and first parenthesis. Parameter lists have no spaces at the ends. Parameters are separated by one space:
foo($bar0,
$bar1,
$bar2)
.Optional function and method parameters must be at the end of the parameter list. Optional parameter values, signified by an equals sign, are separated by spaces:
function
foo($bar0,
$bar1,
$bar2
=
'')
.Use
phpDocumentor
tags to comment code http://www.phpdoc.org/.Use
include_once()
andrequire_once()
in preference toinclude()
andrequire()
.Use
<?php
?>
in preference to all other PHP code block delimiters.
phpDocumentor
is a documentation tool that allows us to easily create documentation from PHP source code. The documentation is extracted from the source and from special comments within the source; these comments are very similar to those used by JavaDoc.
This example demonstrates how we might document a simple function:
/** * Adds two integers together * * @param int $value1 Base value * @param int $value2 Value to add * @return int Resultant value */ function addition($value1, $value2) { return ((int)$value1 + (int)$value2) }
The multiline comment denotes a DocBlock. Note that it uses a double asterisk at the start. The first line is a general description of the function; this description can span more than one line. @param
and @return
are tags.
The @param
tag is used to define a parameter in the format (the name is optional):
@param type [$name] description
The @return
tag is used to define the return value in the format:
@return type description
Our initial example is telling us that the addition()
function has two named integer parameters that it will add together. It will then return the resultant integer value.
When we document complex functions, we might want to provide two descriptions: a long description and a short description. This example demonstrates how we do this:
/** * Does some complex processing * * A verbose description of the function that spans more than * one line * * @param int $value1 Base value * @param int $value2 Value to add * @return int Resultant vaue */ function someComplexFunction($value1, $value2) { // does some complex processing }
Functions are not the only elements that can be documented. Elements that we can document include:
This list defines some common tags we are likely to encounter:
@access private|protected|public
@author name
@param type [$name] description
@return type description
@static
The DocBlocks are easy to read when they are displayed in code, but, more importantly, we can automatically create documentation from the source code. For more information about using phpDocumentor
, please refer to http://www.phpdoc.org/.
J!Dump allows us to output variables during development. The output is displayed in a configurable pop-up window and describes data types and object properties and methods.
J!Dump comes as two separate extensions: a component, which we use to configure the functionality of J!Dump, and a system plugin, which defines functions that we use to 'dump' data to the J!Dump pop-up. Both extensions are required in order for J!Dump to function correctly.
Note
In order for one to use J!Dump the plugin must be published. If it is not, when we attempt to use the J!Dump functions, we will encounter fatal errors.
The most important function in J!Dump is the dump()
function. We can pass a variable to this function, and it will be displayed in the pop-up. This example demonstrates how we use the dump()
function:
// create example object $object = new JObject(); $object->set('name', 'example'); // dump object to popup dump($object, 'Example Object');
Using this will create a pop up, which looks like this:
Other functions we can use include dumpMessage()
, dumpSysinfo()
, dumpTemplate()
, and dumpTrace()
.
Note
T o get a copy of J!Dump, refer to http://joomlacode.org/gf/project/jdump.