PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/install/phing/classes/phing/parser/NestedElementHandler.php

https://github.com/chregu/fluxcms
PHP | 178 lines | 62 code | 17 blank | 99 comment | 8 complexity | 29dfb837e0500849be4a86a0120e4e69 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. include_once 'phing/IntrospectionHelper.php';
  22. /**
  23. * The nested element handler class.
  24. *
  25. * This class handles the occurance of runtime registered tags like
  26. * datatypes (fileset, patternset, etc) and it's possible nested tags. It
  27. * introspects the implementation of the class and sets up the data structures.
  28. *
  29. * @author Andreas Aderhold <andi@binarycloud.com>
  30. * @copyright © 2001,2002 THYRELL. All rights reserved
  31. * @version $Revision: 1.9 $ $Date: 2003/12/24 13:02:09 $
  32. * @access public
  33. * @package phing.parser
  34. */
  35. class NestedElementHandler extends AbstractHandler {
  36. /**
  37. * Reference to the parent object that represents the parent tag
  38. * of this nested element
  39. * @var object
  40. */
  41. private $parent;
  42. /**
  43. * Reference to the child object that represents the child tag
  44. * of this nested element
  45. * @var object
  46. */
  47. private $child;
  48. /**
  49. * Reference to the parent wrapper object
  50. * @var object
  51. */
  52. private $parentWrapper;
  53. /**
  54. * Reference to the child wrapper object
  55. * @var object
  56. */
  57. private $childWrapper;
  58. /**
  59. * Reference to the related target object
  60. * @var object the target instance
  61. */
  62. private $target;
  63. /**
  64. * Constructs a new NestedElement handler and sets up everything.
  65. *
  66. * @param object the ExpatParser object
  67. * @param object the parent handler that invoked this handler
  68. * @param object the ProjectConfigurator object
  69. * @param object the parent object this element is contained in
  70. * @param object the parent wrapper object
  71. * @param object the target object this task is contained in
  72. * @access public
  73. */
  74. function __construct($parser, $parentHandler, $configurator, $parent, $parentWrapper, $target) {
  75. parent::__construct($parser, $parentHandler);
  76. $this->configurator = $configurator;
  77. if ($parent instanceof TaskAdapter) {
  78. $this->parent = $parent->getProxy();
  79. } else {
  80. $this->parent = $parent;
  81. }
  82. $this->parentWrapper = $parentWrapper;
  83. $this->target = $target;
  84. }
  85. /**
  86. * Executes initialization actions required to setup the data structures
  87. * related to the tag.
  88. * <p>
  89. * This includes:
  90. * <ul>
  91. * <li>creation of the nested element</li>
  92. * <li>calling the setters for attributes</li>
  93. * <li>adding the element to the container object</li>
  94. * <li>adding a reference to the element (if id attribute is given)</li>
  95. * </ul>
  96. *
  97. * @param string the tag that comes in
  98. * @param array attributes the tag carries
  99. * @throws ExpatParseException if the setup process fails
  100. * @access public
  101. */
  102. function init($propType, $attrs) {
  103. $configurator = $this->configurator;
  104. $project = $this->configurator->project;
  105. // introspect the parent class that is custom
  106. $parentClass = get_class($this->parent);
  107. $ih = IntrospectionHelper::getHelper($parentClass);
  108. try {
  109. if ($this->parent instanceof UnknownElement) {
  110. $this->child = new UnknownElement(strtolower($propType));
  111. $this->parent->addChild($this->child);
  112. } else {
  113. $this->child = $ih->createElement($project, $this->parent, strtolower($propType));
  114. }
  115. $configurator->configureId($this->child, $attrs);
  116. if ($this->parentWrapper !== null) {
  117. $this->childWrapper = new RuntimeConfigurable($this->child, $propType);
  118. $this->childWrapper->setAttributes($attrs);
  119. $this->parentWrapper->addChild($this->childWrapper);
  120. } else {
  121. $configurator->configure($this->child, $attrs, $project);
  122. $ih->storeElement($project, $this->parent, $this->child, strtolower($propType));
  123. }
  124. } catch (BuildException $exc) {
  125. throw new ExpatParseException("Error initializing nested element <$propType>", $exc, $this->parser->getLocation());
  126. }
  127. }
  128. /**
  129. * Handles character data.
  130. *
  131. * @param string the CDATA that comes in
  132. * @throws ExpatParseException if the CDATA could not be set-up properly
  133. * @access public
  134. */
  135. function characters($data) {
  136. $configurator = $this->configurator;
  137. $project = $this->configurator->project;
  138. if ($this->parentWrapper === null) {
  139. try {
  140. $configurator->addText($project, $this->child, $data);
  141. } catch (BuildException $exc) {
  142. throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation());
  143. }
  144. } else {
  145. $this->childWrapper->addText($data);
  146. }
  147. }
  148. /**
  149. * Checks for nested tags within the current one. Creates and calls
  150. * handlers respectively.
  151. *
  152. * @param string the tag that comes in
  153. * @param array attributes the tag carries
  154. * @access public
  155. */
  156. function startElement($name, $attrs) {
  157. //print(get_class($this) . " name = $name, attrs = " . implode(",",$attrs) . "\n");
  158. $neh = new NestedElementHandler($this->parser, $this, $this->configurator, $this->child, $this->childWrapper, $this->target);
  159. $neh->init($name, $attrs);
  160. }
  161. }