RootHandler.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * $Id: RootHandler.php 905 2010-10-05 16:28:03Z mrook $
  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. require_once 'phing/parser/AbstractHandler.php';
  22. include_once 'phing/parser/ExpatParseException.php';
  23. include_once 'phing/parser/ProjectHandler.php';
  24. /**
  25. * Root filter class for a phing buildfile.
  26. *
  27. * The root filter is called by the parser first. This is where the phing
  28. * specific parsing starts. RootHandler decides what to do next.
  29. *
  30. * @author Andreas Aderhold <andi@binarycloud.com>
  31. * @copyright © 2001,2002 THYRELL. All rights reserved
  32. * @version $Revision: 905 $
  33. * @package phing.parser
  34. */
  35. class RootHandler extends AbstractHandler {
  36. /**
  37. * The phing project configurator object
  38. */
  39. private $configurator;
  40. /**
  41. * Constructs a new RootHandler
  42. *
  43. * The root filter is required so the parser knows what to do. It's
  44. * called by the ExpatParser that is instatiated in ProjectConfigurator.
  45. *
  46. * It recieves the expat parse object ref and a reference to the
  47. * configurator
  48. *
  49. * @param AbstractSAXParser $parser The ExpatParser object.
  50. * @param ProjectConfigurator $configurator The ProjectConfigurator object.
  51. */
  52. function __construct(AbstractSAXParser $parser, ProjectConfigurator $configurator) {
  53. $this->configurator = $configurator;
  54. parent::__construct($parser, $this);
  55. }
  56. /**
  57. * Kick off a custom action for a start element tag.
  58. *
  59. * The root element of our buildfile is the &lt;project&gt; element. The
  60. * root filter handles this element if it occurs, creates ProjectHandler
  61. * to handle any nested tags & attributes of the &lt;project&gt; tag,
  62. * and calls init.
  63. *
  64. * @param string $tag The xml tagname
  65. * @param array $attrs The attributes of the tag
  66. * @throws ExpatParseException if the first element within our build file
  67. * is not the &gt;project&lt; element
  68. */
  69. function startElement($tag, $attrs) {
  70. if ($tag === "project") {
  71. $ph = new ProjectHandler($this->parser, $this, $this->configurator);
  72. $ph->init($tag, $attrs);
  73. } else {
  74. throw new ExpatParseException("Unexpected tag <$tag> in top-level of build file.", $this->parser->getLocation());
  75. }
  76. }
  77. }