Download the PHP package tivie/command without Composer

On this page you can find all versions of the php package tivie/command. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package command

Command =======
Build Status Latest Stable Version License

A cross-platform PHP utility library that harmonizes OS differences and executes external programs in a safer way

Introduction

Command is a small lightweight utility library that enables you to run external programs or commands in a safer way. It also harmonizes the differences between Windows and Unix environments, removing the need to create specific code for each platform.

Features

Installation

You can install it by cloning the git repository or using composer.

Git clone

git clone https://github.com/tivie/command.git

Composer

Add these lines to your composer.json:

or run the following command:

php composer.phar require tivie/command

Quick Usage guide

Simple example

Let's say we want to 'ping' google.com 3 times with 32bytes packets. With PHP we could do something like this:

We want, however, to make our command a little bit safer and escape our arguments.

This will work as expected in a GNU/Linux environment but will fail on Windows, since '-c' is an unrecognized flag and '-s' means something entirely different. The windows version would be :

If we want to ensure cross platform compatibility we will need to perform some kind of OS check and run the appropriate command based on that check:

While this works in most cases, with more complex commands (or command chains) you would be forced to repeat yourself a lot, with a lot of conditional checks.

With command library, you don't need to: it will do this work for you.

Command::run() returns a Result object that you can access to retrieve the result of the command.

Chaining commands

Command library supports command chaining

$results will be an array of Result objects.

You can also specify chaining conditions, similar to Linux's Chaining Operators.

RUN_REGARDLESS (';')

$cmd2 will be run regardless of the exitcode of $cmd1. Mimics the ';' chaining operator and is the default action.

RUN_IF_PREVIOUS_SUCCEEDS ('&&')

$cmd2 will only be run if $cmd1 is successful, that is, if it exits with exitcode 0. Mimics the '&&' chaining operator.

RUN_IF_PREVIOUS_FAILS ('||')

$cmd2 will only be run if $cmd1 is not successful, that is, if it exits with exitcode different than 0. Mimics the '||' chaining operator.

Complex command chains

That being said, you can create complex command chains. For instance:

This will:

  1. Run $cmd1
  2. If $cmd1 is successful then runs $cmd2
  3. If $cmd1 or $cmd2 fails it will run $cmd3
  4. Finally will run $cmd4

Piping

Command library supports 2 types of piping:

STDOUT to STDIN

Piping the standard output of one command to the next's standard input is easy. You just need to set the third argument of Chain::add() to true.

STDOUT to Arguments

You can also pass the STDOUT of previous command as an argument of the next command. The library will look for the special keyword (placeholder) '!PIPE!' in the command's argument key and values and replace them with the previous command's STDOUT. You will then need to pass true as the third argument in Chain::add() function, same as the above case.

Add support for other OS

IF you need to more specific OS checks, you can extend Detector class or create a new class that implements DetectorInterface. For further information, please read the php-os-detector documentation.

Example:

You don't need to create a new constant pertaining the new OS (you can use one of the pre existing families). If, however, you choose to do so, the new OS const value should be a unique number in the 2^n sequence plus the family the OS belongs to. In the example we chose 16th term (65536) plus the OS family (in this case, FAMILY_OTHER) which is 4.

Contribute

Feel free to contribute by forking or making suggestions.

Issue tracker: https://github.com/tivie/command/issues

Source code: https://github.com/tivie/command

Contributors

Tivie Sophie-OS

License

Command Library is released under Apache 2.0 license. For more information, please consult the LICENSE file in this repository or http://www.apache.org/licenses/LICENSE-2.0.txt.


All versions of command with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
tivie/php-os-detector Version 1.0.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tivie/command contains the following files

Loading the files please wait ....