PHPackages                             zachleigh/artisanize - 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. zachleigh/artisanize

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

zachleigh/artisanize
====================

Use Laravel Artisan command syntax in any Symfony Console project.

v1.1.1(6y ago)122.6k31MITPHP

Since Jan 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/zachleigh/artisanize)[ Packagist](https://packagist.org/packages/zachleigh/artisanize)[ RSS](/packages/zachleigh-artisanize/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (6)Used By (1)

Artisanize
==========

[](#artisanize)

#### Use Laravel Artisan command syntax in any Symfony Console command.

[](#use-laravel-artisan-command-syntax-in-any-symfony-console-command)

[![Latest Stable Version](https://camo.githubusercontent.com/7f1bd188eb5fe51b3a3b40f4d547a3bb8158ca34e3fab98837ea925d8f4e9879/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6163686c656967682f6172746973616e697a652e737667)](https://packagist.org/packages/zachleigh/artisanize)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](//packagist.org/packages/zachleigh/artisanize)[![Build Status](https://camo.githubusercontent.com/d711b5a31d68fbe303f4a0bab15163232f75492bcdc349a306778338bbd2de37/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7a6163686c656967682f6172746973616e697a652f6d61737465722e737667)](https://travis-ci.org/zachleigh/artisanize)[![Quality Score](https://camo.githubusercontent.com/20a5b7a33680c0977a25ce43fb1aaf9274b6927407f3f47adcfd342daa3aa18c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a6163686c656967682f6172746973616e697a652e737667)](https://scrutinizer-ci.com/g/zachleigh/artisanize/)[![StyleCI](https://camo.githubusercontent.com/3679c10a5ace8f57708808892d53bc69415016826a2a74463c0db3e3a0b3b281/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131373333393532372f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/117339527)

Contents
--------

[](#contents)

- [Installation](#installation)
- [Writing Commands](#writing-commands)
    - [Command Signature](#command-signature)
        - [Defining Command Arguments](#defining-command-arguments)
        - [Defining Command Options](#defining-command-options)
    - [Accessing Command Arguments And Options](#accessing-command-arguments-and-options)
    - [Asking for Confirmation](#asking-for-confirmation)
    - [Asking a Question](#asking-a-question)
    - [Asking for a Password](#asking-for-a-password)
    - [Choosing from a List](#choosing-from-a-list)
    - [Autocompletion](#autocompletion)
    - [Multiple Choice](#multiple-choice)
    - [Command Output](#command-output)
- [Credits and Contributing](#credits-and-contributing)

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

[](#installation)

Install into any new or existing project that uses Symfony Console via composer:

```
composer require zachleigh/artisanize

```

Then, in your command files, rather than extend Symfony's base command (Symfony\\Component\\Console\\Command\\Command), extend the Artisanize Command class (Artisanize\\Command). Define `signature` and `description` properties and a `handle`method on the class.

```
use Artisanize\Command;

class MyCommand extends Command
{
    /**
     * The command signature.
     *
     * @var string
     */
    protected $signature = 'signature';

    /**
     * The command description.
     *
     * @var string
     */
    protected $description = 'Description.';

    /**
     * Handle the command.
     */
    protected function handle()
    {
        // Handle your command
    }
}
```

Writing Commands
----------------

[](#writing-commands)

A command class has three components: a signature, a description, and a handle method.

```
use Artisanize\Command;

class ExampleCommand extends Command
{
    /**
     * The command signature.
     *
     * @var string
     */
    protected $signature = 'namespace:name {argument} {--o|option=default}';

    /**
     * The command description.
     *
     * @var string
     */
    protected $description = 'Command decription.';

    /**
     * Handle the command.
     */
    protected function handle()
    {
        // handle the command
    }
}
```

`signature` is where you define your command's name, arguments, and options. This is discussed in detail below. `description` is where you can set a description message for your command to be displayed when using the console. The `handle` method will be called when the command is fired and is where you should write the logic for your command.

### Command Signature

[](#command-signature)

The command signature is written in the same way that the command will be used in the console and consists of three parts: the command name, arguments, and options. The command name must come first in the signature and can be namespaced by prefixing the command name with a namespace followed by a colon (':'):

```
protected $signature = 'namespace:name';
```

Arguments and options are enclosed in curly braces and follow the command name. Options are prefixed by two dashes ('--').

#### Defining Command Arguments

[](#defining-command-arguments)

A standard argument consists of the argument name wrapped in curly braces:

```
protected $signature = 'namespace:name {arg} {--option}'
```

The argument name, `arg` in the example above, is used to access the argument value via the [`argument` method](#accessing-command-arguments-and-options).

To make an argument optional, append a question mark ('?') to the argument name:

```
protected $signature = 'namespace:name {arg?} {--option}'
```

To give the argument a default value, separate the argument name and the default value with an equals sign ('='):

```
protected $signature = 'namespace:name {arg=default} {--option}'
```

If no value is provided for the argument, the default value will be used.

If the argument is in array form, append an asterisk ('\*') to the argument name:

```
protected $signature = 'namespace:name {arg*} {--option}'
```

Arguments can then be passed to the command by space separating them:

```
php app.php namespace:name one two three

```

This will set the value of `arg` to `['one', 'two', 'three']`.

Argument arrays can also be set as optional:

```
protected $signature = 'namespace:name {arg?*} {--option}'
```

When accessing optional argument arrays, arguments that have not been passed equal an empty array.

It is often helpful to provide a description with an argument. To do this, add a colon (':') after the argument definition and append the description:

```
protected $signature = 'namespace:name {arg=default : Argument description} {--option}'
```

#### Defining Command Options

[](#defining-command-options)

A standard option consists of the option, prefixed by two dashes ('--'), wrapped in curly braces:

```
protected $signature = 'namespace:name {argument} {--opt}'
```

The option name, `opt`, is used to access the argument value via the [`option` method](#accessing-command-arguments-and-options). Standard options do not take values and act as true/false flags: the presence of the option when the command is called sets its value to true and if it is not present, the value is false.

To define an option with a required value, append an equals sign ('=') to the option name:

```
protected $signature = 'namespace:name {argument} {--opt=}'
```

To set a default value, place it after the equals sign:

```
protected $signature = 'namespace:name {argument} {--opt=default}'
```

Options may also have shortcuts to make them easier to remember and use. To set a shortcut, prepend it to the command name and separate the two with a pipe ('|'):

```
protected $signature = 'namespace:name {argument} {--o|opt}'
```

Now, the option may be called in the standard way:

```
php app.php namespace:name argument --opt

```

Or by using the shortcut:

```
php app.php namespace:name argument -o

```

Options may also be passed as arrays:

```
protected $signature = 'namespace:name {argument} {--opt=*}'
```

When passing options arrays, each value must be prefixed by the option name:

```
php app.php namespace:name argument --opt=one --opt=two --opt=three

```

The value of `opt` will be set to `['one', 'two', 'three']`.

Just like with arguments, the option description can best by appending a colon (':') and the description to the option name definiton:

```
protected $signature = 'namespace:name {argument} {--o|opt : option description.}'
```

### Accessing Command Arguments And Options

[](#accessing-command-arguments-and-options)

To access arguments in the handle method, use the command class `argument` method. If an argument name is given, it will return the value of the argument and if nothing is passed, it will return an array of all arguments:

```
protected function handle()
{
    $arg = $this->argument('arg'); // passed value of arg

    $allArguments = $this->argument(); // array of all arguments
}
```

The `option` method works in the exact same way:

```
protected function handle()
{
    $opt = $this->option('opt'); // passed value of opt

    $allOptions = $this->option(); // array of all options
}
```

There are also `hasArgument` and `hasOption` methods on the command object:

```
protected function handle()
{
    $argExists = $this->hasArgument('exists');  // true

    $optExists = $this->hasOption('doesntExist');  // false
}
```

### Asking for Confirmation

[](#asking-for-confirmation)

The `confirm` method can be used to ask the user for simple confirmation:

```
if ($this->confirm('Do you wish to continue? ')) {
    // user answered true
}
```

### Asking a Question

[](#asking-a-question)

The `ask` method can be used to ask a user a question. Pass a default value as the second argument:

```
$name = $this->ask('What is your name?', 'Nobody');
```

### Asking for a Password

[](#asking-for-a-password)

The user answer can be hidden by using the `askPassword` method:

```
$password = $this->askPassword('Please type your password');
```

### Choosing From a List

[](#choosing-from-a-list)

The `choose` method only allows an answer from a predefined list of choices. The default value can be passed as the third argument:

```
$car = $this->choose('What is your favourite car?', ['Ferrari', 'Lamborghini', 'Maserati'], 1);
```

### Autocompletion

[](#autocompletion)

The `anticipate` method can provide the user with some auto-completion help when starting to write. The user can still provide any answer, regardless of the auto-completion hints:

```
$food = $this->anticipate('What is your favourite food?', ['Pizza', 'Pasta', 'Lasagna'], 'Mozzarella');
```

### Multiple Choice

[](#multiple-choice)

When the user should be allowed to choose more than a single answer, the `choice`method allows them to select multiple items from a list. The third argument contains a string of comma-separated defaults:

```
$colors = $this->choice('What are your favourite colors (defaults to blue and red)?', ['Blue', 'Red', 'Green'], '0,1');
```

### Command Output

[](#command-output)

Every command has an `output` variable stored on the object that has several methods to help write output to the console.

The `write` method outputs plain unformatted text, `writeInfo` outputs green text, `writeError` outputs red text, and `writeComment` outputs yellow text:

```
protected function handle()
{
    $this->output->write('Message'); // plain text

    $this->output->writeInfo('Message');  // green text

    $this->output->writeError('Message');  // red text

    $this->output->writeComment('Message');  // yellow text
}
```

The output variable is a simple wrapper around Symfony's output class. To access this class, use the `getOutputInterface` method:

```
protected function handle()
{
    $output = $this->getOutputInterface(); // $output is instance of Symfony\Component\Console\Output\OutputInterface
}
```

Keep in mind that since the Artisanize Command class simply wraps up the Symfony console component, all Symfony command features are still available on your command objects. For more information on Symfony Commands, see the [Symfony console component documentation](http://symfony.com/doc/current/components/console.html).

Credits and Contributing
------------------------

[](#credits-and-contributing)

This project was extracted out of the [Yarak](https://github.com/zachleigh/yarak)project. Many thanks to @micheleangioni for his contributions to that codebase, many of which have made their way here.

Contributions are more than welcome. Fork, improve and make a pull request. For bugs, ideas for improvement or other, please create an issue.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~239 days

Total

4

Last Release

2369d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00a76b63e84a85f8770b1b02b1190c03400c48528f0c33262f7789d35eca875d?d=identicon)[zachleigh](/maintainers/zachleigh)

---

Top Contributors

[![zachleigh](https://avatars.githubusercontent.com/u/5616626?v=4)](https://github.com/zachleigh "zachleigh (24 commits)")

---

Tags

artisanconsolelaravelsymfonysymfony-consoleconsolesymfonylaravelartisan

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zachleigh-artisanize/health.svg)

```
[![Health](https://phpackages.com/badges/zachleigh-artisanize/health.svg)](https://phpackages.com/packages/zachleigh-artisanize)
```

###  Alternatives

[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.7k348.7M10.5k](/packages/nunomaduro-collision)[nunomaduro/laravel-console-menu

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

815424.6k52](/packages/nunomaduro-laravel-console-menu)[nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2592.3M13](/packages/nunomaduro-laravel-console-task)[nunomaduro/laravel-console-summary

A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.

672.2M4](/packages/nunomaduro-laravel-console-summary)[nunomaduro/laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.

16357.3k8](/packages/nunomaduro-laravel-console-dusk)[rahul900day/laravel-console-spinner

Laravel Console Spinner is a spinner output for Laravel command line.

76128.8k1](/packages/rahul900day-laravel-console-spinner)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
