Result.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Auth
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Auth
  24. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Auth_Result
  28. {
  29. /**
  30. * General Failure
  31. */
  32. const FAILURE = 0;
  33. /**
  34. * Failure due to identity not being found.
  35. */
  36. const FAILURE_IDENTITY_NOT_FOUND = -1;
  37. /**
  38. * Failure due to identity being ambiguous.
  39. */
  40. const FAILURE_IDENTITY_AMBIGUOUS = -2;
  41. /**
  42. * Failure due to invalid credential being supplied.
  43. */
  44. const FAILURE_CREDENTIAL_INVALID = -3;
  45. /**
  46. * Failure due to uncategorized reasons.
  47. */
  48. const FAILURE_UNCATEGORIZED = -4;
  49. /**
  50. * Authentication success.
  51. */
  52. const SUCCESS = 1;
  53. /**
  54. * Authentication result code
  55. *
  56. * @var int
  57. */
  58. protected $_code;
  59. /**
  60. * The identity used in the authentication attempt
  61. *
  62. * @var mixed
  63. */
  64. protected $_identity;
  65. /**
  66. * An array of string reasons why the authentication attempt was unsuccessful
  67. *
  68. * If authentication was successful, this should be an empty array.
  69. *
  70. * @var array
  71. */
  72. protected $_messages;
  73. /**
  74. * Sets the result code, identity, and failure messages
  75. *
  76. * @param int $code
  77. * @param mixed $identity
  78. * @param array $messages
  79. */
  80. public function __construct($code, $identity, array $messages = array())
  81. {
  82. $code = (int) $code;
  83. if ($code < self::FAILURE_UNCATEGORIZED) {
  84. $code = self::FAILURE;
  85. } elseif ($code > self::SUCCESS ) {
  86. $code = 1;
  87. }
  88. $this->_code = $code;
  89. $this->_identity = $identity;
  90. $this->_messages = $messages;
  91. }
  92. /**
  93. * Returns whether the result represents a successful authentication attempt
  94. *
  95. * @return boolean
  96. */
  97. public function isValid()
  98. {
  99. return ($this->_code > 0) ? true : false;
  100. }
  101. /**
  102. * getCode() - Get the result code for this authentication attempt
  103. *
  104. * @return int
  105. */
  106. public function getCode()
  107. {
  108. return $this->_code;
  109. }
  110. /**
  111. * Returns the identity used in the authentication attempt
  112. *
  113. * @return mixed
  114. */
  115. public function getIdentity()
  116. {
  117. return $this->_identity;
  118. }
  119. /**
  120. * Returns an array of string reasons why the authentication attempt was unsuccessful
  121. *
  122. * If authentication was successful, this method returns an empty array.
  123. *
  124. * @return array
  125. */
  126. public function getMessages()
  127. {
  128. return $this->_messages;
  129. }
  130. }