File indexing completed on 2024-12-22 05:36:53

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_Oauth
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 /** Zend_Oauth_Token */
0023 // require_once 'Zend/Oauth/Token.php';
0024 
0025 /**
0026  * @category   Zend
0027  * @package    Zend_Oauth
0028  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0029  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0030  */
0031 class Zend_Oauth_Token_AuthorizedRequest extends Zend_Oauth_Token
0032 {
0033     /**
0034      * @var array
0035      */
0036     protected $_data = array();
0037 
0038     /**
0039      * Constructor
0040      *
0041      * @param  null|array $data
0042      * @param  null|Zend_Oauth_Http_Utility $utility
0043      * @return void
0044      */
0045     public function __construct(array $data = null, Zend_Oauth_Http_Utility $utility = null)
0046     {
0047         if ($data !== null) {
0048             $this->_data = $data;
0049             $params = $this->_parseData();
0050             if (count($params) > 0) {
0051                 $this->setParams($params);
0052             }
0053         }
0054         if ($utility !== null) {
0055             $this->_httpUtility = $utility;
0056         } else {
0057             $this->_httpUtility = new Zend_Oauth_Http_Utility;
0058         }
0059     }
0060 
0061     /**
0062      * Retrieve token data
0063      *
0064      * @return array
0065      */
0066     public function getData()
0067     {
0068         return $this->_data;
0069     }
0070 
0071     /**
0072      * Indicate if token is valid
0073      *
0074      * @return bool
0075      */
0076     public function isValid()
0077     {
0078         if (isset($this->_params[self::TOKEN_PARAM_KEY])
0079             && !empty($this->_params[self::TOKEN_PARAM_KEY])
0080         ) {
0081             return true;
0082         }
0083         return false;
0084     }
0085 
0086     /**
0087      * Parse string data into array
0088      *
0089      * @return array
0090      */
0091     protected function _parseData()
0092     {
0093         $params = array();
0094         if (empty($this->_data)) {
0095             return;
0096         }
0097         foreach ($this->_data as $key => $value) {
0098             $params[rawurldecode($key)] = rawurldecode($value);
0099         }
0100         return $params;
0101     }
0102 }