-
Notifications
You must be signed in to change notification settings - Fork 11
CAP Processor API
The Cap Processor Class is located in the “lib” folder of the CAP PHP Library and is named: cap.class.php
To implement the Cap Processor class you have to require it:
require_once 'PATH_TO_LIB/cap.class.php';
After this initialize the class:
$cap = new CapProcessor();
Now you can use the Cap Processor Class with the instance $cap.
The CAP Processor class is separated in alert, info, resource, area parts
To make a Test CAP simply use this short code:
NOTE: use the parameter false to not stop the execution of the program
$cap = new CapProcessor();
$cap->makeTestCAP(false);
Now you can edit and test it with the CapProcessor
To change the CAP content of a specific tag you can use this short code:
// in OOP
$cap = new CapProcessor();
$cap->makeTestCAP(false);
$alert = $cap->getAlert(0);
$info = $alert->getInfo(0);
$area = $info->getArea(0);
$area->setAreaDesc('Changed Area DESC');
// or in PP
$cap->alert[0]->info[0]->area[0]->setAreaDesc('Changed Area DESC'); // change event Procedural
To read a CAP xml file, array or string you can use this short code:
With a file:
$cap = new CapProcessor();
$cap->readCap("CAP_PATH/CAP_NAME");
// make changes
$alert = $cap->getAlert(0);
$info = $alert->getInfo(0);
$area = $info->getArea(0);
$area->setAreaDesc('Changed Area DESC');
Without a file:
$cap = new CapProcessor();
$cap->readCap("PUT_HERE_CAP_XML_CONTEND");
// make changes
$alert = $cap->getAlert(0);
$info = $alert->getInfo(0);
$area = $info->getArea(0);
$area->setAreaDesc('Changed Area DESC');
To build or save a CAP you can use this short code:
$cap = new CapProcessor();
$cap->makeTestCAP(false); // debug = false
$cap->buildCap(); // returns a XML string
$cap->saveCap('CAP_NAME'); // returns the destination of the new cap file
Implement the CapProcessor class
require_once 'cap.class.php';
Make a instanz of the class
$cap = new CapProcessor();
The Constructor of the class:
output: the destination where files should be written (default: output)
cap_mime: the mime type of the cap (default: xml)
$cap = new CapProcessor($output = "output", $cap_mime = "xml")
returns the cap alertBlock class at the given index
$cap->getAlert();
create a new alertBlock instanz at the given index
this will create a new alert block part of the cap
$cap->setAlert();
redirect of setAlert()
$cap->addAlert();
returns a Cap alert in xml format from the given index
$cap->buildCap();
===saveCap($name = ,$index = false)===
This method will save the result of the buildCap() to a file
$name: if empty the identifier of the alertBlock will be used as name $index: declares the use of with alertBlock to use (default: 0)
$cap->saveCap();
Read a Cap into the Class
$destination: the path of the file to read or direct xml string input
$cap->readCap('PATH_OF_FILE');
$cap->readCap('XML_STRING');
Creates a complete test CAP
$debug: if true execution will stop after creating the test CAP and print it.
$cap->makeTestCAP();
if $cap->debug is true this method will stop the execution and prints the given value
$debug_val: the value to print
$cap->debug('ARRAY_OR_STRING');
The parameterBlock Class initializes the eventCode, parameter and geocode part of a CAP
$valueName; $value;
$param_val = new parameterBlock($valn, $val);
The CapCreate class uses the CapProcessor and the XmlProcessor class to build a xml CAP and save a xml CAP
$cap = new CapProcessor();
$cap->buildCap();
$cap->saveCap('CAP_NAME');
The CapCreate class uses the CapProcessor class to read a xml CAP and initialzie the complete CAP it in the CapProcessor class
$cap = new CapProcessor();
$cap->readCap("CAP_PATH/CAP_NAME");
The XmlProcessor is used by the CapCreate class and builds the CAP contend in a xml format
$alert = $this->processor->getAlert($index);
$xml = new XmlProcessor(/*ver*/'1.0',/*encoding*/'utf-8',array('standalone'=>'yes'));
$xml->tag_open('alert',array('xmlns' => 'urn:oasis:names:tc:emergency:cap:1.2'));
$xml->tag_close('alert');
$output_content = $xml->output();
Special ... with additional meteoalarm.eu webservice functions (www.meteoalarm.eu)