Start One Command Line Tool use Silly CLI micro-framework based on Symfony Console



Base Command Line Tool use Silly CLI micro-framework based on Symfony Console

Donate Me

Buy me a coffee:  https://paypal.me/nguyenanhung

Summary

Key Value
Project Start Project PHP CLI
Framework Silly CLI micro-framework
GitHub https://github.com/nguyenanhung/start-project-use-command
Packagist https://packagist.org/packages/nguyenanhung/start-project-use-command

Install the Application

Run this command from the directory in which you want to install your new CLI micro-framework application.

composer create-project nguyenanhung/start-project-use-command [my-app-name]

or

php composer.phar create-project nguyenanhung/start-project-use-command [my-app-name]

Replace  [my-app-name]  with the desired directory name for your new application.

Usage

Create  TestCommand  in namespace  Bear\App\Controllers

class TestCommand
{
    public function __invoke($name, $upper, OutputInterface $output)
    {
        if ($name) {
            $text = 'Hello, Iam ' . $name;
            $output->writeln("Nguyễn An Hưng");
        } else {
            $text = 'Hello, Iam.' . $this->son();
        }
        if ($upper) {
            $text = strtoupper($text);
        }
        $output->writeln($text);
    }

    protected function son(): string
    {
        return "Bear";
    }
}

And declare Command in  Bear  in  bear  file in root folder

#!/usr/bin/env php
<?php
// Register Application Space
define('BEAR', $_SERVER['BEAR_ENV'] ?? 'production');

// Includes Composer Vendor Packages
require_once __DIR__ . '/vendor/autoload.php';

use Silly\Edition\PhpDi\Application;

$app = new Application();

// Routes list Command
$app->command('greet [name] [--upper]', 'Bear\App\Controllers\TestCommand');

try {
    $app->run();
}
catch (Exception $e) {
    echo $e->getMessage();
}

Running the application is the same as running any other Symfony Console application:

$ php bear greet
Hello
$ php bear greet john --yell
HELLO JOHN
$ php bear greet --yell john
HELLO JOHN

Silly\Application  extends  Symfony\Console\Application  and can be used wherever Symfony's Application can.

Documentation

Also see Official Document here:  https://github.com/mnapoli/silly

Contact

If any question & request, please contact following information

Name Email Skype Facebook
Hung Nguyen [email protected] nguyenanhung5891 @nguyenanhung

From Hanoi with Love <3

Nhận xét

Bài đăng phổ biến từ blog này

Tạo SSH key trên MAC OS X

Journalctl: How to Read and Edit Systemd Logs

How to Restore a Deleted File in Linux