Skip to content

Console

StefansArya edited this page Apr 17, 2019 · 5 revisions

This framework has a build-in server by calling

$ php scarlets serve (port) (address) (options)

Address: localhost, network, IPAddress
Options: --log, --verbose

alt text

Even the build-in server was blazingly fast, it still have some problem because it's running in a single thread for every request. So it's very recommended to setup your website using Nginx. But if you want to deploy a small server into Raspberry PI, Android, or other linux devices it may be better to use the build-in server.

You can also create your own command for your project

alt text

The user defined command are editable on /routes/console.php

Define command

Console::command(pattern, callback, info='');

Console::command('echo {*}', function($message){
    echo($message);
});

Use invisible writting

Console::hiddenInput();

Console::command('input', function(){
    echo("Type something invisible: ");
    print_r("Result: ".Console::hiddenInput());
}, 'Type something');

Change text color

Console::chalk(text, color);

Console::command('echo {*}', function($message){
    echo(Console::chalk("Computer> $message", 'yellow'));
});

Match more pattern

Console::args(pattern, callback);

Console::command('echo {*}', function($all){
    Console::args('{0} {1}', function($name, $message){
        echo("$name> $message");
    });

    // Check if args above was not being called
    if(!Console::$found)
        echo "Computer> $all";
});

Adding help section

Console::help(text, color);

Console::help('echo', "Type 'echo (anything here)' to get echo back.");

Clear console

Console::clear();

Check if running on console

Console::isConsole() === true;

Obtain registered console command

Console::collection();

Arrange result as a table on console

Console::table(array);
Clone this wiki locally