stephenjude/extended-artisan-commands

Generate plain PHP files using artisan console commands.

3.0.3 2023-06-01 12:38 UTC

This package is auto-updated.

Last update: 2024-11-06 13:05:38 UTC


README

Latest Version on Packagist Build Status Total Downloads

Have you ever enjoyed the assistance of artisan commands? This package brings more of it :)

You can now generate PHP classes and traits using artisan make:class, make:interface, make:trait or make:abstract-class console commands.

Installation

Step 1: Install Through Composer

composer require stephenjude/extended-artisan-commands --dev

Step 2: Run Artisan!

You're all set. Run php artisan from the console, and you'll see the new commands in the make:* namespace section.

  • make:interface
  • make:class
  • make:abstract-class
  • make:trait
  • make:enum

Usage

Here's a few other examples of commands that you might write:

php artisan make:class Services/EmailForwarderService
php artisan make:abstract-class Services/AbstractEmailForwarder
php artisan make:interface EmailForwarderContract
php artisan make:trait FileUpload
php artisan make:enum Permission

Option for all the commands

--force This will overide the existing file, if it exist

Options for the make:class command

  • --interface OR -i This will generate an interface for the generated class.
  • --trait OR -t This will generate a trait for the generated class.
  • --abstract OR -c This will generate an abstract class for the generated class.
  • --all OR -a This will generate an interface, a trait and an abstract class for the generated class.

Example:

This will generate an interface for this class.

php artisan make:class Services/EmailForwarderService --interface

This will generate a trait for this class.

php artisan make:class Services/EmailForwarderService --trait

Default Namespaces

  • All interfaces are generated under the App/Contracts namespace.
  • All traits are generated under the App/Traits namespace.
  • All enums are generated under the App/Enums namespace.
  • Classes and abstract classes are generated under the App namespace.

Default namespaces can be configured inside the package config file.

Configurations

You can configure default namespace by publishing the package config file:

php artisan vendor:publish --provider="Stephenjude\ExtendedArtisanCommands\ExtendedArtisanCommandsServiceProvider" --tag="config"

Configuring Default Namespace

return [
    /*
    |--------------------------------------------------------------------------
    | Default Class Namespace
    |--------------------------------------------------------------------------
    |
    | Here you can configure the default namespace for
    | the make:class command.
    |
    */

    'class_namespace' => '',


    /*
    |--------------------------------------------------------------------------
    | Default Abstract Class Namespace
    |--------------------------------------------------------------------------
    |
    | Here you can configure the default namespace for
    | the make:abstract-class command.
    |
    */

    'abstract_class_namespace' => '',


    /*
    |--------------------------------------------------------------------------
    | Default Interface Namespace
    |--------------------------------------------------------------------------
    |
    | Here you can configure the default namespace for
    | the make:interface command.
    |
    */

    'interface_namespace' => '\Contracts',


    /*
    |--------------------------------------------------------------------------
    | Default Trait Namespace
    |--------------------------------------------------------------------------
    |
    | Here you can configure the default namespace for
    | the make:trait command.
    |
    */

    'trait_namespace' => '\Traits',
    
        /*
    |--------------------------------------------------------------------------
    | Default Enum Namespace
    |--------------------------------------------------------------------------
    |
    | Here you can configure the default namespace for
    | the make:enum command.
    |
    */

    'enum_namespace' => '\Enums',
];

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email stephenjudesuccess@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.