PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Oauth2/Config.php

https://github.com/A-Shevchenko/oauth-2---facebook---zend-framework-components
PHP | 350 lines | 138 code | 32 blank | 180 comment | 3 complexity | f51653739546d2a719cd03123bec5f73 MD5 | raw file
  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_Oauth2
  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: Config.php 20232 2010-01-12 17:56:33Z matthew $
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Oauth2
  24. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Oauth2_Config
  28. {
  29. /**
  30. * The URL root to append default OAuth endpoint paths.
  31. *
  32. * @var string
  33. */
  34. protected $_siteUrl = null;
  35. /**
  36. * This optional value is used to define where the user is redirected to
  37. *
  38. * @var string
  39. */
  40. protected $_callbackUrl = null;
  41. /**
  42. * An OAuth application's client id
  43. *
  44. * @var string
  45. */
  46. protected $_clientId = null;
  47. /**
  48. * An OAuth application's client secret
  49. *
  50. * @var string
  51. */
  52. protected $_clientSecret = null;
  53. /**
  54. *
  55. * @var string
  56. */
  57. protected $_type = 'web_server';
  58. /**
  59. * the secret type
  60. *
  61. * @var string
  62. */
  63. protected $_secretType = null;
  64. /**
  65. *
  66. * @var string
  67. */
  68. protected $_state = null;
  69. /**
  70. *
  71. * @var string
  72. */
  73. protected $_immediate = null;
  74. /**
  75. * rights that the application wants to get from website, can be string (single) or array (multiple)
  76. *
  77. * @var string|array
  78. */
  79. protected $_requestedRights = null;
  80. /**
  81. * Constructor; create a new object with an optional array|Zend_Config
  82. * instance containing initialising options.
  83. *
  84. * @param array|Zend_Config $options
  85. * @return void
  86. */
  87. public function __construct($options = null)
  88. {
  89. if (!is_null($options)) {
  90. if ($options instanceof Zend_Config) {
  91. $options = $options->toArray();
  92. }
  93. $this->setOptions($options);
  94. }
  95. }
  96. /**
  97. * Parse option array or Zend_Config instance and setup options using their
  98. * relevant mutators.
  99. *
  100. * @param array|Zend_Config $options
  101. * @return Zend_Oauth_Config
  102. */
  103. public function setOptions(array $options)
  104. {
  105. foreach ($options as $key => $value) {
  106. switch ($key) {
  107. case 'siteUrl':
  108. $this->setSiteUrl($value);
  109. break;
  110. case 'callbackUrl':
  111. $this->setCallbackUrl($value);
  112. break;
  113. case 'clientId':
  114. $this->setClientId($value);
  115. break;
  116. case 'clientSecret':
  117. $this->setClientSecret($value);
  118. break;
  119. case 'type':
  120. $this->setType($value);
  121. break;
  122. case 'secretType':
  123. $this->setSecretType($value);
  124. break;
  125. case 'state':
  126. $this->setState($value);
  127. break;
  128. case 'immediate':
  129. $this->setImmediate($value);
  130. break;
  131. case 'requestedRights':
  132. $this->setRequestedRights($value);
  133. break;
  134. }
  135. }
  136. return $this;
  137. }
  138. /**
  139. * Set site url
  140. *
  141. * @param string $key
  142. * @return Zend_Oauth2_Config
  143. */
  144. public function setSiteUrl($siteUrl)
  145. {
  146. $this->_siteUrl = $siteUrl;
  147. return $this;
  148. }
  149. /**
  150. * Get site url
  151. *
  152. * @return string
  153. */
  154. public function getSiteUrl()
  155. {
  156. return $this->_siteUrl;
  157. }
  158. /**
  159. * Set callback url
  160. *
  161. * @param string $callbackUrl
  162. * @return Zend_Oauth2_Config
  163. */
  164. public function setCallbackUrl($callbackUrl)
  165. {
  166. $this->_callbackUrl = $callbackUrl;
  167. return $this;
  168. }
  169. /**
  170. * Get callback url
  171. *
  172. * @return string
  173. */
  174. public function getCallbackUrl()
  175. {
  176. return $this->_callbackUrl;
  177. }
  178. /**
  179. * Set client id
  180. *
  181. * @param string $id
  182. * @return Zend_Oauth2_Config
  183. */
  184. public function setClientId($clientId)
  185. {
  186. $this->_clientId = $clientId;
  187. return $this;
  188. }
  189. /**
  190. * Get client id
  191. *
  192. * @return string
  193. */
  194. public function getClientId()
  195. {
  196. return $this->_clientId;
  197. }
  198. /**
  199. * Set client secret
  200. *
  201. * @param string $id
  202. * @return Zend_Oauth2_Config
  203. */
  204. public function setClientSecret($clientSecret)
  205. {
  206. $this->_clientSecret = $clientSecret;
  207. return $this;
  208. }
  209. /**
  210. * Get client secret
  211. *
  212. * @return string
  213. */
  214. public function getClientSecret()
  215. {
  216. return $this->_clientSecret;
  217. }
  218. /**
  219. * Set type
  220. *
  221. * @param array rights
  222. * @return Zend_Oauth2_Config
  223. */
  224. public function setType($type)
  225. {
  226. $this->_type = $type;
  227. return $this;
  228. }
  229. /**
  230. * Get type
  231. *
  232. * @return string
  233. */
  234. public function getType()
  235. {
  236. return $this->_type;
  237. }
  238. /**
  239. * Set secret type
  240. *
  241. * @param array rights
  242. * @return Zend_Oauth2_Config
  243. */
  244. public function setSecretType($secretType)
  245. {
  246. $this->_secretType = $secretType;
  247. return $this;
  248. }
  249. /**
  250. * Get secret type
  251. *
  252. * @return string
  253. */
  254. public function getSecretType()
  255. {
  256. return $this->_secretType;
  257. }
  258. /**
  259. * Set state
  260. *
  261. * @param string
  262. * @return Zend_Oauth2_Config
  263. */
  264. public function setState($state)
  265. {
  266. $this->_state = $state;
  267. return $this;
  268. }
  269. /**
  270. * Get state
  271. *
  272. * @return string
  273. */
  274. public function getState()
  275. {
  276. return $this->_state;
  277. }
  278. /**
  279. * Set immediate
  280. *
  281. * @param string
  282. * @return Zend_Oauth2_Config
  283. */
  284. public function setImmediate($immediate)
  285. {
  286. $this->_immediate = $immediate;
  287. return $this;
  288. }
  289. /**
  290. * Get immediate
  291. *
  292. * @return string
  293. */
  294. public function getImmediate()
  295. {
  296. return $this->_immediate;
  297. }
  298. /**
  299. * Set requested rights
  300. *
  301. * @param string|array
  302. * @return Zend_Oauth2_Config
  303. */
  304. public function setRequestedRights($rights)
  305. {
  306. $this->_requestedRights = $rights;
  307. return $this;
  308. }
  309. /**
  310. * Get requested rights
  311. *
  312. * @return string|array
  313. */
  314. public function getRequestedRights()
  315. {
  316. return $this->_requestedRights;
  317. }
  318. }