Simplify PHP Development with WASP
WASP (Web Application Structure for PHP) is a three-tier framework built on PHP 5. Lately, more software engineers are moving from cumbersome "enterprise" languages such as Java and C# to languages such as Python and Ruby and PHP. With version 5, PHP has finally reached the point where these developers can feel at home in what used to be considered a hacker's language. By demonstrating that it is possible to create and use complicated, "enterprise-class" frameworks effectively in PHP 5, WASP will help more developers make the switch.
WASP's initial basis is in the ideas mentioned in the article "Three-Tier Development with PHP 5." Since then, it has come a long way toward bridging the gap between PHP frameworks and other, traditionally more accepted three-tier tools. PangoMedia has put it to large-scale use in several production applications.
This article demonstrates how to build a small database-driven application: a simple task-list web application. This example is short; however, it demonstrates most of the powerful features that WASP has to offer.
The code in this article uses WASP 1.1. Some familiarity with PHP 5 syntax is helpful, but not necessary. For more information on the methods and classes used in this tutorial, see the WASP API documentation. For additional reference, the following resources may be helpful:
- PHP Manual
- "Classes and Objects in PHP 5"
- Phing reference
Installation and Configuration
Create a WASP project by running the command:
phing -buildfile PEAR_DIR/lib/php/data/WASP/build.xml wasp-project
PEAR_DIR is the installed location of your PEAR classes. You can find out where this directory is by running:
$ pear config-get php_dir
If all is well, you will see:
Buildfile: /usr/local/php5/lib/php/data/WASP/build.xml WASP > wasp-project: Directory to create project in >
Enter the fully qualified path where your new WASP project will be created. This will create the directory and copy over the build.xml and build.properties files.
For the purposes of this example, I've used /Users/brianfioca/Development/projects/Todo.
Make sure the directory you choose is accessible from within your web server's root.
You should now have a directory called Todo that looks like this:
|_Todo |_build.xml |_build.properties
WASP uses Phing and the build.properties file to manage its configuration. When you create your application, the Phing tool reads your build.properties and builds the correct configuration files for your project.
Here is a build.properties file that has default values for this tutorial.
################### # FILE: build.properties # DESC: wasp project configuration properties file # # The properties below are used to configure your wasp application. # Set these properties to customize your wasp install. # # run phing config to regenerate the configuration when these are changed. ## # The name of the application app.name= Todo # Toggle Debug output debug.flag= True # Toggle for email of error messages email.flag= False session.flag= True # URL of the database for this application database.url= mysql://user:pass@localhost/todo # Directory where pear packages are installed pear.dir= /usr/local/php5/lib/php
In the configuration, the
app.name property is
Todo, which will be the name of the application as well as the name of the root directory (located off of the
app.dir directory or the wasp directory, if not specified) of all modules, chunks, and templates that the build tool will create.
app.dir property is the directory where the application will reside within your web root. For this example, I've set the
app.dir to /var/www. This is the directory that the Apache HTTP server considers its root directory. Change this directory to match your particular web server configuration. When the application is installed, it'll reside in /var/www/Todo.
pear.dir property to the location of your PEAR classes: the directory that contains DB/DataObject and HTML/Template/Flexy. As I mentioned before, you can also find the location of this directory by running:
$ pear config-get php_dir
database.url property to the URL of the database that your project will use. This example assumes you will be creating a database called
todo on the MySQL instance on the local host.
If at any point you wish to regenerate the configuration, run the command:
$ phing config