Download the PHP package lotfio/conso without Composer
On this page you can find all versions of the php package lotfio/conso. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package conso
Conso (PHP console applications for cool kids).
🔥 Introduction :
Conso is a simple, lightweight PHP package that helps you create (executable, .phar
, shareable) command line applications easily.
:collision: Is it really lightweight ?
📌 Requirements :
- PHP >= 7.2 or newer versions
- PHPUnit >= 8 (for testing purpose)
🚀 Installation :
-
Via composer :
- for testing
🎉 Write your first command
- create a
commands.php
file. - create a
conso
file (you can change the name as you like). - include your
commands.php
file intoconso
executable file. - it should look something like this.
:star: Available config methods :
-
now define a new
test
command in yourcommands.php
: - now your command has been registered.
- run
php conso --commands
or./conso --commands
in your terminal and you should see your command.
- command test is registered now (no description is shown you can add this later on).
- run your command
php conso test
or./conso test
.
:star: Add description
->description(string $description)
;
:star: Define sub commands
->sub(string|array $subCommand)
;
:star: Define command flags
- you can define flags using the flag method
->flags(string|array $flag)
- this is a list of reserved flags
['-h', '--help', '-v', '--version', '-c', '--commands', '-q', '--quiet', '--ansi', '--no-ansi']
- for debug you can use
-vv or --verbose
flags to get more details about the error - you can also pass values to flags
--flag=value
or-f=value
:star: Add command alias
- you can add an alias to a command with the alias method
->alias(string $alias)
:star: Define command help
- you can add help instructions to a command using the help method
->help(array $help)
- command help can be displayed using the
-h
or--help
flags - help array must be an array of sub commands, options and flags with their descriptions
:star: Group commands
- you can group commands using the
group()
method
:star: Class commands
- class commands are very helpful for big commands
- first you need to create an
app/Commands
folder. - you can also move your commands definitions file
commands.php
toapp
folder to clean up things. - don't forget to autoload your commands with composer
psr-4{ "App\\" : "app" }
-
now you need add commands paths and namespaces to conso to allow the build in command (command) to automatically create commands for you.
- to create a class command run
php conso command:make {command name}
- for example lets create a test class command
php conso command:make test
-
this will generate a
Test
command class like this: -
now you need to register this command in your
commands.php
file: - by default
test
command will run theexecute
method if no sub command is provided - each sub command is a separate method
:star: Accessing app from commands :
-
from a callback command
- from a class command
:star: Commands namespace
- you can wrap commands in the same namespace with
namespace()
method which makes things cleaner
:star: Http support
- you can invoke conso from the browser or any http client just by passing commands to the input instance
:star: Compile your app to an executable shareable single .phar
file :
- you can use this feature from version
2.0
and above. - to compile your application and create a shareable
.phar
file use the built incompile
command. - run
php conso compile:init
to create aconso.json
build file.
-
this will generate a json file like follow:
-
your stub file should look something like this:
- now you can run
php conso compile
and you will get your package compiled to aphar
file.
- you can use
--no-shebang
flag to avoid adding shebang to yourphar
file (this is useful if you want to invoke yourphar
file fromhttp
)
:star: Testing helpers:
- you can use
Conso\Testing\TestCase
test helper class for testing which helps you to :- turn on testing mode for you (return results instead of outputing to STDOUT).
- disable ansi colors which is not needed when testing.
✨ Todo
- improve code quality.
✨ Contributing
Thank you for considering to contribute to Conso. All the contribution guidelines are mentioned Here.
💖 Support
If this project helped you reduce time to develop, you can give me a cup of coffee :) : Paypal.
✨ License
Conso is an open-source software licensed under the MIT license.