Fault.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /*
  3. * This file is part of the Supervisor package.
  4. *
  5. * (c) Márk Sági-Kazár <mark.sagikazar@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Supervisor\Exception;
  11. /**
  12. * Fault codes are taken from the source code, not the documentation
  13. * The most common ones are covered by the XML-RPC doc
  14. *
  15. * @link http://supervisord.org/api.html
  16. *
  17. * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
  18. */
  19. class Fault extends \Exception
  20. {
  21. /**
  22. * Fault responses
  23. */
  24. const UNKNOWN_METHOD = 1;
  25. const INCORRECT_PARAMETERS = 2;
  26. const BAD_ARGUMENTS = 3;
  27. const SIGNATURE_UNSUPPORTED = 4;
  28. const SHUTDOWN_STATE = 6;
  29. const BAD_NAME = 10;
  30. const BAD_SIGNAL = 11;
  31. const NO_FILE = 20;
  32. const NOT_EXECUTABLE = 21;
  33. const FAILED = 30;
  34. const ABNORMAL_TERMINATION = 40;
  35. const SPAWN_ERROR = 50;
  36. const ALREADY_STARTED = 60;
  37. const NOT_RUNNING = 70;
  38. const SUCCESS = 80;
  39. const ALREADY_ADDED = 90;
  40. const STILL_RUNNING = 91;
  41. const CANT_REREAD = 92;
  42. /**
  43. * @var array
  44. */
  45. private static $exceptionMap = [
  46. 1 => 'Supervisor\Exception\Fault\UnknownMethod',
  47. 2 => 'Supervisor\Exception\Fault\IncorrectParameters',
  48. 3 => 'Supervisor\Exception\Fault\BadArguments',
  49. 4 => 'Supervisor\Exception\Fault\SignatureUnsupported',
  50. 6 => 'Supervisor\Exception\Fault\ShutdownState',
  51. 10 => 'Supervisor\Exception\Fault\BadName',
  52. 11 => 'Supervisor\Exception\Fault\BadSignal',
  53. 20 => 'Supervisor\Exception\Fault\NoFile',
  54. 21 => 'Supervisor\Exception\Fault\NotExecutable',
  55. 30 => 'Supervisor\Exception\Fault\Failed',
  56. 40 => 'Supervisor\Exception\Fault\AbnormalTermination',
  57. 50 => 'Supervisor\Exception\Fault\SpawnError',
  58. 60 => 'Supervisor\Exception\Fault\AlreadyStarted',
  59. 70 => 'Supervisor\Exception\Fault\NotRunning',
  60. 80 => 'Supervisor\Exception\Fault\Success',
  61. 90 => 'Supervisor\Exception\Fault\AlreadyAdded',
  62. 91 => 'Supervisor\Exception\Fault\StillRunning',
  63. 92 => 'Supervisor\Exception\Fault\CantReread',
  64. ];
  65. /**
  66. * Creates a new Fault
  67. *
  68. * If there is a mach for the fault code in the exception map then the matched exception will be returned
  69. *
  70. * @param string $faultString
  71. * @param integer $faultCode
  72. *
  73. * @return self
  74. */
  75. public static function create($faultString, $faultCode)
  76. {
  77. if (!isset(self::$exceptionMap[$faultCode])) {
  78. return new self($faultString, $faultCode);
  79. }
  80. return new self::$exceptionMap[$faultCode]($faultString, $faultCode);
  81. }
  82. }