The PHP interpreter can be used within Command, Subscriber and Function types to form the script to be run.
A helper is made available which can access attributes, commands and functions.
Usage | Notes |
---|---|
$ws['sample.key.name'] |
ArrayAccess interface for interacting with attributes |
$ws('command input here') |
__invoke for calling declared commands |
$ws->function('arg') |
__call for calling declared functions |
command('hello'): |
#!php
echo "Hello World";
>>> ws hello
Hello World
attribute('message'): Hello World
command('hello'): |
#!php
echo $ws['message'];
>>> ws hello
Hello World
function('greet', [name]): |
#!php
= "Hello {$name}.";
command('hello'): |
#!php
echo $ws->greet('Guest');
>>> ws hello
Hello Guest
When declaring a function if you wish to return a value use =
on the last line of the script followed by an expression.
command('hello'): |
#!php
echo "Hello World";
command('say hello'): |
#!php
$ws('hello');
>>> ws say hello
Hello World
command('get my cwd'): |
#!php(workspace:/sample/path/here)
echo getcwd();
>>> mkdir -p sample/path/here
>>> ws get my cwd
/path/to/workspace/sample/path/here
workspace:
, harness:
and cwd
: are the path prefixes available by default.