Posted on February 14th, 2007 by headwedge
WARNIING Blogging in the bar, cocktails fuelled musings: Not being able to get a ref to the filter object is a bit of a pain when it comes to initialising it. Which, in turn, limits abstracting and generalising the class. However, the filter registration function at least allows one to pass a parameter which becomes [...]
Filed under: code, colouriser, php, pie in the sky | No Comments »
Posted on February 7th, 2007 by headwedge
Here is a quick try at a filter to add font tags around the opening and closing PHP script tags.
The colouring and layout filters are both appended to the stream and then used on the test harness and the source script to produce the following output:
Filed under: code, colouriser, php | No Comments »
Posted on February 4th, 2007 by headwedge
Having played with adding tags to colour the code it became clear that a FSM to reproduce the layout was the first problem to tackle. Separating this functionality out into its own filter improved flexibility.
Coding a FSM to replace < and > with < and > character codes is trivial. Similarly inserting a〈BR〉 tag for [...]
Filed under: code, colouriser, php | No Comments »
Posted on January 29th, 2007 by headwedge
My preferred design approach for the ‘code-colouriser’ would be for it to filter a PHP script through a suitably trained finite state machine (FSM). After a bit of rummaging in the online PHP manual I was pleased to find that PHP 5 has a rich, if poorly documented, set of stream functions [link] and, [...]
Filed under: code, colouriser, php | No Comments »
Posted on January 10th, 2007 by headwedge
Previous musings on the random image class [link] seemed to result in a toss-up between enforcing structure in the image names or structuring the image names in code, but…
The glob() function seems to allow the best of both of these worlds. Given a path and a file name pattern to match it returns an array [...]
Filed under: code, php | No Comments »
Posted on January 4th, 2007 by headwedge
A Finite State Machine [link] is a way of making a decision or modeling behaviour. Although it is a core concept in computer science and in particular the theory of computing, it is probably more widely known from its use in the Quake games [link]. Conceptually it is a bit like a flow chart and [...]
Filed under: code, php | No Comments »
Posted on January 3rd, 2007 by headwedge
Confining class code and associated files to its own directory is a convenient and flexible way of organising your code. Unfortunately maintaining a long list of include files is not.
However, PHP 5 offers the __autoload($class_name) function for you to redefine to automatically load class definition files based upon your path structure [link].
Future test harness examples [...]
Filed under: code, php | No Comments »
Posted on October 14th, 2006 by headwedge
Wrap mhash incantations in an exception protected, lean interface to facilitate modular class composition.
Example:
<?php
require_once “includes/header.inc.php”;
try { $input = “Lorem ipsum dolor sit amet!”; $hash = mhash(MHASH_SHA256, $input); echo “The hash is ” . bin2hex($hash) . “<br />\n”; $hash = mhash(MHASH_SHA256, $input, “owner_id”); echo “The hmac is ” . bin2hex($hash) . “<br />\n”; $h = new Hash(); echo $h; echo “The hash is ” [...]
Filed under: code, php | No Comments »
Posted on October 10th, 2006 by headwedge
Wrap mcyrpt incantations in an exception protected, lean interface to facilitate modular class composition.
Example:
<?php
require_once “includes/header.inc.php”;
try { $c = new Cipher(‘passphrase’); echo $c; $s = $c->encrypt(‘Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis [...]
Filed under: code, php | No Comments »