Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Code Documentation

Krinkle edited this page Apr 5, 2012 · 7 revisions

Classes

TestSwarm (as of 0.3) is in an object-oriented way and and context based. A short overview of the main classes follows.

BrowserInfo

Given a user agent string this class parses into an object and extracts information about the client. Such as browser name, version, engine and operating system. It also tries to find a matching entry from the useragents table.

Database

Although right now the only supported database backend is MySQL, the Database class abstracts most MySQL specific methods so that it is fairly easy to change this later on. It also offers various convenience methods (such as getOne, getRow and getRows), and uses proper context based calls to the underlying php functions (e.g. methods like mysql_error and mysql_insert_id are always called with the connection object in case multiple connections are active).

WebRequest

Abstraction for accessing request data ($_GET, $_POST, $_SESSIONand IP-address). Also provides several convenience methods such aswasPosted(), getBool, getInt, getArray and getVal( key, defaultValue ).

TestSwarmContext

The above and other classes are lazy loaded when they are needed. Both the class files themselves are lazy-loaded using the PHP Autoloader and the initialization of the classes is done on-the-fly when they are first needed and the instance is cached from there for re-use.

Action

The base class for all actions. Actions are the front-end independent logic. Pages and APIs use these to get the information in a structured format.

Page

Formats the skin for index.php requests and Page-extending classes implement page specific output, gathered from one or more instances of Action classes.

Globals

As of TestSwarm 0.3 TestSwarm practically uses zero globals. There are however 2 global variables used in some legacy functions that will be phased out later.

  • $swarmInstallDir (string) This is the absolute path of the directory where the TestSwarm install is located in the file system.

  • $swarmContext (TestSwarmContext) Primary instance of the TestSwarmContext class. Should be used as little as possible. In general only within an entry point file (index.php, api.php). In any other environment the current context should be used from within the enclosing class.

Settings

It's not required to define all settings in testswarm.ini. Only the ones you need to override have to be defined there. The others can be commented out or left out entirely. The application will populate them with the defaults automatically. The default sample INI (./config/config-sample.ini) contains more information about each setting. Refer to that file for documentation on the settings.

Clone this wiki locally