master

laravel/framework

Last updated at: 29/12/2023 09:21

ProcessResult.php

TLDR

This file defines the ProcessResult interface in the Illuminate\Contracts\Process namespace. The interface provides methods for retrieving information about a process result, such as the command executed, the exit code, the output, and error output. It also provides methods for determining if the process was successful or failed, and for throwing an exception based on the process result.

Methods

command()

Returns the original command executed by the process.

successful()

Determines if the process was successful. Returns true if the process was successful, false otherwise.

failed()

Determines if the process failed. Returns true if the process failed, false otherwise.

exitCode()

Returns the exit code of the process. If the process is still running or has not yet been started, null is returned.

output()

Returns the standard output of the process.

errorOutput()

Returns the error output of the process.

throw(callable $callback = null)

Throws an exception if the process failed. An optional callback can be provided to customize the exception.

throwIf(bool $condition, callable $callback = null)

Throws an exception if the process failed and the given condition is true. An optional callback can be provided to customize the exception.

<?php

namespace Illuminate\Contracts\Process;

interface ProcessResult
{
    /**
     * Get the original command executed by the process.
     *
     * @return string
     */
    public function command();

    /**
     * Determine if the process was successful.
     *
     * @return bool
     */
    public function successful();

    /**
     * Determine if the process failed.
     *
     * @return bool
     */
    public function failed();

    /**
     * Get the exit code of the process.
     *
     * @return int|null
     */
    public function exitCode();

    /**
     * Get the standard output of the process.
     *
     * @return string
     */
    public function output();

    /**
     * Get the error output of the process.
     *
     * @return string
     */
    public function errorOutput();

    /**
     * Throw an exception if the process failed.
     *
     * @param  callable|null  $callback
     * @return $this
     */
    public function throw(callable $callback = null);

    /**
     * Throw an exception if the process failed and the given condition is true.
     *
     * @param  bool  $condition
     * @param  callable|null  $callback
     * @return $this
     */
    public function throwIf(bool $condition, callable $callback = null);
}