web/lib/Zend/Service/DeveloperGarden/Response/ResponseAbstract.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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_Service
       
    17  * @subpackage DeveloperGarden
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: ResponseAbstract.php 20166 2010-01-09 19:00:17Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Service_DeveloperGarden_Response_Exception
       
    25  */
       
    26 require_once 'Zend/Service/DeveloperGarden/Response/Exception.php';
       
    27 
       
    28 /**
       
    29  * @category   Zend
       
    30  * @package    Zend_Service
       
    31  * @subpackage DeveloperGarden
       
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    33  * @author     Marco Kaiser
       
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    35  */
       
    36 abstract class Zend_Service_DeveloperGarden_Response_ResponseAbstract
       
    37 {
       
    38     /**
       
    39      * errorCode
       
    40      *
       
    41      * @var string
       
    42      */
       
    43     public $errorCode = null;
       
    44 
       
    45     /**
       
    46      * errorMessage
       
    47      *
       
    48      * @var string
       
    49      */
       
    50     public $errorMessage = null;
       
    51 
       
    52     /**
       
    53      * parse the token data and throws exceptions
       
    54      *
       
    55      * @throws Zend_Service_DeveloperGarden_Response_Exception
       
    56      * @return Zend_Service_DeveloperGarden_Response_ResponseAbstract
       
    57      */
       
    58     public function parse()
       
    59     {
       
    60         if ($this->hasError()) {
       
    61             throw new Zend_Service_DeveloperGarden_Response_Exception(
       
    62                 $this->getErrorMessage(),
       
    63                 $this->getErrorCode()
       
    64             );
       
    65         }
       
    66 
       
    67         return $this;
       
    68     }
       
    69 
       
    70     /**
       
    71      * returns the error code
       
    72      *
       
    73      * @return string|null
       
    74      */
       
    75     public function getErrorCode()
       
    76     {
       
    77         return $this->errorCode;
       
    78     }
       
    79 
       
    80     /**
       
    81      * returns the error message
       
    82      *
       
    83      * @return string
       
    84      */
       
    85     public function getErrorMessage()
       
    86     {
       
    87         return $this->errorMessage;
       
    88     }
       
    89 
       
    90     /**
       
    91      * returns true if the errorCode is not null and not 0000
       
    92      *
       
    93      * @return boolean
       
    94      */
       
    95     public function isValid()
       
    96     {
       
    97         return ($this->errorCode === null
       
    98              || $this->errorCode == '0000');
       
    99     }
       
   100 
       
   101     /**
       
   102      * returns true if we have a error situation
       
   103      *
       
   104      * @return boolean
       
   105      */
       
   106     public function hasError()
       
   107     {
       
   108         return ($this->errorCode !== null
       
   109                 && $this->errorCode != '0000');
       
   110     }
       
   111 }