-
Notifications
You must be signed in to change notification settings - Fork 24
Option Trigger
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.
})Related Works:
- CLIFramework: https://github.com/c9s/CLIFramework
Applications using GetOptionKit and CLIFramework:
- PHPBrew: https://github.com/phpbrew/phpbrew
- LazyRecord: https://github.com/c9s/LazyRecord
- PHPRelease: https://github.com/c9s/PHPRelease
- AssetKit: https://github.com/c9s/AssetKit
- Onion: https://github.com/c9s/Onion