ilesinge / website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

StyleCI Status Build Status Quality Score Latest Stable Version Software License

This is a community project and not an official Laravel one

Laravel Zero was created and maintained by Nuno Maduro. Laravel Zero is a micro-framework that provides an elegant starting point for your console application. Unofficial and customized version of Laravel optimized for building command-line applications.

Requirements & Installation

Requires PHP 7.1+

Via Laravel Zero Installer

composer global require laravel-zero/installer
laravel-zero new your-app-name

Or simply create a new Laravel Zero project using Composer:

composer create-project --prefer-dist laravel-zero/laravel-zero your-app-name

To run your application just type in your application root folder:

php your-app-name

You can rename your application anytime by running the following command in your app directory:

php your-app-name app:rename new-name

Usage

App\Commands

Laravel Zero provides you an app\Commands\HelloCommand.php as example. Create a new command using:

php your-app-name make:command NewCommand

Concerning the Command file content, you may want to review the documentation of the Artisan Console component:

  • The Defining Input Expectations section allows you to understand how to gather input from the user through arguments or options. As example:
 protected $signature = 'user:create
                        {name : The name of the user} // required
                        {--age= : The age of the user}'; // optional.

  • The Command I/O allows you to understand how to capture those input expectations and interact the with using commands like line, info, comment, question and error methods.

Laravel Zero adds an extra option allowing desktop notifications:

  $this->notify("Title", "Body", "icon.png");

The default command of your aplication is the symfony ListCommand, that provides a list of commands. You may change this behavior modifying the config/app.php:

    'default-command' => App\Commands\DefaultCommand::class,

All commands should exists within app/Commands directory in order to be automatic registered by the application. You may want to load other commands or other commands paths modifying config/app.php:

    'commands' => [
      App\Prod\CleanCache::class,
    ],

    'commands-paths' => [
      "Local/Commands",
      "Deploy/Commands"
    ],

You may want to hide development commands moving the application to production modifying the config/app.php:

    'production' => true,

App\ServiceProviders

Laravel Zero recommends the usage of Laravel Service Providers for defining concrete implementations. Define them in app\Providers\AppServiceProvider.php or create new service providers. The config/app.php providers array contain the registered service providers. Below there is an example of a concrete implementation bound to a contract/interface.

    public function register()
    {
        $this->app->singleton(Contract::class, function ($app) {
            return new Concrete(config('database'));
        });
    }

    app(Contract::class) // Returns a Concrete implementation.

Config

The config\app.php file contains your application configuration, there you can create a new configuration foo => true and access to the that same configuration using config('app.foo').

All files within config folder are automatic registered as configuration files. You can also create specific configuration files, E.g: app\bar.php and access it by config('bar').

Tests

The tests folder contains your phpunit tests. By default, the Laravel Zero ships with an Integration suite that can be used like the example below:

class CommandTest extends TestCase
{
    /** @test */
    public function it_checks_the_command_output(): void
    {
        $this->app->call('command-name');

        $this->assertTrue($this->app->output() === 'Love beautiful code? We do too.');
    }
}

Running your application tests:

./vendor/bin/phpunit

Database

Laravel Zero allows you to install a Database component out of the box to push your console app to the next level. As you might have already guessed it is Laravel's Eloquent component that works with the same breeze in Laravel Zero environment too.

php your-app-name database:install

Usage:

use Illuminate\Support\Facades\DB;

DB::table('users')->insert(
    ['email' => 'enunomaduro@gmail.com']
);

$users = DB::table('users')->get();

Laravel Database Migrations feature is also included.

Filesystem

If you want to move files in your system, or to multiple providers like AwsS3 and Dropbox, Laravel Zero ships with Filesystem component by default.

Note: The root directory is your-app-name/storage/local.

use Illuminate\Support\Facades\Storage;

Storage::put("reminders.txt", "Task 1");

Scheduler

Laravel Zero ships with the Task Scheduling of Laravel, to use it you may need to add the following Cron entry to your server:

* * * * * php /path-to-your-project/your-app-name schedule:run >> /dev/null 2>&1

You may define all of your scheduled tasks in the schedule method of the command:

    public function schedule(Schedule $schedule): void
    {
        $schedule->command(static::class)->everyMinute();
    }

You may want to remove this feature, modifying config/app.php:

    'with-scheduler' => false,

Building a standalone application

Your Laravel Zero project, by default, allows you to build a standalone PHAR archive to ease the deployment or the distribution of your project.

php your-app-name app:build <your-build-name>

The build will provide a single phar archive, ready to use, containing all the code of your project and its dependencies. You will then be able to execute it directly:

./builds/<your-build-name>

or on Windows:

C:\application\path> php builds\<your-build-name>

Collision - Detailed & intuitive errors

Love Whoops on Laravel? Get ready for a similar error handler! Laravel Zero ships with Collision giving you a detailed & intuitive interface for errors and exceptions on your console application.

Get more details: https://github.com/nunomaduro/collision.

Tinker

Laravel Tinker is a powerful REPL for Laravel. Jorge González made it available for Laravel Zero.

Get more details: https://github.com/intonate/tinker-zero.

Support & Community

Thank you for considering to contribute to Laravel Zero. All the contribution guidelines are mentioned here.

You can have a look at the CHANGELOG for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements : @enunomaduro

License

Laravel Zero is an open-sourced software licensed under the MIT license.

About


Languages

Language:HTML 100.0%