Play! Documentation

play.php

The play/play.php file is the center of the Play Library. Its base classes exist to create and support Plugin objects.

Play

The Play class is the root class for most library classes. It defines a set of static variables and methods listed below.

Plugins

Plugins are discrete packages of PHP code generally meant to perform a small, focused set of tasks - hopefully, related to their name. Play Library plugins are typically stored in the plugin folder, each inside a subfolder matching its plugin name, in a file matching its plugin name with the extension ".php". Every plugin is defined as a class named "plugin_" plus the plugin name.

The bulk of Play Library functionality is provided by Plugin objects. Plugin documentation will be provided individually by plugin.

Currently, there is only one method defined by the Plugin class - the respond method.

Database Access

Database access is provided through the use of two classes: Datasource and Query. Datasource represents a connection to a database and Query represents the results of one SQL query.

Query objects are returned by passing an SQL statement to a Datasource object's query function.

In general, a datasource should be created by passing a datasource name to the static Play::Datasource method. If the named datasource does not already exist, it's created and stored so that it can be reused if called for again.

For the Play::Datasource method to work, the static variable Play::$OnDatasource must be set to a callback function that returns a Datasource based on the $dsn argument. To actually instantiate a new Datasource object, pass an array of connection parameters to the datasource plugin's "create" method.

An example implementation of the Play::$OnDatasource callback can be found above under the Play::Datasource() section.

The plugin_datasource class is defined in play.php, but there is still a datasource folder within the plugin folder where new implementations of the Datasource class can be stored. The database plugin looks for a "dbms" key in the create method's array argument and loads the file with a matching name from the plugin/datasources folder.

Currently, mysql.php is included there, and can be used to create MySQL database connections. The following section indicates how each of the abstract Datasource and Query class methods must respond when called, so it should be relatively easy to create your own Datasource (and Query) subclasses if necessary.

Implementing Datasource

Extend the Datasource class to provide access to a DBMS.

Extend the Query class to provide access to result data selected by calling the Datasource class query method.