]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - Zend/Oauth/Token/Access.php
Release 6.5.0
[Github/sugarcrm.git] / Zend / Oauth / Token / Access.php
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_Oauth
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
20  */
21
22 /** Zend_Oauth_Token */
23 require_once 'Zend/Oauth/Token.php';
24
25 /** Zend_Oauth_Http */
26 require_once 'Zend/Oauth/Http.php';
27
28 /** Zend_Uri_Http */
29 require_once 'Zend/Uri/Http.php';
30
31 /** Zend_Oauth_Client */
32 require_once 'Zend/Oauth/Client.php';
33
34 /**
35  * @category   Zend
36  * @package    Zend_Oauth
37  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38  * @license    http://framework.zend.com/license/new-bsd     New BSD License
39  */
40 class Zend_Oauth_Token_Access extends Zend_Oauth_Token
41 {
42     /**
43      * Cast to HTTP header
44      * 
45      * @param  string $url 
46      * @param  Zend_Oauth_Config_ConfigInterface $config 
47      * @param  null|array $customParams 
48      * @param  null|string $realm 
49      * @return string
50      */
51     public function toHeader(
52         $url, Zend_Oauth_Config_ConfigInterface $config, array $customParams = null, $realm = null
53     ) {
54         if (!Zend_Uri::check($url)) {
55             require_once 'Zend/Oauth/Exception.php';
56             throw new Zend_Oauth_Exception(
57                 '\'' . $url . '\' is not a valid URI'
58             );
59         }
60         $params = $this->_httpUtility->assembleParams($url, $config, $customParams);
61         return $this->_httpUtility->toAuthorizationHeader($params, $realm);
62     }
63
64     /**
65      * Cast to HTTP query string
66      * 
67      * @param  mixed $url 
68      * @param  Zend_Oauth_Config_ConfigInterface $config 
69      * @param  null|array $params 
70      * @return string
71      */
72     public function toQueryString($url, Zend_Oauth_Config_ConfigInterface $config, array $params = null)
73     {
74         if (!Zend_Uri::check($url)) {
75             require_once 'Zend/Oauth/Exception.php';
76             throw new Zend_Oauth_Exception(
77                 '\'' . $url . '\' is not a valid URI'
78             );
79         }
80         $params = $this->_httpUtility->assembleParams($url, $config, $params);
81         return $this->_httpUtility->toEncodedQueryString($params);
82     }
83
84     /**
85      * Get OAuth client
86      * 
87      * @param  array $oauthOptions 
88      * @param  null|string $uri 
89      * @param  null|array|Zend_Config $config 
90      * @param  bool $excludeCustomParamsFromHeader 
91      * @return Zend_Oauth_Client
92      */
93     public function getHttpClient(array $oauthOptions, $uri = null, $config = null, $excludeCustomParamsFromHeader = true)
94     {
95         $client = new Zend_Oauth_Client($oauthOptions, $uri, $config, $excludeCustomParamsFromHeader);
96         $client->setToken($this);
97         return $client;
98     }
99 }