PHPackages                             modulate/artisan-interceptor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. modulate/artisan-interceptor

ActiveLibrary[CLI &amp; Console](/categories/cli)

modulate/artisan-interceptor
============================

Allows you to add options, listeners and handlers to artisan commands

v1.0.0(2y ago)08MITPHPPHP ^8.1

Since Sep 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/modulate-php/artisan-interceptor)[ Packagist](https://packagist.org/packages/modulate/artisan-interceptor)[ RSS](/packages/modulate-artisan-interceptor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Modulate Artisan Interceptor
============================

[](#modulate-artisan-interceptor)

### An easy but elegant way to change global behaviours of Artisan commands

[](#an-easy-but-elegant-way-to-change-global-behaviours-of-artisan-commands)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9acbeb2ac8acf279715a3a217f4f9428e327471cfca63c94d280bcb3b495875a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f64756c6174652f6172746973616e2d696e746572636570746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/modulate/artisan-interceptor)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5fd44dd2629ad77351add86405e41823b16f422f94a667dfb304e2ae37c82d42/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6f64756c6174652d7068702f6172746973616e2d696e746572636570746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/modulate-php/artisan-interceptor/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/54d060abd9769c29909f29675f88ba1063e3bc5d4cf30ec6b40bc33f9334a640/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6f64756c6174652d7068702f6172746973616e2d696e746572636570746f722f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/modulate-php/artisan-interceptor/?branch=main)[![Build Status](https://camo.githubusercontent.com/1078e20b27d4da2b94001196666dfd3f3864795a8d44ae8c8c656a8e40aa18c4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6f64756c6174652d7068702f6172746973616e2d696e746572636570746f722f6261646765732f6275696c642e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/modulate-php/artisan-interceptor/build-status/main)[![Total Downloads](https://camo.githubusercontent.com/7e5fae1b657f0c9b5e210ddbafd0e214b6e3299a193f59cd0b0bf2ab02a88a21/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f64756c6174652f6172746973616e2d696e746572636570746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/modulate/artisan-interceptor)

Features
--------

[](#features)

- Add new global options to artisan e.g. --tenant=2 or --module=my-module
- Add handlers to be executed before and/or after an artisan command is run
- Add conditional handlers than only run when a specified option is given to a command
- Fluent builder for adding input options to artisan

Adding Global Options
---------------------

[](#adding-global-options)

Generally speaking there is currently no easy way to add new global options to the artisan command. Options like --env or --version come built in but artisan doesn't expose a way for you to add new ones out of the box. This is where artisan interceptor comes in.

The interceptor allows you to add new global options to artisan and add your own custom handlers detect and process those options. This is all done using the built in artisan events but gives you a clean and elegant way of adding and interacting with new options

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require modulate/artisan-interceptor
```

Usage
-----

[](#usage)

### Adding Global Options

[](#adding-global-options-1)

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

// Adding required options to the shell to handle things like authentication
ArtisanInterceptor::addOptions(
    ArtisanInterceptor::optionBuilder()
        ->name('user')
        ->required()
        ->get(),
    ArtisanInterceptor::optionBuilder()
        ->name('password')
        ->required()
        ->get()
);
```

### Adding Listeners

[](#adding-listeners)

```
