File indexing completed on 2024-05-12 06:02:17

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Auth
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 
0023 /**
0024  * @category   Zend
0025  * @package    Zend_Auth
0026  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0027  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0028  */
0029 class Zend_Auth_Result
0030 {
0031     /**
0032      * General Failure
0033      */
0034     const FAILURE                        =  0;
0035 
0036     /**
0037      * Failure due to identity not being found.
0038      */
0039     const FAILURE_IDENTITY_NOT_FOUND     = -1;
0040 
0041     /**
0042      * Failure due to identity being ambiguous.
0043      */
0044     const FAILURE_IDENTITY_AMBIGUOUS     = -2;
0045 
0046     /**
0047      * Failure due to invalid credential being supplied.
0048      */
0049     const FAILURE_CREDENTIAL_INVALID     = -3;
0050 
0051     /**
0052      * Failure due to uncategorized reasons.
0053      */
0054     const FAILURE_UNCATEGORIZED          = -4;
0055 
0056     /**
0057      * Authentication success.
0058      */
0059     const SUCCESS                        =  1;
0060 
0061     /**
0062      * Authentication result code
0063      *
0064      * @var int
0065      */
0066     protected $_code;
0067 
0068     /**
0069      * The identity used in the authentication attempt
0070      *
0071      * @var mixed
0072      */
0073     protected $_identity;
0074 
0075     /**
0076      * An array of string reasons why the authentication attempt was unsuccessful
0077      *
0078      * If authentication was successful, this should be an empty array.
0079      *
0080      * @var array
0081      */
0082     protected $_messages;
0083 
0084     /**
0085      * Sets the result code, identity, and failure messages
0086      *
0087      * @param int   $code
0088      * @param mixed $identity
0089      * @param array $messages
0090      */
0091     public function __construct($code, $identity, array $messages = array())
0092     {
0093         $code = (int) $code;
0094 
0095         if ($code < self::FAILURE_UNCATEGORIZED) {
0096             $code = self::FAILURE;
0097         } elseif ($code > self::SUCCESS ) {
0098             $code = 1;
0099         }
0100 
0101         $this->_code     = $code;
0102         $this->_identity = $identity;
0103         $this->_messages = $messages;
0104     }
0105 
0106     /**
0107      * Returns whether the result represents a successful authentication attempt
0108      *
0109      * @return boolean
0110      */
0111     public function isValid()
0112     {
0113         return ($this->_code > 0) ? true : false;
0114     }
0115 
0116     /**
0117      * getCode() - Get the result code for this authentication attempt
0118      *
0119      * @return int
0120      */
0121     public function getCode()
0122     {
0123         return $this->_code;
0124     }
0125 
0126     /**
0127      * Returns the identity used in the authentication attempt
0128      *
0129      * @return mixed
0130      */
0131     public function getIdentity()
0132     {
0133         return $this->_identity;
0134     }
0135 
0136     /**
0137      * Returns an array of string reasons why the authentication attempt was unsuccessful
0138      *
0139      * If authentication was successful, this method returns an empty array.
0140      *
0141      * @return array
0142      */
0143     public function getMessages()
0144     {
0145         return $this->_messages;
0146     }
0147 }