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

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

https://bitbucket.org/cesarmedrano/cesarmedrano
PHP | 630 lines | 282 code | 71 blank | 277 comment | 19 complexity | 1df21dd0444c68392fbf0cc573040d0f 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\Utilities;
  25. use WindowsAzure\Common\Internal\Resources;
  26. use WindowsAzure\Common\Internal\Validate;
  27. /**
  28. * The Entry class of ATOM standard.
  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 Entry extends AtomBase
  39. {
  40. /**
  41. * The author of the entry.
  42. *
  43. * @var Person
  44. */
  45. protected $author;
  46. /**
  47. * The category of the entry.
  48. *
  49. * @var array
  50. */
  51. protected $category;
  52. /**
  53. * The content of the entry.
  54. *
  55. * @var string
  56. */
  57. protected $content;
  58. /**
  59. * The contributor of the entry.
  60. *
  61. * @var string
  62. */
  63. protected $contributor;
  64. /**
  65. * An unqiue ID representing the entry.
  66. *
  67. * @var string
  68. */
  69. protected $id;
  70. /**
  71. * The link of the entry.
  72. *
  73. * @var string
  74. */
  75. protected $link;
  76. /**
  77. * Is the entry published.
  78. *
  79. * @var boolean
  80. */
  81. protected $published;
  82. /**
  83. * The copy right of the entry.
  84. *
  85. * @var string
  86. */
  87. protected $rights;
  88. /**
  89. * The source of the entry.
  90. *
  91. * @var string
  92. */
  93. protected $source;
  94. /**
  95. * The summary of the entry.
  96. *
  97. * @var string
  98. */
  99. protected $summary;
  100. /**
  101. * The title of the entry.
  102. *
  103. * @var string
  104. */
  105. protected $title;
  106. /**
  107. * Is the entry updated.
  108. *
  109. * @var \DateTime
  110. */
  111. protected $updated;
  112. /**
  113. * The extension element of the entry.
  114. *
  115. * @var string
  116. */
  117. protected $extensionElement;
  118. /**
  119. * Creates an ATOM Entry instance with default parameters.
  120. */
  121. public function __construct()
  122. {
  123. $this->attributes = array();
  124. }
  125. /**
  126. * Populate the properties of an ATOM Entry instance with specified XML..
  127. *
  128. * @param string $xmlString A string representing an ATOM entry instance.
  129. *
  130. * @return none
  131. */
  132. public function parseXml($xmlString)
  133. {
  134. Validate::notNull($xmlString, 'xmlString');
  135. $entryXml = simplexml_load_string($xmlString);
  136. $this->attributes = (array)$entryXml->attributes();
  137. $entryArray = (array)$entryXml;
  138. if (array_key_exists(Resources::AUTHOR, $entryArray)) {
  139. $this->author = $this->processAuthorNode($entryArray);
  140. }
  141. if (array_key_exists(Resources::CATEGORY, $entryArray)) {
  142. $this->category = $this->processCategoryNode($entryArray);
  143. }
  144. if (array_key_exists('content', $entryArray)) {
  145. $content = new Content();
  146. $content->parseXml($entryArray['content']->asXML());
  147. $this->content = $content;
  148. }
  149. if (array_key_exists(Resources::CONTRIBUTOR, $entryArray)) {
  150. $this->contributor = $this->processContributorNode($entryArray);
  151. }
  152. if (array_key_exists('id', $entryArray)) {
  153. $this->id = (string)$entryArray['id'];
  154. }
  155. if (array_key_exists(Resources::LINK, $entryArray)) {
  156. $this->link = $this->processLinkNode($entryArray);
  157. }
  158. if (array_key_exists('published', $entryArray)) {
  159. $this->published = $entryArray['published'];
  160. }
  161. if (array_key_exists('rights', $entryArray)) {
  162. $this->rights = $entryArray['rights'];
  163. }
  164. if (array_key_exists('source', $entryArray)) {
  165. $source = new Source();
  166. $source->parseXml($entryArray['source']->asXML());
  167. $this->source = $source;
  168. }
  169. if (array_key_exists('title', $entryArray)) {
  170. $this->title = $entryArray['title'];
  171. }
  172. if (array_key_exists('updated', $entryArray)) {
  173. $this->updated = \DateTime::createFromFormat(
  174. \DateTime::ATOM,
  175. (string)$entryArray['updated']
  176. );
  177. }
  178. }
  179. /**
  180. * Gets the author of the entry.
  181. *
  182. * @return Person
  183. */
  184. public function getAuthor()
  185. {
  186. return $this->author;
  187. }
  188. /**
  189. * Sets the author of the entry.
  190. *
  191. * @param Person $author The author of the entry.
  192. *
  193. * @return none
  194. */
  195. public function setAuthor($author)
  196. {
  197. $this->author = $author;
  198. }
  199. /**
  200. * Gets the category.
  201. *
  202. * @return array
  203. */
  204. public function getCategory()
  205. {
  206. return $this->category;
  207. }
  208. /**
  209. * Sets the category.
  210. *
  211. * @param string $category The category of the entry.
  212. *
  213. * @return none
  214. */
  215. public function setCategory($category)
  216. {
  217. $this->category = $category;
  218. }
  219. /**
  220. * Gets the content.
  221. *
  222. * @return Content.
  223. */
  224. public function getContent()
  225. {
  226. return $this->content;
  227. }
  228. /**
  229. * Sets the content.
  230. *
  231. * @param Content $content Sets the content of the entry.
  232. *
  233. * @return none
  234. */
  235. public function setContent($content)
  236. {
  237. $this->content = $content;
  238. }
  239. /**
  240. * Gets the contributor.
  241. *
  242. * @return string
  243. */
  244. public function getContributor()
  245. {
  246. return $this->contributor;
  247. }
  248. /**
  249. * Sets the contributor.
  250. *
  251. * @param string $contributor The contributor of the entry.
  252. *
  253. * @return none
  254. */
  255. public function setContributor($contributor)
  256. {
  257. $this->contributor = $contributor;
  258. }
  259. /**
  260. * Gets the ID of the entry.
  261. *
  262. * @return string
  263. */
  264. public function getId()
  265. {
  266. return $this->id;
  267. }
  268. /**
  269. * Sets the ID of the entry.
  270. *
  271. * @param string $id The id of the entry.
  272. *
  273. * @return none
  274. */
  275. public function setId($id)
  276. {
  277. $this->id = $id;
  278. }
  279. /**
  280. * Gets the link of the entry.
  281. *
  282. * @return string
  283. */
  284. public function getLink()
  285. {
  286. return $this->link;
  287. }
  288. /**
  289. * Sets the link of the entry.
  290. *
  291. * @param string $link The link of the entry.
  292. *
  293. * @return none
  294. */
  295. public function setLink($link)
  296. {
  297. $this->link = $link;
  298. }
  299. /**
  300. * Gets published of the entry.
  301. *
  302. * @return boolean
  303. */
  304. public function getPublished()
  305. {
  306. return $this->published;
  307. }
  308. /**
  309. * Sets published of the entry.
  310. *
  311. * @param boolean $published Is the entry published.
  312. *
  313. * @return none
  314. */
  315. public function setPublished($published)
  316. {
  317. $this->published = $published;
  318. }
  319. /**
  320. * Gets the rights of the entry.
  321. *
  322. * @return string
  323. */
  324. public function getRights()
  325. {
  326. return $this->rights;
  327. }
  328. /**
  329. * Sets the rights of the entry.
  330. *
  331. * @param string $rights The rights of the entry.
  332. *
  333. * @return none
  334. */
  335. public function setRights($rights)
  336. {
  337. $this->rights = $rights;
  338. }
  339. /**
  340. * Gets the source of the entry.
  341. *
  342. * @return string
  343. */
  344. public function getSource()
  345. {
  346. return $this->source;
  347. }
  348. /**
  349. * Sets the source of the entry.
  350. *
  351. * @param string $source The source of the entry.
  352. *
  353. * @return none
  354. */
  355. public function setSource($source)
  356. {
  357. $this->source = $source;
  358. }
  359. /**
  360. * Gets the summary of the entry.
  361. *
  362. * @return string
  363. */
  364. public function getSummary()
  365. {
  366. return $this->summary;
  367. }
  368. /**
  369. * Sets the summary of the entry.
  370. *
  371. * @param string $summary The summary of the entry.
  372. *
  373. * @return none
  374. */
  375. public function setSummary($summary)
  376. {
  377. $this->summary = $summary;
  378. }
  379. /**
  380. * Gets the title of the entry.
  381. *
  382. * @return string
  383. */
  384. public function getTitle()
  385. {
  386. return $this->title;
  387. }
  388. /**
  389. * Sets the title of the entry.
  390. *
  391. * @param string $title The title of the entry.
  392. *
  393. * @return none
  394. */
  395. public function setTitle($title)
  396. {
  397. $this->title = $title;
  398. }
  399. /**
  400. * Gets updated.
  401. *
  402. * @return \DateTime
  403. */
  404. public function getUpdated()
  405. {
  406. return $this->updated;
  407. }
  408. /**
  409. * Sets updated
  410. *
  411. * @param \DateTime $updated updated.
  412. *
  413. * @return none
  414. */
  415. public function setUpdated($updated)
  416. {
  417. $this->updated = $updated;
  418. }
  419. /**
  420. * Gets extension element.
  421. *
  422. * @return string
  423. */
  424. public function getExtensionElement()
  425. {
  426. return $this->extensionElement;
  427. }
  428. /**
  429. * Sets extension element.
  430. *
  431. * @param string $extensionElement The extension element of the entry.
  432. *
  433. * @return none
  434. */
  435. public function setExtensionElement($extensionElement)
  436. {
  437. $this->extensionElement = $extensionElement;
  438. }
  439. /**
  440. * Writes a inner XML string representing the entry.
  441. *
  442. * @param \XMLWriter $xmlWriter The XML writer.
  443. *
  444. * @return none
  445. */
  446. public function writeXml($xmlWriter)
  447. {
  448. Validate::notNull($xmlWriter, 'xmlWriter');
  449. $xmlWriter->startElementNS(
  450. 'atom',
  451. Resources::ENTRY,
  452. Resources::ATOM_NAMESPACE
  453. );
  454. $this->writeInnerXml($xmlWriter);
  455. $xmlWriter->endElement();
  456. }
  457. /**
  458. * Writes a inner XML string representing the entry.
  459. *
  460. * @param \XMLWriter $xmlWriter The XML writer.
  461. *
  462. * @return none
  463. */
  464. public function writeInnerXml($xmlWriter)
  465. {
  466. if (!is_null($this->attributes)) {
  467. if (is_array($this->attributes)) {
  468. foreach (
  469. $this->attributes
  470. as $attributeName => $attributeValue
  471. ) {
  472. $xmlWriter->writeAttribute($attributeName, $attributeValue);
  473. }
  474. }
  475. }
  476. if (!is_null($this->author)) {
  477. $this->writeArrayItem(
  478. $xmlWriter,
  479. $this->author,
  480. Resources::AUTHOR
  481. );
  482. }
  483. if (!is_null($this->category)) {
  484. $this->writeArrayItem(
  485. $xmlWriter,
  486. $this->category,
  487. Resources::CATEGORY
  488. );
  489. }
  490. if (!is_null($this->content)) {
  491. $this->content->writeXml($xmlWriter);
  492. }
  493. if (!is_null($this->contributor)) {
  494. $this->writeArrayItem(
  495. $xmlWriter,
  496. $this->contributor,
  497. Resources::CONTRIBUTOR
  498. );
  499. }
  500. $this->writeOptionalElementNS(
  501. $xmlWriter,
  502. 'atom',
  503. 'id',
  504. Resources::ATOM_NAMESPACE,
  505. $this->id
  506. );
  507. if (!is_null($this->link)) {
  508. $this->writeArrayItem(
  509. $xmlWriter,
  510. $this->link,
  511. Resources::LINK
  512. );
  513. }
  514. $this->writeOptionalElementNS(
  515. $xmlWriter,
  516. 'atom',
  517. 'published',
  518. Resources::ATOM_NAMESPACE,
  519. $this->published
  520. );
  521. $this->writeOptionalElementNS(
  522. $xmlWriter,
  523. 'atom',
  524. 'rights',
  525. Resources::ATOM_NAMESPACE,
  526. $this->rights
  527. );
  528. $this->writeOptionalElementNS(
  529. $xmlWriter,
  530. 'atom',
  531. 'source',
  532. Resources::ATOM_NAMESPACE,
  533. $this->source
  534. );
  535. $this->writeOptionalElementNS(
  536. $xmlWriter,
  537. 'atom',
  538. 'summary',
  539. Resources::ATOM_NAMESPACE,
  540. $this->summary
  541. );
  542. $this->writeOptionalElementNS(
  543. $xmlWriter,
  544. 'atom',
  545. 'title',
  546. Resources::ATOM_NAMESPACE,
  547. $this->title
  548. );
  549. if (!is_null($this->updated)) {
  550. $xmlWriter->writeElementNS(
  551. 'atom',
  552. 'updated',
  553. Resources::ATOM_NAMESPACE,
  554. $this->updated->format(\DateTime::ATOM)
  555. );
  556. }
  557. }
  558. }
  559. ?>