Skip to content

Instantly share code, notes, and snippets.

@tom--
Created May 22, 2017 15:30
Show Gist options
  • Save tom--/0806dc2878d0d80a5f71ca241972f8db to your computer and use it in GitHub Desktop.
Save tom--/0806dc2878d0d80a5f71ca241972f8db to your computer and use it in GitHub Desktop.
<?php
namespace v2\helpers;
use yii\helpers\Console;
/**
* Error code constane names, values, and descriptions are taken from
* OpenBSD's sysexits(3) man page http://man.openbsd.org/sysexits
*/
class ConsoleHelper extends Console
{
// The command completed successfully.
const EX_OK = 0;
// The command exited with an error code that says nothing about the error.
const EX_UNSPECIFIED = 1;
// The command was used incorrectly, e.g., with the wrong number of
// arguments, a bad flag, a bad syntax in a parameter, or whatever.
const EX_USAGE = 64;
// The input data was incorrect in some way. This should only be used for
// user's data and not system files.
const EX_DATAERR = 65;
// An input file (not a system file) did not exist or was not readable.
// This could also include errors like ``No message'' to a mailer (if it
// cared to catch it).
const EX_NOINPUT = 66;
// The user specified did not exist. This might be used for mail addresses
// or remote logins.
const EX_NOUSER = 67;
// The host specified did not exist. This is used in mail addresses or
// network requests.
const EX_NOHOST = 68;
// A service is unavailable. This can occur if a support program or file
// does not exist. This can also be used as a catchall message when
// something you wanted to do does not work, but you do not know why.
const EX_UNAVAILABLE = 69;
// An internal software error has been detected. This should be limited to
// non-operating system related errors as possible.
const EX_SOFTWARE = 70;
// An operating system error has been detected. This is intended to be
// used for such things as ``cannot fork'', ``cannot create pipe'', or the
// like. It includes things like getuid returning a user that does not
// exist in the passwd file.
const EX_OSERR = 71;
// Some system file (e.g., /etc/passwd, /var/run/utx.active, etc.) does not
// exist, cannot be opened, or has some sort of error (e.g., syntax error).
const EX_OSFILE = 72;
// A (user specified) output file cannot be created.
const EX_CANTCREAT = 73;
// An error occurred while doing I/O on some file.
const EX_IOERR = 74;
// Temporary failure, indicating something that is not really an error. In
// sendmail, this means that a mailer (e.g.) could not create a connection,
// and the request should be reattempted later.
const EX_TEMPFAIL = 75;
// The remote system returned something that was ``not possible'' during a
// protocol exchange.
const EX_PROTOCOL = 76;
// You did not have sufficient permission to perform the operation. This
// is not intended for file system problems, which should use EX_NOINPUT or
// EX_CANTCREAT, but rather for higher level permissions.
const EX_NOPERM = 77;
/**
* @const int Something was found in an unconfigured or misconfigured state.
*/
const EX_CONFIG = 78;
public static $exReasons = [
self::EX_OK => 'Success',
self::EX_UNSPECIFIED => "Unspecified error",
self::EX_USAGE => 'Incorrect usage, e.g. argument or option error',
self::EX_DATAERR => 'Error in input data',
self::EX_NOINPUT => 'Input file not found or unreadable',
self::EX_NOUSER => 'User not found',
self::EX_NOHOST => 'Host not found',
self::EX_UNAVAILABLE => 'A requied service is unavailable',
self::EX_SOFTWARE => 'Internal error',
self::EX_OSERR => 'Error making system call or using OS service',
self::EX_OSFILE => 'Error accessing system file',
self::EX_CANTCREAT => 'Cannot create output file',
self::EX_IOERR => 'I/O error',
self::EX_TEMPFAIL => 'Temporary failure',
self::EX_PROTOCOL => 'Error in remote service',
self::EX_NOPERM => 'Insufficient permissions',
self::EX_CONFIG => 'Configuration error',
];
/**
* Returns a short description of the given exit code.
* @param int $exitCode
* @return string
*/
public static function getReason($exitCode)
{
return isset(static::$exReasons[$exitCode])
? static::$exReasons[$exitCode]
: 'Unknown exit code';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment