Peeker


Peeker Detector Set Class

This is the interface from the main Peeker Class to the Detectors.

The Peeker Detector system lets you pull and process email in a declarative programming style. This style can make logic clearer than a bunch of nested if statements. It also helps you modularize reuseable detector components. Declarative programming can help you split tasks among multiple programmers.

Note: The Peeker Detector system only works if you use the get_message() function or create a custom message class and tell Peeker to use that class: $this->peeker->set_message_class('peeker_header');

Detector array

This class holds an array of detectors.

Function Reference

make_detector($detector_method, $detector_method_arguments, $callback_method, $callback_method_arguments)

Create a detector circuit that "detects" an event and triggers a callback when the event is TRUE. Returns the detector object when created.

// in_from is a custom message class method
// that tests the from address with the strpos() function
$detector_method = 'in_from';
$detector_method_arguments = 'spammer@spamtown.us';

// set_delete is a method in the custom header class
$callback_method = 'set_delete';
$callback_method_arguments = TRUE;

$detector = $this->peeker->make_detector_set();
$detector->make_detector($detector_method, $detector_method_arguments, $callback_method, $callback_method_arguments);

Once you have a detector_set object you can add detectors. The detector set and its detectors must be created before calling the message() method.

A note on detector method naming and the not__ string invertor

Detector methods are functions that return TRUE or FALSE. Instead of writing the negated form of every function ( for instance, in_from() and not_in_from() ) this detector set class defines a string that will tell the detector to automatically 'NOT' the returned value. So instead of writing an actual "not_in_from()" function and bloating the class you can just pass the function name as 'not__in_from' (note double-underscore).

The not__ string can be used on any detector method (any method that returns a boolean). The return value of that function will be inverted.

// strpos_from is a custom message class method
// that tests the from address with the strpos() function
$detector_method = 'not__in_from'; // using the not__ invertor string
$detector_method_arguments = 'secretaddress@mywordpresssite.us';

// set_delete is a method in the custom header class
$callback_method = 'set_delete';
$callback_method_arguments = TRUE;

$detector = $this->peeker->make_detector_set();
$detector->make_detector($detector_method, $detector_method_arguments, $callback_method, $callback_method_arguments);