Subentry of
KateOS
Sun20May2007
- Contents
This document covers the standards set forth in KateOS for building stable and portable applications in PHP using the PHP-GTK extension. It will briefly explain the configuration of PHP required, the installation implementation, and file system standards required to make development consistent between developers and distributions.
Assumptions:
• PHP-GTK is in reference to PHP-GTK2 at all times in this document, unless otherwise stated.
• PHP is in reference to PHP5, preferably the most recent stable release.
All questions or suggestions pertaining to these documents (and any related) should be directed to Bob Majdak Jr <bob at kateos dot org>
• GTK2 must first be installed and working with it's dependencies (GLib, ATK, Pango, Cairo). All the development headers should also be installed. If the libraries were compiled and installed from source then the required file should already exist. If they were installed from a binary package check that the dev packages are also installed. In KateOS all the required files exist inside the main binary packages, and are installed on the system by default.
• PHP must be compiled and installed with the Command Line Interface enabled as a minimum, with a prefix of /usr or a symlink created in /usr/bin to the PHP interpreter binary. Good modules to have for PHP include ZLIB, BZ2, PNG, JPEG, GD, MySQL, Sockets, FTP, Freetype, Gettext and XML. If the same installation of PHP is to work with a web server such as Apache then it should be compiled with the configuration directory to be somewhere obvious that the configuration is for web server environments. On KateOS, the default configuration file is located at /etc/apache2/php.ini.
• A separate PHP configuration file for the use with PHP-GTK. This should be located in /etc/gtk/php.ini. It should be configured to disable features that are not important for local system applications (meaning anything web related). PHP applications will not use this configuration file on their own accord. (see PHP-GTK Development - Default GTK PHP.INI)
File System Implementation
All basic Linux file system standards should be followed. However there are special cases which must be taken into consideration for application development like this to play nice with the system.
Since there is no true thing as a binary in the case of PHP applications, we define the application 'binary' as the primary script that launches the main application. Typically this is named as the command the user is expected to execute to launch the application. For example to launch the [[KateLAN]] the user is expected to execute the command `katelan` on a terminal or with an application launcher in their window manager. These 'binaries' are placed in a PATH location such as /usr/bin so they may be called without knowing the full path. To further increase the 'user friendly' factor the .php extension is dropped from binaries placed in PATH locations.
A library is defined as a file which contains no main-level executable code, meaning they only define functions and or classes. If these are structured correctly they may be reused by other developers. To make library locations consistent they should be placed in the /usr/lib/php directory under a subdirectory with the library name. Pure PHP libraries may ''not'' be placed in /usr/lib because the GNU Linker will throw errors about non-self files when performing tasks such as updating the ld cache. All function libraries should have the file extension .so.php to designate them as libraries.
All configuration files which are manually parsed by the application should end up in the /etc directory, preferably in a subdirectory for the application they belong with. These type of configuration files should have the .conf file extension. Configuration files which contain executable PHP code for the purpose of drop in include() or require() configuration should be designated as having executable code by having the .conf.php file extension. These also should be placed in /etc under a subdirectory for the application they belong with.
Developing a PHP-GTK Application
To run a PHP-GTK application, the program itself must know two things: the interpreter and the configuration file to use. This is easily set in the hashbang of the script.
#!/usr/bin/php -c/etc/gtk/php.ini
<?php
require('libexample/example.so.php');
// ... application code...
?>
#!/usr/bin/php -c/etc/gtk/php.ini
<?php
class bobWindow extends GtkWindow {
public function __construct() {
parent::__construct();
$this->vbox = new GtkVBox;
$this->label = new GtkLabel("KateOS <3 PHP-GTK2.");
$this->set_title("Bob's Demo");
$this->set_border_width(16);
$this->set_position(Gtk::WIN_POS_CENTER);
$this->connect_simple('delete-event',array($this,'quit'));
$this->vbox->pack_start($this->label,true,true,3);
$this->add($this->vbox);
$this->show_all();
}
public function quit() {
$this->hide();
Gtk::main_quit();
}
}
$w = new bobWindow;
Gtk::main();
$w = null;
?>