PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/codes-php/phpjakarta/WindowsAzure/Common/Internal/Atom/Source.php

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