Skip to content

Command line tool to generate your classes, interfaces and traits. Aiming for higher productivity

License

Notifications You must be signed in to change notification settings

DavidNgugi/laravel-php-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel PHP Generator

A simple command line tool to generate your Laravel classes, interfaces and traits. Aiming for your higher productivity

Installation

composer require davidngugi/laravel-php-generator

Documentation

The package allows you to generate Classes, Interfaces and Traits. You can generate classes that extend another class and implements an interface. The package generates the necessary directories as specified by the -p or path option. Otherwise there is a default path used.

All paths lead to the App directory. So don't have App in you path.

The following subsections explain further how to use the various commands

NOTE: Replace the string in curly braces with your own values

Create a class

php artisan generate:class {class_name_here}

Example

php artisan generate:class Account

this generates the following

<?php

namespace App\Logic;

class Account 
{
    //
}

Including the path. E.g Logic/Core

php artisan generate:class -p {path_here} {class_name_here}

You can generate multiple classes at a go

php artisan generate:class {class1_name_here} {class2_name_here} {class3_name_here}

Create and Extend a class

We use the -e or --extend option. Specify the name of the class to extend. The class to extend will also be generated if it doesn't exist. You can only extend one class

php artisan generate:class -e {name_of_class_to_extend} {class_name_here}

Example

php artisan generate:class -e BankAccount CurrentAccount

this generates the following 2 files:

<?php

namespace App\Logic;

class BankAccount
{
    //
}
<?php

namespace App\Logic;

use App\Logic\BankAccount;

class CurrentAccount extends BankAccount
{
    //
}

Generate a class and Implement an Interface

We use the -i or --interface option. Specify the name of the interface to implement.

NOTE: The interface name should be without the word 'Interface' at the end, this will be auto-generated . You can only implement one interface

php artisan generate:class -i{name_of_interface_to_extend} {class_name_here}

Example:

php artisan generate:class -i Finance BankAccount

this will generate the following 2 files:

An interface

<?php

namespace App\Logic;

interface FinanceInterface
{
    //
}

and a class

<?php

namespace App\Logic;

use App\Logic\FinanceInterface;

class BankAccount implements FinanceInterface
{
    //
}

Create and Extend a class and Implement an Interface

We use the above options (-e and -i).

php artisan generate:class -e {name_of_class_to_extend} -i  {class_name_here}

Example

php artisan generate:class -e BanckAccount -i Finance CurrentAccount

this generates

<?php

namespace App\Logic;

use App\Logic\FinanceInterface;
use App\Logic\BankAccount;

class CurrentAccount extends BankAccount implements FinanceInterface
{
    //
}

NOTE: No existing files or folders will be overwritten by these commands

Create an Interface

We use the generate:interface artisan command. This also supports the -p or --path option to specify the directory path.

App\Logic\Interfaces is the default path

php artisan generate:interface {interface_name}

Example

php artisan generate:interface Finance

this generates the following

<?php

namespace App\Logic\Interfaces;

/**
*  FinanceInterface Interface
*/
interface FinanceInterface
{
    //
}

Create a Trait

We use the generate:trait artisan command. This also supports the -p or --path option to specify the directory path.

App\Logic\Traits is the default path

php artisan generate:trait {trait_name}

Example

php artisan generate:trait Transactable

this generates the following

<?php

namespace App\Logic\Traits;

/**
*  Transactable Trait
*/
trait Transactable 
{
    //
}

Contribution

All contributions (big or small) are highly welcomed. Send a PR

Authors

Support

If you would love to support the continuous development and maintenance of this package, please consider buying me a coffee.

License

This package is open-sourced software licensed under the MIT Licence

About

Command line tool to generate your classes, interfaces and traits. Aiming for higher productivity

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages