-
Notifications
You must be signed in to change notification settings - Fork 0
setup.sdk
To develop with the XP framework here's an overview of the essential utilities:
Runs XP classes with a main
method and is the base for all other
utilities.
Given the following class:
<?php
uses('util.cmd.Console');
class SayHello extends Object {
public static function main(array $args) {
Console::writeLine('Hello ', $args[0]);
}
}
?>
...the following run on a command line:
$ xp SayHello World
...will print "Hello World" to the console.
Runs util.cmd
, which greatly simplify the
task of writing command line utilities. Instead of having to parse arguments,
instantiate database connections and load configuration files manually,
command line classes can ask for these resources by annotating methods.
The following is the (functional) equivalent of the above:
<?php
uses('util.cmd.Command');
class SayHello extends Command {
protected $name;
#[@arg(position= 0)]
public function setName($name) {
$this->name= $name;
}
public function run() {
$this->out->writeLine('Hello ', $this->name);
}
}
?>
To print "Hello World" to the console:
$ xpcli SayHello World
This method may look like additional overhead in the beginning (and actually is in this case) but has numerous benefits - [http://news.xp-framework.net/article/205/2007/07/22/](this entry) from our blog explains "xpclis" in depth.
Runs unittest
.
Works with [core.xars](XAR archives).