web/Zend/Auth/Result.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     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-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: Result.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 
       
    23 /**
       
    24  * @category   Zend
       
    25  * @package    Zend_Auth
       
    26  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    27  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    28  */
       
    29 class Zend_Auth_Result
       
    30 {
       
    31     /**
       
    32      * General Failure
       
    33      */
       
    34     const FAILURE                        =  0;
       
    35 
       
    36     /**
       
    37      * Failure due to identity not being found.
       
    38      */
       
    39     const FAILURE_IDENTITY_NOT_FOUND     = -1;
       
    40 
       
    41     /**
       
    42      * Failure due to identity being ambiguous.
       
    43      */
       
    44     const FAILURE_IDENTITY_AMBIGUOUS     = -2;
       
    45 
       
    46     /**
       
    47      * Failure due to invalid credential being supplied.
       
    48      */
       
    49     const FAILURE_CREDENTIAL_INVALID     = -3;
       
    50 
       
    51     /**
       
    52      * Failure due to uncategorized reasons.
       
    53      */
       
    54     const FAILURE_UNCATEGORIZED          = -4;
       
    55 
       
    56     /**
       
    57      * Authentication success.
       
    58      */
       
    59     const SUCCESS                        =  1;
       
    60 
       
    61     /**
       
    62      * Authentication result code
       
    63      *
       
    64      * @var int
       
    65      */
       
    66     protected $_code;
       
    67 
       
    68     /**
       
    69      * The identity used in the authentication attempt
       
    70      *
       
    71      * @var mixed
       
    72      */
       
    73     protected $_identity;
       
    74 
       
    75     /**
       
    76      * An array of string reasons why the authentication attempt was unsuccessful
       
    77      *
       
    78      * If authentication was successful, this should be an empty array.
       
    79      *
       
    80      * @var array
       
    81      */
       
    82     protected $_messages;
       
    83 
       
    84     /**
       
    85      * Sets the result code, identity, and failure messages
       
    86      *
       
    87      * @param  int     $code
       
    88      * @param  mixed   $identity
       
    89      * @param  array   $messages
       
    90      * @return void
       
    91      */
       
    92     public function __construct($code, $identity, array $messages = array())
       
    93     {
       
    94         $code = (int) $code;
       
    95 
       
    96         if ($code < self::FAILURE_UNCATEGORIZED) {
       
    97             $code = self::FAILURE;
       
    98         } elseif ($code > self::SUCCESS ) {
       
    99             $code = 1;
       
   100         }
       
   101 
       
   102         $this->_code     = $code;
       
   103         $this->_identity = $identity;
       
   104         $this->_messages = $messages;
       
   105     }
       
   106 
       
   107     /**
       
   108      * Returns whether the result represents a successful authentication attempt
       
   109      *
       
   110      * @return boolean
       
   111      */
       
   112     public function isValid()
       
   113     {
       
   114         return ($this->_code > 0) ? true : false;
       
   115     }
       
   116 
       
   117     /**
       
   118      * getCode() - Get the result code for this authentication attempt
       
   119      *
       
   120      * @return int
       
   121      */
       
   122     public function getCode()
       
   123     {
       
   124         return $this->_code;
       
   125     }
       
   126 
       
   127     /**
       
   128      * Returns the identity used in the authentication attempt
       
   129      *
       
   130      * @return mixed
       
   131      */
       
   132     public function getIdentity()
       
   133     {
       
   134         return $this->_identity;
       
   135     }
       
   136 
       
   137     /**
       
   138      * Returns an array of string reasons why the authentication attempt was unsuccessful
       
   139      *
       
   140      * If authentication was successful, this method returns an empty array.
       
   141      *
       
   142      * @return array
       
   143      */
       
   144     public function getMessages()
       
   145     {
       
   146         return $this->_messages;
       
   147     }
       
   148 }