PageRenderTime 13ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/zf/library/Zend/Service/DeveloperGarden/Credential.php

http://github.com/eryx/php-framework-benchmark
PHP | 186 lines | 78 code | 17 blank | 91 comment | 10 complexity | 85107f3c9a235266ff05b4adffc64472 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause
  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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: Credential.php 23775 2011-03-01 17:25:24Z ralph $
 21 */
 22
 23/**
 24 * @category   Zend
 25 * @package    Zend_Service
 26 * @subpackage DeveloperGarden
 27 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 28 * @author     Marco Kaiser
 29 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 30 */
 31class Zend_Service_DeveloperGarden_Credential
 32{
 33    /**
 34     * Service Auth Username
 35     *
 36     * @var string
 37     */
 38    protected $_username = null;
 39
 40    /**
 41     * Service Password
 42     *
 43     * @var string
 44     */
 45    protected $_password = null;
 46
 47    /**
 48     * Service Realm - default t-online.de
 49     *
 50     * @var string
 51     */
 52    protected $_realm = 't-online.de';
 53
 54    /**
 55     * constructor to init the internal data
 56     *
 57     * @param string $username
 58     * @param string $password
 59     * @param string $realm
 60     * @return Zend_Service_DeveloperGarden_Credential
 61     */
 62    public function __construct($username = null, $password = null, $realm = null)
 63    {
 64        if (!empty($username)) {
 65            $this->setUsername($username);
 66        }
 67        if (!empty($password)) {
 68            $this->setPassword($password);
 69        }
 70        if (!empty($realm)) {
 71            $this->setRealm($realm);
 72        }
 73    }
 74
 75    /**
 76     * split the password into an array
 77     *
 78     * @param string $password
 79     * @throws Zend_Service_DeveloperGarden_Client_Exception
 80     * @return Zend_Service_DeveloperGarden_Client_ClientAbstract
 81     */
 82    public function setPassword($password = null)
 83    {
 84        if (empty($password)) {
 85            require_once 'Zend/Service/DeveloperGarden/Client/Exception.php';
 86            throw new Zend_Service_DeveloperGarden_Client_Exception('Empty password not permitted.');
 87        }
 88
 89        if (!is_string($password)) {
 90            require_once 'Zend/Service/DeveloperGarden/Client/Exception.php';
 91            throw new Zend_Service_DeveloperGarden_Client_Exception('Password must be a string.');
 92        }
 93
 94        $this->_password = $password;
 95        return $this;
 96    }
 97
 98    /**
 99     * returns the current configured password
100     *
101     * @return string
102     */
103    public function getPassword()
104    {
105        return $this->_password;
106    }
107
108    /**
109     * set the new login
110     *
111     * @param string $username
112     * @throws Zend_Service_DeveloperGarden_Client_Exception
113     * @return Zend_Service_DeveloperGarden_Client_ClientAbstract
114     */
115    public function setUsername($username = null)
116    {
117        if (empty($username)) {
118            require_once 'Zend/Service/DeveloperGarden/Client/Exception.php';
119            throw new Zend_Service_DeveloperGarden_Client_Exception('Empty username not permitted.');
120        }
121
122        if (!is_string($username)) {
123            require_once 'Zend/Service/DeveloperGarden/Client/Exception.php';
124            throw new Zend_Service_DeveloperGarden_Client_Exception('Username must be a string.');
125        }
126
127        $this->_username = $username;
128        return $this;
129    }
130
131    /**
132     * returns the username
133     *
134     * if $withRealm == true we combine username and realm like
135     * username@realm
136     *
137     * @param bool $withRealm
138     * @return string|null
139     */
140    public function getUsername($withRealm = false)
141    {
142        $retValue = $this->_username;
143        if ($withRealm) {
144            $retValue = sprintf(
145                '%s@%s',
146                $this->_username,
147                $this->_realm
148            );
149        }
150        return $retValue;
151    }
152
153    /**
154     * set the new realm
155     *
156     * @param string $realm
157     * @throws Zend_Service_DeveloperGarden_Client_Exception
158     * @return Zend_Service_DeveloperGarden_Client_ClientAbstract
159     */
160    public function setRealm($realm = null)
161    {
162        if (empty($realm)) {
163            require_once 'Zend/Service/DeveloperGarden/Client/Exception.php';
164            throw new Zend_Service_DeveloperGarden_Client_Exception('Empty realm not permitted.');
165        }
166
167        if (!is_string($realm)) {
168            require_once 'Zend/Service/DeveloperGarden/Client/Exception.php';
169            throw new Zend_Service_DeveloperGarden_Client_Exception('Realm must be a string.');
170        }
171
172        $this->_realm = $realm;
173        return $this;
174    }
175
176    /**
177     * returns the realm
178     *
179     * @return string|null
180     */
181    public function getRealm()
182    {
183        return $this->_realm;
184    }
185}
186