Repository navigation
POS Hello World Recipe
The canonical introduction to any new system! In this particular implementation we're going to create a command that causes POS to say "Hello World".
To handle input, we need a Parser class. These are discovered and inserted into input parsing automatically based on class hierarchy.
class HelloWorldParser extends Parser
{
}A Parser needs to define two methods: check() examines the input value to see if it is our Parser's command; parse() performs whatever actions are associated with our command. For the example, the command will be "Hello". This requires a check() method like this:
public function check($str)
{
if ($str == 'HELLO') {
return true;
} else {
return false;
}
}Note that check() should return a boolean and also that inputs are automatically capitalized before parsing.
The parse() method performs an action. In this case we're simply going to show a dialog box. The parse method would look like this:
public function parse($str)
{
$json = $this->default_json();
$json['output'] = DisplayLib::boxMsg('Hello World');
return $json;
}The parse() method needs to return a properly structured array. Using default_json() will initialize such an array and is the recommended way of starting. The "output" key of the array contains the HTML we're going to display. The DisplayLib::boxMsg() method takes the input string and wraps it in the appropriate HTML for a standard-looking dialog box.
Full example: HelloWorldParser.php
class HelloWorldParser extends Parser
{
public function check($str)
{
if ($str == 'HELLO') {
return true;
} else {
return false;
}
}
public function parse($str)
{
$json = $this->default_json();
$json['output'] = DisplayLib::boxMsg('Hello World');
return $json;
}
}