jameslevi/atmos

Is a simple library for creating command line scripts in PHP.

v1.0.4 2021-05-02 08:10 UTC

This package is not auto-updated.

Last update: 2024-04-28 23:21:29 UTC


README

Is a simple library for creating command line scripts in PHP.

Features

  1. Create good looking PHP command line scripts.
  2. Built-in commands to make web development much easier.
  3. Easy integration with any PHP frameworks.

Installation

  1. You can install via composer.
composer require jameslevi/atmos
  1. Copy the atmos file from vendor/jameslevi/atmos to root directory.
  2. Create a new folder named commands in your root directory.

Getting Started

  1. Generate a new command file.
php atmos --make Test
  1. Open the generated PHP command file and write your code inside the main method.
/**
 * Method to be executed in the command line.
 *
 * @param  array $arguments
 * @return void
 */
protected function main(array $arguments)
{
    Console::log("Hello World!");  
}
  1. Test the command.
php atmos test

Call Specific Methods

  1. Add new protected method in your command file. For this example let's say "generate".
/**
 * This method will generate new file.
 *
 * @param  array $arguments
 * @return void
 */
protected function generate(array $arguments)
{
    Console::success("File is generated.");  
}
  1. Call this method using this command.
php atmos test:generate

Arguments

  1. You can use parameters supplied from the command line.
/**
 * This method will generate new file.
 *
 * @param  array $arguments
 * @return void
 */
protected function generate(array $arguments)
{
    Console::success($arguments[0] . " file is generated.");  
}
  1. You can call this method using this command.
php atmos test:generate newfile.php

Alias

You can set an alias for your command by setting a protected variable named "alias" in the command class.

protected $alias = "alternative";

The command below will execute generate method.

php atmos --alternative:generate

Console Messages

  1. Log - Print a simple message.
Console::log("Hello World!");
  1. Success - Print a success message.
Console::success("Congratulations! you made it!");
  1. Error - Print an error message.
Console::error("Something went wrong!");
  1. Info - Print an info message.
Console::info("You scored 30 points!");
  1. Warning - Print a warning message.
Console::warn("I told you not to go here!");

Call Multiple Commands

Very useful if you want to call multiple commands in just a single command. The order of execution of each command depends on the order of values in array.

Console::call(array(
    'composer -h',
    'php atmos -h'
));

Start Built-in PHP Server

You can now start PHP server using atmos commands. This command will start the server at port 8080.

php atmos --serve 8080

Contribution

For issues, concerns and suggestions, you can email James Crisostomo via nerdlabenterprise@gmail.com.

License

This package is an open-sourced software licensed under MIT License.