Skip to content
Niklas Spanring edited this page Oct 17, 2016 · 10 revisions

Table of Contents

CAP Processor API Documentation

Info

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.

CAP Blocks

The CAP Processor class is separated in alert, info, resource, area parts

alertBlock

CAP_Processor_area

infoBlock

CAP_Processor_info

resourceBlock

CAP_Processor_resource

areaBlock

CAP_Processor_area

Make a Test CAP

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

Edit a CAP

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

Read a CAP

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');

Build and save a CAP

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

The CapProcessor class

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")

getAlert($index = 0)

returns the cap alertBlock class at the given index

  $cap->getAlert();

setAlert($index = false)

create a new alertBlock instanz at the given index

this will create a new alert block part of the cap

  $cap->setAlert();

addAlert($index = false)

redirect of setAlert()

  $cap->addAlert();

buildCap($index = false)

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();

readCap($destination)

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');

makeTestCAP($debug = true)

Creates a complete test CAP

$debug: if true execution will stop after creating the test CAP and print it.

  $cap->makeTestCAP();

debug($debug_val)

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');

parameterBlock

The parameterBlock Class initializes the eventCode, parameter and geocode part of a CAP

  $valueName;
  $value;
  $param_val = new parameterBlock($valn, $val);

CapCreate

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');

CapRead

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");

XmlProcessor

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(); 
Clone this wiki locally