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

/includes/Opl/Opt/Xml/Text.php

https://bitbucket.org/kandsten/hitta.sverok.se
PHP | 72 lines | 32 code | 3 blank | 37 comment | 10 complexity | b7a497b718f763dfdb33015a872db22a MD5 | raw file
Possible License(s): GPL-3.0, MIT
  1. <?php
  2. /*
  3. * OPEN POWER LIBS <http://www.invenzzia.org>
  4. *
  5. * This file is subject to the new BSD license that is bundled
  6. * with this package in the file LICENSE. It is also available through
  7. * WWW at this URL: <http://www.invenzzia.org/license/new-bsd>
  8. *
  9. * Copyright (c) Invenzzia Group <http://www.invenzzia.org>
  10. * and other contributors. See website for details.
  11. *
  12. * $Id: Text.php 231 2009-09-19 07:13:14Z zyxist $
  13. */
  14. /**
  15. * This is a container for Opt_Xml_Cdata and Opt_Xml_Expression objects.
  16. */
  17. class Opt_Xml_Text extends Opt_Xml_Scannable
  18. {
  19. /**
  20. * Constructs a new text object. If the argument is a
  21. * string, it automatically creates the initial Opt_Xml_Cdata
  22. * node and initializes it with the argument value.
  23. *
  24. * @param string $cdata The optional text for CDATA node.
  25. */
  26. public function __construct($cdata = null)
  27. {
  28. parent::__construct();
  29. if(!is_null($cdata))
  30. {
  31. $this->appendData($cdata);
  32. }
  33. } // end __construct();
  34. /**
  35. * Appends the text to the last character data node. If the last
  36. * node of Opt_Xml_Text is not Opt_Xml_Cdata, it automatically
  37. * creates the new node and initializes it with the argument value.
  38. *
  39. * @param string $cdata The string to append.
  40. */
  41. public function appendData($cdata)
  42. {
  43. $node = $this->getLastChild();
  44. if(is_null($node) || $node->getType() != 'Opt_Xml_Cdata' || $node->get('cdata') == true)
  45. {
  46. $node = new Opt_Xml_Cdata($cdata);
  47. $this->appendChild($node);
  48. }
  49. else
  50. {
  51. $node->appendData($cdata);
  52. }
  53. } // end appendData();
  54. /**
  55. * Tests, if the node we want to add is either Opt_Xml_Expression or Opt_Xml_Cdata.
  56. * The error is signalized with an exception.
  57. *
  58. * @internal
  59. * @param Opt_Xml_Node $node The node to test.
  60. * @throws Opt_APIInvalidNodeType_Exception
  61. */
  62. protected function _testNode(Opt_Xml_Node $node)
  63. {
  64. if($node->getType() != 'Opt_Xml_Expression' && $node->getType() != 'Opt_Xml_Cdata')
  65. {
  66. throw new Opt_APIInvalidNodeType_Exception('Opt_Xml_Text', $node->getType());
  67. }
  68. } // end _testNode();
  69. } // end Opt_Xml_Text;