Open main menu

ObjectFactory creates objects from specifications (via ObjectFactory::getObjectFromSpec()). This format is used by certain configuration settings (such as $wgMWLoggerDefaultSpi or $wgSessionProviders). A typical specification looks like this:

$spec = [
    'class' => 'Message',
    'args' => [ 'unexpected', [ 'foo', 123 ] ],
];

which is the specification for new Message( 'unexpected', [ 'foo', 123 ] ).

Other options include:

$spec = [
    'factory' => 'Message::newFallbackSequence',
    'args' => [ 'unexpected', 'unexpected2' ],
];
// Message::newFallbackSequence( 'unexpected', 'unexpected2' )
$spec = [
    'class' => 'Message',
    'args' => [ 'foo', 'bar' ],
    'calls' => [ 'inLanguage' => [ 'en' ], 'useDatabase' => [ false ] ],
];
// will call $message->inLanguage( 'en' ), $message->useDatabase( false ) after creating $message

External linksEdit