Setting up the framework

The XP framework is installed by a setup script bundled with each release. It will check the dependendencies, create the directories, write the configuration files and setup the runners.

Prerequisites

You need to download and install the PHP language to use the XP framework. PHP 5 >= 5.2.0 is required. The stock PHP comes with a decent number of extensions enabled and will suffice for the XP Framework's core functionality. To connect to different database servers or use the imaging APIs, you'll need the respective extensions enabled. See here for a complete list.

Un*x

You might encounter problems when using the Suhosin patch; it prevents xar:// URLs from being read in some version because it thinks they are remote.

Windows

On the Windows platform (regardless of whether you're using Cygwin or not) the .NET Framework with a minimum version of 2.0 is required. It can be obtained by using the Windows Update mechanism if not already installed!

Installation

The installer works on any platform that PHP works on - but things do differ just a little bit for Windows and Un*x platforms. We strongly suggest to use Cygwin on Windows, although it is not required, it does make things much easier (see Installing on Windows without Cygwin if you don't want to).

Typical installation

To install a framework release in your own home directory, open a shell window and type the following:

  $ mkdir ~/xp
  $ cd ~/xp
  $ wget http://releases.xp-framework.net/setup/5.7.7 -O - | php -- -d ~/bin

If the directory ~/bin is not in $PATH, you can add it by editing your ~/.profile and adding a line export PATH=${HOME}/bin:${PATH}.



Getting started

You're ready to use the XP framework now. Instead of using the PHP runtime directly, the XP framework comes with its own runners. For now, we'll focus on the most simple one, the command line utility called xp.

Basic usage

To run a class with a public static main() method, simply supply its classname as command line argument:

  $ xp {class.Name}

Any argument after the classname will be passed to the class' main method.

Hello World

Well, because a simple hello world is just too easy, and boring, we'll start with a slightly more complex example. Save the following sourcecode to a file called AgeInDays.class.php:

<?php
uses
('util.Date', 'util.DateUtil');

class AgeInDays extends Object {
public static function main(array $args) {
$span= DateUtil::timespanBetween(new Date($args[0]), Date::now());
Console::writeLine
('Hey, you are ', $span->getDays(), ' days old');
}
}
?>

Now run it:

  $ xp AgeInDays 1977-12-14
  Hey, you are 11363 days old



Where to go from here

To learn about the framework's core concept - class loading, archives, the type system, annotations, but also on how to work with databases, XML, files, and more have a look at the documentation overview.

Table of contents