Dynamic Getter/Setters for PHP
November 23rd, 2007
We use the magic __call method in PHP which is called on an object when a declared function is called on it but it does not exist. This behaviour allows us to have default getters/setters but if we want specific behaviour for a get/set we just have to add the function to the class and __call will no longer be used for that class attribute.
class GetSetExample{/*** Dynamic getters and setters than maintain getX and setX formati. They can be overwritten* if custom processing is needed** @param string $method* @param array $arguments* @return mixed*/function __call($method, $arguments) {#Is this a get or a set$prefix = strtolower(substr($method, 0, 3));#What is the get/set class attribute$property = substr($method, 3);if (empty($prefix) || empty($property)) { #Did not match a get/set callthrow New Exception("Calling a non get/set method that does not exist: $method");}#Check if the get/set paramter exists within this class as an attribute$match=false;foreach($this as $class_var=>$class_var_value){if(strtolower($class_var) == strtolower($property)){$property=$class_var;$match=true;}}#Get attributeif ($match && $prefix == "get" && (isset($this->$property) || is_null($this->$property)) {return $this->$property;}#Setif ($match && $prefix == "set") {$this->$property = $arguments[0];}elseif (!$match && $prefix == "set"){throw new Exception("Setting a variable that does not exist: var:$property value: $arguments[0]");}else{throw new Exception("Calling a get/set method that does not exist: $property");}}}
Intelligent workflow management System
November 22nd, 2007
Download PDF Thesis http://www.doc.ic.ac.uk/teaching/projects/Distinguished04/JosephWilk.pdf
This project took the HTML form systems as a model and built a Workflow Management System that uses artificial intelligence planning methodologies and Event Calculus workflow specifications to try to overcome some of the problems of Workflow Management Systems. Logic, server side languages and planning all rolled into one.

The development of the Workflow Management System with AI uncovered interesting issues in modelling situations in the Event Calculus and the
problems that need to be overcome to use AI with workflow. The problems and
solutions developed in the project cover a wide spectrum of domains, looking at logic
programming, server-side languages and getting the two to talk to each other. Areas
covered include such interesting topics as typing of HTML to new frameworks for
Prolog running as CGI.
Achievements
- Workflow specification language
Using the Event Calculus and extensions to specify workflow. - [HTML form typing | HTML typing in Prolog]
A typing engine for ensuring that the HTML form element specifications are
correct when used in workflow specifications. - A Visualisation tool for Event Calculus plans
A tool that generates Scalable Vector Graphic graphs for Event Calculus
plans. - A HTML/PHP iWFMS engine
Using the plans generated from the workflow specifications to support the
running and management of a system. - A JavaScript plan execution engine
Facilitates the following of workflow plans in a scripting language that runs
while the user is viewing and interacting with a web page. - Logic programming running as Common Gateway Interface (CGI)
A framework for the use of high-level declarative programming languages
functioning as CGI. - [Logic programming and server-side language interaction model | Interaction support between PHP and Prolog]
An Interaction model allowing server-side languages used for generating web
pages to interact with logic programming languages. - A Hospital model working example
An example of how the specification can be utilised for a real world scenario in
a hospital. Providing the full functionality within the iWFMS to run and manage
this system.
Curl and Certificates with Windows PHP
November 6th, 2007
Curl on a Windows PHP installation does not know where to look for certificates. Hence when you try and curl a https url it fails. The default value for CURLOPT_SSL_VERIFYPEER is true which means curl will always try and validate ssl by default. I discovered this while working with an OpenID library (v1.2.3):
http://openidenabled.com/php-openid/
There is the option of disabling the verfication.
$ch=curl_init;
// set URL and other appropriate options
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
But thats ignoring the problem and opening a security hole! Instead download a reputable Certificate bundle file, for example:
http://curl.haxx.se/docs/caextract.html
Then set CURLOPT_CAINFO with the location of your certificate bundle.
if( strtoupper (substr(PHP_OS, 0,3)) == 'WIN' ) {
curl_setopt($c, CURLOPT_CAINFO, 'C:/certificates/cacert.pem');
}

