PHP code example of modulate / artisan-interceptor

1. Go to this page and download the library: Download modulate/artisan-interceptor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

modulate / artisan-interceptor example snippets


// Add a new optional option to artisan
ArtisanInterceptor::addOption(
    ArtisanInterceptor::optionBuilder()
        ->name('tenant')
        ->optional()
        ->get()
);

// Adding e('password')
        ->


use Modulate\Artisan\Interceptor\InterceptedCommand;

ArtisanInterceptor::before(function(InterceptedCommand $intercepted) {
    // Add a callback that runs before the command is run
    // but will only run if the given option is set
    $intercepted->getOutput()->writeln(sprintf(
        'Hello from %s tenantId: %d', 
        $intercepted->getCommand(),
        $intercepted->getInput()->getOption('tenant')
    ));
}, 'tenant')
->after(function(InterceptedCommand $intercepted) {
    // Add a callback that runs after the command is run
    // but will only run if the given option is set
    $intercepted->getOutput()->writeln(sprintf(
        'exitCode %d',
        $intercepted->getExitCode(),
    ));
}, 'tenant')
->after(function(InterceptedCommand $intercepted) {
    // You can also omit the option parameter to a before or after
    // callback to always run the callback
    $intercepted->getOutput()->writeln('This callback will always run after a command');
});