Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,110 of 9,110 pages
About the help in other languages
All help pages

Handlers named by settings

Replace one part of the system with a class chosen by a setting: getHandlerClass(), a verified mail transport, and the handler points for login, session, search, shop and more.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/extension-development/part-3-extension-developer/handlers-named-by-settings.md

On this page

Handlers named by settings

Part 3, chapter 29. Many parts of the system are handlers: a class chosen by a setting. The kernel ships a default, and an extension can provide another and select it with one line of settings. Mail transports, login, sessions, search, binary file storage, payment gateways, VAT and shipping are all handlers. This chapter shows the mechanism with a mail transport; resolving it was checked with the kernel loaded (nothing was sent).

The mechanism

eZExtension::getHandlerClass( ezpExtensionOptions $options ) (lib/ezutils/classes/ezextension.php) reads a setting, looks up a class name, and creates the object. The mail system uses it like this (eZMailTransport::send(), lib/ezutils/classes/ezmailtransport.php):

<?php
$options = new ezpExtensionOptions( array( 'iniFile'      => 'site.ini',
                                           'iniSection'   => 'MailSettings',
                                           'iniVariable'  => 'TransportAlias',
                                           'handlerIndex' => strtolower( $transportType ) ) );
$transportClass = eZExtension::getHandlerClass( $options );

[MailSettings] Transport names the alias (sendmail by default), and TransportAlias[] maps aliases to classes: file to eZFileTransport, sendmail to eZSendmailTransport, smtp to eZSMTPTransport.

A mail transport of your own

<?php
/**
 * A mail transport that sends nothing: it writes the receivers and subject to var/log/mysite_mail.log.
 * Selected with site.ini [MailSettings] Transport=mysitelog and TransportAlias[mysitelog]=mysiteLogMailTransport.
 */
class mysiteLogMailTransport extends eZMailTransport
{
    public function sendMail( eZMail $mail )
    {
        $receivers = array();
        foreach ( $mail->receiverElements() as $receiver )
        {
            $receivers[] = $receiver['email'];
        }
        eZLog::write( 'Mail to ' . implode( ', ', $receivers ) . ': ' . $mail->subject(), 'mysite_mail.log' );
        return true;
    }
}

Select it in your extension's settings/site.ini.append.php:

[MailSettings]
TransportAlias[mysitelog]=mysiteLogMailTransport

and, on a development installation, in that server's settings/override/site.ini.append.php: Transport=mysitelog. With the alias added, getHandlerClass() returned an object of mysiteLogMailTransport.

Note that the kernel's mail gate (expMailGate, the e-mail preferences) still applies on top of any transport.

Handler points

The RAD catalogue lists every handler point with its setting and contract; the Handler extension wizard writes a class for each at /setup/handlerextension/<kind>. The kinds offered there:

AreaKinds
Content and rich textxmlinput, xmloutput, attributeoperator, publishfilter, urlfilter
Storage and infrastructuredbhandler, cluster, dfsbackend, dfsdbbackend, binaryfile, search, session, staticcache, inicache, mail
Users and requestslogin, mobilefilter
RESTrestprovider, restprerouting, restrequestfilter, restresultfilter, restresponsefilter, restprefix, restroutefilter
Ajax and notificationsajaxfunction, notificationtype, notificationhandler
Packagespackagehandler, packagecreation, packageinstall
Shoppaymentgateway, paymentgatewaydirect, vat, shipping, basketinfo, exchangerate

A few registrations, from Extension points:

HandlerRegistered byContract
Loginsite.ini [UserSettings] LoginHandler[] and ExtensionDirectory[]extends eZUser, implements loginUser()
Sessionsite.ini [Session] Handlera session handler class
Search enginesite.ini [SearchSettings] SearchEngineimplements ezpSearchEngine
Mailsite.ini [MailSettings] Transport and TransportAlias[]extends eZMailTransport, implements sendMail()

Rules

  • Extend the kernel's base class or implement its interface; copy the default handler's behavior for everything you do not change.
  • Ship the alias in your extension, but let each installation choose it in its own settings: a handler for one server (a mail relay, a cluster backend) is not a default for everyone.
  • Test with the default handler switched back: removing your extension must leave a working system.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x