Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.

Docs Request Filters

Frank Kleine edited this page Apr 7, 2012 · 1 revision

Table of Contents

Application specific filters

Applies to Stubbles 1.3.0 or greater. For Stubbles versions before 1.3.0 please see Filters before 1.3.0.

Create your own filter class

While Stubbles already provides a list of filters by default and those are very easy to use via the Request API, sometimes it is required to create your own filter for application specific needs. To create a filter one has to implement the net::stubbles::ipo::request::filter::stubFilter interface. This interface consists of a single method execute($value) which does the actual filtering.

The execute($value) is allowed to throw exceptions of the type net::stubbles::ipo::request::filter::stubFilterException. This exception expects an instance of net::stubbles::ipo::request::stubRequestValueError. See Request Errors for more details.

Make the filter available

In order to make the filter available via the Request API it has to be introduced to the filter creation mechanism. To do this, simply call the net::stubbles::ipo::ioc::stubIpoBindingModule::addFilterForType() method when you create the bindings:

$ipoBindingModule->addFilterForType('my::package::filter::ExampleFilter', 'example');

After the binding process is complete, the filter is available via the Request API:

$fooExample = $request->readParam('foo')->asType('example');

If used this way the filter class is also applicable for dependency injection. In case you have specific options for the filter to be set at runtime:

$fooExample = $request->readParam('foo')->withFilter($filterFactory->createForType('example')->asRequired()->setExampleConfig(313));

Here you need to have an instance of net::stubbles::ipo::request::filter::stubFilterFactory. It's createForType() method returns an instance of net::stubbles::ipo::request::filter::stubFilterBuilder which decorates your own filter class. You can still call all methods of your own filter class - the net::stubbles::ipo::request::filter::stubFilterBuilder has a magic __call() method which passes the method call to the decorated filter.

Providing filters within star files

In case you have a module which provides filters you can add them to be automatically available and detected by the framework. To enable this you need to have a file ipo/filter.ini in your star file. The content of the file should look like this:

[filter]
example=my::package::ExampleFilter

With this and the star module within the lib directory of an application the application can use the filter with

$example = $request->readParam('foo')->withFilter($filterFactory->createForType('example');

without adding it manually as described above.

Clone this wiki locally