jimchen/script

Simple to write script in PHP.

v1.0.0 2018-10-17 15:19 UTC

This package is auto-updated.

Last update: 2022-05-18 00:20:28 UTC


README

Simple to write script in PHP.

Installing

$ composer create-project jimchen/script script --prefer-dist

Usage

Create a command file

$ cd script/
$ php artisan make:command HelloCommand  // Create a file named `HelloCommand` in `app/Commands`

Write your command file

In app/Commands/HelloCommand.php

<?php

namespace App\Commands;

use Illuminate\Console\Command;

class HelloCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'A test command';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $this->info('Hello World!');
    }
}

Configuration

In app/Kernel.php

<?php

namespace App;

use App\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Commands\HelloCommand::class,
    ];
    
    ...
}

License

MIT