This is the XP Framework's development checkout
Clone this repository, e.g. using Git Read-Only:
$ cd /path/to/xp
$ git clone git://github.com/xp-framework/core.git
The entry point for software written in the XP Framework is not the PHP interpreter's CLI / web server API but either a command line runner or a specialized web entry point. These runners can be installed by using the following one-liner:
$ cd ~/bin
$ wget 'https://github.com/xp-framework/xp-runners/releases/download/v5.5.0/setup' -O - | php
To use the the XP Framework development checkout, put the following
in your ~/bin/xp.ini
file:
use=/path/to/xp/core
Finally, start xp -v
to see it working:
$ xp -v
XP 6.5.3-dev { PHP 5.6.12 & ZE 2.6.0 } @ Windows NT SLATE 10.0 build 10240 (Windows 10) i586
Copyright (c) 2001-2015 the XP group
FileSystemCL<...\xp\core\src\main\php\>
FileSystemCL<...\xp\core\src\test\php\>
FileSystemCL<...\xp\core\src\test\resources\>
FileSystemCL<...\home\Timm\devel\xp\core\>
The XP Framework runs classes with a public static main()
method. To run a class, supply the fully qualified classname as command line argument: $ xp {class.Name}
.
Any argument after the classname will be passed to the class' main method.
Save the following sourcecode to a file called AgeInDays.class.php :
<?php
use util\Date;
use util\DateUtil;
use util\cmd\Console;
class AgeInDays extends \lang\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 13724 days old
Alternatively, you can run this directly in the shell:
$ xp -w '
use util\{Date, DateUtil};
$span= DateUtil::timespanBetween(new Date($argv[1]), Date::now());
return "Hey, you are ".$span->getDays()." days old"
' 1977-12-14
Hey, you are 13724 days old
Enjoy!
To contribute, use the GitHub way - fork, hack, and submit a pull request!