Available in stable development 1.17 1.16 1.15 1.14 1.13 1.12 1.11 1.10 1.9 1.8 1.7 1.6

core:PHP

This is a filter which makes it possible to run arbitrary PHP code to modify the attributes or state of an user.

1 Parameters

class
This is the name of the filter. It must be 'core:PHP'.
code
The PHP code that should be run. This code will have two variables available:

2 Examples

Add the mail attribute based on the user's uid attribute:

10 => array(
    'class' => 'core:PHP',
    'code' => '
        if (empty($attributes["uid"])) {
            throw new Exception("Missing uid attribute.");
        }

        $uid = $attributes["uid"][0];
        $mail = $uid . "@example.net";
        $attributes["mail"] = array($mail);
    ',
),

Create a random number variable:

10 => array(
    'class' => 'core:PHP',
    'code' => '
        $attributes["random"] = array(
            (string)rand(),
        );
    ',
),

Force a specific NameIdFormat. Useful if an SP misbehaves and requests (or publishes) an incorrect NameId

90 => array(
     'class' => 'core:PHP',
     'code' => '$state["saml:NameIDFormat"] = ["Format" => "urn:oasis:names:tc:SAML:2.0:nameid-format:transient", "AllowCreate" => true];'
),