ChainedState.php

The Provision_ChainedState class.

Classes

Namesort descending Description
Provision_ChainedState A base class for the service and file handling classes that implements chaining of methods.

File

Provision/ChainedState.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * The Provision_ChainedState class.
  5. */
  6. /**
  7. * A base class for the service and file handling classes that implements
  8. * chaining of methods.
  9. */
  10. class Provision_ChainedState {
  11. protected $last_status;
  12. protected $tokens;
  13. /**
  14. * Clear internal state
  15. */
  16. protected function _clear_state() {
  17. $this->last_status = NULL;
  18. $this->tokens = NULL;
  19. }
  20. /**
  21. * Return the status of the last operation.
  22. *
  23. * @return
  24. * TRUE or FALSE for success or failure; NULL if there was not a previous
  25. * operation.
  26. */
  27. function status() {
  28. return $this->last_status;
  29. }
  30. /**
  31. * Log a notice into the logging system, if the last operation completed
  32. * succesfully.
  33. *
  34. * @param $message
  35. * The message to log, a string.
  36. */
  37. function succeed($message) {
  38. if ($this->last_status === TRUE) {
  39. drush_log(dt($message, $this->tokens), 'success');
  40. }
  41. return $this;
  42. }
  43. /**
  44. * Log a notice into the logging system, if the last operation did not
  45. * complete succesfully.
  46. *
  47. * @param $message
  48. * Log this as a error to the logging system, if the $error_codes parameter
  49. * has been set, otherwise, log this as a warning. If the operation
  50. * specifies an additional reason for the operation failing, it will be
  51. * appended to this message.
  52. *
  53. * @param error_codes
  54. * Generate these system level errors using the provision error bitmasks.
  55. */
  56. function fail($message, $error_codes = NULL) {
  57. if (!empty($this->tokens['@reason'])) {
  58. $message .= ' (@reason)';
  59. }
  60. if ($this->last_status === FALSE) {
  61. if (is_null($error_codes)) {
  62. // Trigger a warning
  63. drush_log(dt($message, $this->tokens), 'warning');
  64. }
  65. else {
  66. // Trigger a sysem halting error
  67. drush_set_error($error_codes, dt($message, $this->tokens));
  68. }
  69. }
  70. return $this;
  71. }
  72. }