Tag Archives: PHP

Dynamic Getter/Setters for PHP

23 Nov

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.

  1. class GetSetExample{
  2.  
  3. /**
  4. * Dynamic getters and setters than maintain getX and setX formati. They can be overwritten
  5. * if custom processing is needed
  6. *
  7. * @param string $method
  8. * @param array $arguments
  9. * @return mixed
  10. */
  11. function __call($method, $arguments) {
  12.  
  13. #Is this a get or a set
  14. $prefix = strtolower(substr($method, 0, 3));
  15.  
  16. #What is the get/set class attribute
  17. $property = substr($method, 3);
  18.  
  19. if (empty($prefix) || empty($property)) { #Did not match a get/set call
  20. throw New Exception("Calling a non get/set method that does not exist: $method");
  21. }
  22.  
  23. #Check if the get/set paramter exists within this class as an attribute
  24. $match=false;
  25. foreach($this as $class_var=>$class_var_value){
  26. if(strtolower($class_var) == strtolower($property)){
  27. $property=$class_var;
  28. $match=true;
  29. }
  30. }
  31.  
  32. #Get attribute
  33. if ($match && $prefix == "get" && (isset($this->$property) || is_null($this->$property)) {
  34. return $this->$property;
  35. }
  36.  
  37. #Set
  38. if ($match && $prefix == "set") {
  39. $this->$property = $arguments[0];
  40. }
  41. elseif (!$match && $prefix == "set"){
  42. throw new Exception("Setting a variable that does not exist: var:$property value: $arguments[0]");
  43. }
  44. else{
  45. throw new Exception("Calling a get/set method that does not exist: $property");
  46. }
  47. }
  48.  
  49. }

Intelligent workflow management System

22 Nov

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.

iWFMS admin interface

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

6 Nov

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