Download the PHP package ptlis/shell-command without Composer

On this page you can find all versions of the php package ptlis/shell-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 shell-command

ptlis/shell-command

A developer-friendly wrapper around execution of shell commands.

There were several goals that inspired the creation of this package:

Build Status codecov Latest Stable Version

Install

From the terminal:

Usage

The Builder

The package ships with a command builder, providing a simple and safe method to build commands.

The builder will attempt to determine your environment when constructed, you can override this by specifying an environment as the first argument:

Note: this builder is immutable - method calls must be chained and terminated with a call to like so:

Set Command

First we must provide the command to execute:

If the command is not locatable a is thrown.

Set Process Timeout

The timeout (in microseconds) sets how long the library will wait on a process before termination. Defaults to -1 which never forces termination.

If the process execution time exceeds this value a SIGTERM will be sent; if the process then doesn't terminate after a further 1 second wait then a SIGKILL is sent.

Set Poll Timeout

Set how long to wait (in microseconds) between polling the status of processes. Defaults to 1,000,000 (1 second).

Set Working Directory

You can set the working directory for a command:

Add Arguments

Add arguments to invoke the command with (all arguments are escaped):

Conditionally add, depending on the result of an expression:

Add several arguments:

Conditionally add, depending on the result of an expression:

Note: Escaped and raw arguments are added to the command in the order they're added to the builder. This accommodates commands that are sensitive to the order of arguments.

Add Raw Arguments

WARNING: Do not pass user-provided data to these methods! Malicious users could easily execute arbitrary shell commands.

Arguments can also be applied without escaping:

Conditionally, depending on the result of an expression:

Add several raw arguments:

Conditionally, depending on the result of an expression:

Note: Escaped and raw arguments are added to the command in the order they're added to the builder. This accommodates commands that are sensitive to the order of arguments.

Add Environment Variables

Environment variables can be set when running a command:

Conditionally, depending on the result of an expression:

Add several environment variables:

Conditionally, depending on the result of an expression:

Add Process Observers

Observers can be attached to spawned processes. In this case we add a simple logger:

Build the Command

One the builder has been configured, the command can be retrieved for execution:

Synchronous Execution

To run a command synchronously use the method. This returns an object implementing , encoding the result of the command.

When you need to re-run the same command multiple times you can simply invoke repeatedly; each call will run the command returning the result to your application.

The exit code & output of the command are available as methods on this object:

Asynchronous Execution

Commands can also be executed asynchronously, allowing your program to continue executing while waiting for the result.

Command::runAsynchronous

The method returns an object implementing the which provides methods to monitor the state of a process.

As with the synchronouse API, when you need to re-run the same command multiple times you can simply invoke repeatedly; each call will run the command returning the object representing the process to your application.

Process API

provides the methods required to monitor and manipulate the state and lifecycle of a process.

Check whether the process has completed:

Force the process to stop:

Wait for the process to stop (this blocks execution of your script, effectively making this synchronous):

Get the process id (throws a if the process has ended):

Read output from a stream:

Provide input (e.g. via STDIN):

Get the exit code (throws a if the process is still running):

Send a signal (SIGTERM or SIGKILL) to the process:

Get the string representation of the running command:

Process::getPromise

Monitoring of shell command execution can be wrapped in a ReactPHP Promise. This gives us a flexible execution model, allowing chaining (with Promise::then) and aggregation using Promise::all, Promise::some, Promise::race and their friends.

Building promise to execute a command can be done by calling the method from a instance. This returns an instance of :

The ReactPHP EventLoop component is used to periodically poll the running process to see if it has terminated yet; once it has the promise is either resolved or rejected depending on the exit code of the executed command.

The effect of this implementation is that once you've created your promises, chains and aggregates you must invoke :

This will block further execution until the promises are resolved/rejected.

Mocking

Mock implementations of the Command & Builder interfaces are provided to aid testing.

By type hinting against the interfaces, rather than the concrete implementations, these mocks can be injected & used to return pre-configured result objects.

Contributing

You can contribute by submitting an Issue to the issue tracker, improving the documentation or submitting a pull request. For pull requests i'd prefer that the code style and test coverage is maintained, but I am happy to work through any minor issues that may arise so that the request can be merged.

Known limitations


All versions of shell-command with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
ext-pcntl Version *
psr/log Version ^1.0
react/event-loop Version ^0.4.3
react/promise Version ^2.5
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 ptlis/shell-command contains the following files

Loading the files please wait ....