Custom Handler Class

This section is dedicated to developers who want to create a custom handler for page level testing. It covers PHP interface and eZ Publish INI configuration as well as explains custom handler development process based on a simple example.

In order to create a custom handler follow the steps below:

1. Create a new eZ Publish extension folder: extension/mycustomhandler
2. Create a “classes” folder under extension/mycustomhandler where PHP handler class will be stored
3. Once the folder “classes” is available, create a new PHP file “mycustomhandler.php” under extension/mycustomhandler/classes
4. The custom handler class has to implement the PHP interface “ezpMultivariateTestHandlerInterface” as follows:

class myCustomHandler implements ezpMultivariateTestHandlerInterface
{
      /**
       * Checks whether multivariate testing is enabled or not
       *
       * @return bool
       */
     public function isEnabled()
     {
            // TODO: Implement isEnabled() method.
     }
     /**
      * Executes multivariate test scenarios
      *
      * @param int $nodeID
      * @return int
      */
     public function execute($nodeID)
     {
            // TODO: Implement execute() method.
     }
}

5. Enable the extension in eZ Publish. Do this by opening the file settings/override/site.ini.append.php and adding the following command to the [ExtensionSettings] block:

ActiveExtensions[]=mycustomhandler

6. Update the autoloads class by running the script: php bin/php/ezpgenerateautoloads.php -e -p

7. Define your custom handler class on content.ini. [TestingSettings] block:

# A handler class which implements <ezpMultivariateTestHandlerInterface> interface
MultivariateTestingHandlerClass=myCustomHandler

Note: The execute() method takes a numeric Node ID as an input parameter and has to return a numeric Node ID too. It is important that the returned Node ID is valid (it has to exist in the system). Inside the execute() method you can implement your own login or algorithm to do probability calculations and return Node ID of the page that will be displayed to the end user. Your custom execute() method will be run automatically by the system.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2013 eZ Systems AS (except where otherwise noted). All rights reserved.