PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/install/phing/classes/phing/RuntimeConfigurable.php

https://github.com/chregu/fluxcms
PHP | 118 lines | 56 code | 20 blank | 42 comment | 7 complexity | b0ca5db220dbe1e8b14b3e25fa6988e5 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. /**
  22. * Wrapper class that holds the attributes of a Task (or elements
  23. * nested below that level) and takes care of configuring that element
  24. * at runtime.
  25. *
  26. * <strong>SMART-UP INLINE DOCS</strong>
  27. *
  28. * @author Andreas Aderhold <andi@binarycloud.com>
  29. * @author Hans Lellelid <hans@xmpl.org>
  30. * @version $Revision: 1.6 $
  31. * @package phing
  32. */
  33. class RuntimeConfigurable {
  34. private $elementTag = null;
  35. private $children = array();
  36. private $wrappedObject = null;
  37. private $attributes = array();
  38. private $characters = "";
  39. /** @param proxy The element to wrap. */
  40. function __construct($proxy, $elementTag) {
  41. $this->wrappedObject = $proxy;
  42. $this->elementTag = $elementTag;
  43. }
  44. function setProxy($proxy) {
  45. $this->wrappedObject = $proxy;
  46. }
  47. /** Set's the attributes for the wrapped element. */
  48. function setAttributes($attributes) {
  49. $this->attributes = $attributes;
  50. }
  51. /** Returns the AttributeList of the wrapped element. */
  52. function getAttributes() {
  53. return $this->attributes;
  54. }
  55. /** Adds child elements to the wrapped element. */
  56. function addChild(RuntimeConfigurable $child) {
  57. $this->children[] = $child;
  58. }
  59. /** Returns the child with index */
  60. function getChild($index) {
  61. return $this->children[(int)$index];
  62. }
  63. /** Add characters from #PCDATA areas to the wrapped element. */
  64. function addText($data) {
  65. $this->characters .= (string) $data;
  66. }
  67. function getElementTag() {
  68. return $this->elementTag;
  69. }
  70. /** Configure the wrapped element and all children. */
  71. function maybeConfigure(Project $project) {
  72. $id = null;
  73. // DataType configured in ProjectConfigurator
  74. // if ( is_a($this->wrappedObject, "DataType") )
  75. // return;
  76. if ($this->attributes || $this->characters) {
  77. ProjectConfigurator::configure($this->wrappedObject, $this->attributes, $project);
  78. if (isset($this->attributes["id"])) {
  79. $id = $this->attributes["id"];
  80. }
  81. $this->attributes = null;
  82. if ($this->characters) {
  83. ProjectConfigurator::addText($project, $this->wrappedObject, (string) $this->characters);
  84. $this->characters="";
  85. }
  86. if ($id !== null) {
  87. $project->addReference($id, $this->wrappedObject);
  88. }
  89. }
  90. if ( is_array($this->children) && !empty($this->children) ) {
  91. // Configure all child of this object ...
  92. foreach($this->children as $child) {
  93. $child->maybeConfigure($project);
  94. ProjectConfigurator::storeChild($project, $this->wrappedObject, $child->wrappedObject, strtolower($child->getElementTag()));
  95. }
  96. }
  97. }
  98. }