PageRenderTime 614ms CodeModel.GetById 18ms RepoModel.GetById 5ms app.codeStats 0ms

/wp-content/plugins/backwpup/sdk/WindowsAzure/Common/Internal/Atom/AtomLink.php

https://bitbucket.org/cesarmedrano/cesarmedrano
PHP | 343 lines | 129 code | 39 blank | 175 comment | 9 complexity | ed86b31ffa846e5c4add35d802ac15d9 MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package WindowsAzure\Common\Internal\Atom
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/WindowsAzure/azure-sdk-for-php
  22. */
  23. namespace WindowsAzure\Common\Internal\Atom;
  24. use WindowsAzure\Common\Internal\Resources;
  25. use WindowsAzure\Common\Internal\Utilities;
  26. use WindowsAzure\Common\Internal\Validate;
  27. /**
  28. * This link defines a reference from an entry or feed to a Web resource.
  29. *
  30. * @category Microsoft
  31. * @package WindowsAzure\Common\Internal\Atom
  32. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  33. * @copyright 2012 Microsoft Corporation
  34. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  35. * @version Release: @package_version@
  36. * @link https://github.com/WindowsAzure/azure-sdk-for-php
  37. */
  38. class AtomLink extends AtomBase
  39. {
  40. /**
  41. * The undefined content.
  42. *
  43. * @var string
  44. */
  45. protected $undefinedContent;
  46. /**
  47. * The HREF of the link.
  48. *
  49. * @var string
  50. */
  51. protected $href;
  52. /**
  53. * The rel attribute of the link.
  54. *
  55. * @var string
  56. */
  57. protected $rel;
  58. /**
  59. * The media type of the link.
  60. *
  61. * @var string
  62. */
  63. protected $type;
  64. /**
  65. * The language of HREF.
  66. *
  67. * @var string
  68. */
  69. protected $hreflang;
  70. /**
  71. * The titile of the link.
  72. *
  73. * @var string
  74. */
  75. protected $title;
  76. /**
  77. * The length of the link.
  78. *
  79. * @var integer
  80. */
  81. protected $length;
  82. /**
  83. * Creates a AtomLink instance with specified text.
  84. */
  85. public function __construct()
  86. {
  87. }
  88. /**
  89. * Parse an ATOM Link xml.
  90. *
  91. * @param string $xmlString an XML based string of ATOM Link.
  92. *
  93. * @return none
  94. */
  95. public function parseXml($xmlString)
  96. {
  97. Validate::notNull($xmlString, 'xmlString');
  98. Validate::isString($xmlString, 'xmlString');
  99. $atomLinkXml = simplexml_load_string($xmlString);
  100. $attributes = $atomLinkXml->attributes();
  101. if (!empty($attributes['href'])) {
  102. $this->href = (string)$attributes['href'];
  103. }
  104. if (!empty($attributes['rel'])) {
  105. $this->rel = (string)$attributes['rel'];
  106. }
  107. if (!empty($attributes['type'])) {
  108. $this->type = (string)$attributes['type'];
  109. }
  110. if (!empty($attributes['hreflang'])) {
  111. $this->hreflang = (string)$attributes['hreflang'];
  112. }
  113. if (!empty($attributes['title'])) {
  114. $this->title = (string)$attributes['title'];
  115. }
  116. if (!empty($attributes['length'])) {
  117. $this->length = (integer)$attributes['length'];
  118. }
  119. $undefinedContent = (string)$atomLinkXml;
  120. if (empty($undefinedContent)) {
  121. $this->undefinedContent = null;
  122. } else {
  123. $this->undefinedContent = (string)$atomLinkXml;
  124. }
  125. }
  126. /**
  127. * Gets the href of the link.
  128. *
  129. * @return string
  130. */
  131. public function getHref()
  132. {
  133. return $this->href;
  134. }
  135. /**
  136. * Sets the href of the link.
  137. *
  138. * @param string $href The href of the link.
  139. *
  140. * @return none
  141. */
  142. public function setHref($href)
  143. {
  144. $this->href = $href;
  145. }
  146. /**
  147. * Gets the rel of the atomLink.
  148. *
  149. * @return string
  150. */
  151. public function getRel()
  152. {
  153. return $this->rel;
  154. }
  155. /**
  156. * Sets the rel of the link.
  157. *
  158. * @param string $rel The rel of the atomLink.
  159. *
  160. * @return none
  161. */
  162. public function setRel($rel)
  163. {
  164. $this->rel = $rel;
  165. }
  166. /**
  167. * Gets the type of the link.
  168. *
  169. * @return string
  170. */
  171. public function getType()
  172. {
  173. return $this->type;
  174. }
  175. /**
  176. * Sets the type of the link.
  177. *
  178. * @param string $type The type of the link.
  179. *
  180. * @return none
  181. */
  182. public function setType($type)
  183. {
  184. $this->type = $type;
  185. }
  186. /**
  187. * Gets the language of the href.
  188. *
  189. * @return string
  190. */
  191. public function getHrefLang()
  192. {
  193. return $this->hrefLang;
  194. }
  195. /**
  196. * Sets the language of the href.
  197. *
  198. * @param string $hrefLang The language of the href.
  199. *
  200. * @return none
  201. */
  202. public function setHrefLang($hrefLang)
  203. {
  204. $this->hrefLang = $hrefLang;
  205. }
  206. /**
  207. * Gets the title of the link.
  208. *
  209. * @return string
  210. */
  211. public function getTitle()
  212. {
  213. return $this->title;
  214. }
  215. /**
  216. * Sets the title of the link.
  217. *
  218. * @param string $title The title of the link.
  219. *
  220. * @return none
  221. */
  222. public function setTitle($title)
  223. {
  224. $this->title = $title;
  225. }
  226. /**
  227. * Gets the length of the link.
  228. *
  229. * @return string
  230. */
  231. public function getLength()
  232. {
  233. return $this->length;
  234. }
  235. /**
  236. * Sets the length of the link.
  237. *
  238. * @param string $length The length of the link.
  239. *
  240. * @return none
  241. */
  242. public function setLength($length)
  243. {
  244. $this->length = $length;
  245. }
  246. /**
  247. * Gets the undefined content.
  248. *
  249. * @return string
  250. */
  251. public function getUndefinedContent()
  252. {
  253. return $this->undefinedContent;
  254. }
  255. /**
  256. * Sets the undefined content.
  257. *
  258. * @param string $undefinedContent The undefined content.
  259. *
  260. * @return none
  261. */
  262. public function setUndefinedContent($undefinedContent)
  263. {
  264. $this->undefinedContent = $undefinedContent;
  265. }
  266. /**
  267. * Writes an XML representing the ATOM link item.
  268. *
  269. * @param \XMLWriter $xmlWriter The xml writer.
  270. *
  271. * @return none
  272. */
  273. public function writeXml($xmlWriter)
  274. {
  275. Validate::notNull($xmlWriter, 'xmlWriter');
  276. $xmlWriter->startElementNS(
  277. 'atom',
  278. Resources::LINK,
  279. Resources::ATOM_NAMESPACE
  280. );
  281. $this->writeInnerXml($xmlWriter);
  282. $xmlWriter->endElement();
  283. }
  284. /**
  285. * Writes the inner XML representing the ATOM link item.
  286. *
  287. * @param \XMLWriter $xmlWriter The xml writer.
  288. *
  289. * @return none
  290. */
  291. public function writeInnerXml($xmlWriter)
  292. {
  293. Validate::notNull($xmlWriter, 'xmlWriter');
  294. $this->writeOptionalAttribute($xmlWriter, 'href', $this->href);
  295. $this->writeOptionalAttribute($xmlWriter, 'rel', $this->rel);
  296. $this->writeOptionalAttribute($xmlWriter, 'type', $this->type);
  297. $this->writeOptionalAttribute($xmlWriter, 'hreflang', $this->hreflang);
  298. $this->writeOptionalAttribute($xmlWriter, 'title', $this->title);
  299. $this->writeOptionalAttribute($xmlWriter, 'length', $this->length);
  300. if (!empty($this->undefinedContent)) {
  301. $xmlWriter->writeRaw($this->undefinedContent);
  302. }
  303. }
  304. }