Skip to content
Yo-An Lin edited this page Apr 23, 2015 · 1 revision

Sometimes you need to share the logics between different commands for the same option, and option trigger is designed for this purpose. You can define a trigger with a Closure, and once the option value is set via Option::setValue, the trigger will be get called.

here is the sample code of using option trigger:

$specs->add('file:', 'option value should be a file.' )
    ->isa('File');
    ->trigger(function($value) {
        echo "Set value to :";
        var_dump($value); // we will get `SplFileInfo` object here since we defined the option as a 'File' option.
    })

Clone this wiki locally