CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,98 @@
<?php
/*
* $Id: AbstractHandler.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/parser/ExpatParseException.php';
/**
* This is an abstract class all SAX handler classes must extend
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @package phing.parser
*/
abstract class AbstractHandler {
public $parentHandler = null;
public $parser = null;
/**
* Constructs a SAX handler parser.
*
* The constructor must be called by all derived classes.
*
* @param object the parser object
* @param object the parent handler of this handler
*/
protected function __construct($parser, $parentHandler) {
$this->parentHandler = $parentHandler;
$this->parser = $parser;
$this->parser->setHandler($this);
}
/**
* Gets invoked when a XML open tag occurs
*
* Must be overloaded by the child class. Throws an ExpatParseException
* if there is no handler registered for an element.
*
* @param string the name of the XML element
* @param array the attributes of the XML element
*/
public function startElement($name, $attribs) {
throw new ExpatParseException("Unexpected element $name");
}
/**
* Gets invoked when element closes method.
*
*/
protected function finished() {}
/**
* Gets invoked when a XML element ends.
*
* Can be overloaded by the child class. But should not. It hands
* over control to the parentHandler of this.
*
* @param string the name of the XML element
*/
public function endElement($name) {
$this->finished();
$this->parser->setHandler($this->parentHandler);
}
/**
* Invoked by occurance of #PCDATA.
*
* @param string the name of the XML element
* @exception ExpatParserException if there is no CDATA but method
* was called
* @access public
*/
public function characters($data) {
$s = trim($data);
if (strlen($s) > 0) {
throw new ExpatParseException("Unexpected text '$s'", $this->parser->getLocation());
}
}
}

View file

@ -0,0 +1,116 @@
<?php
/*
* $Id: AbstractSAXParser.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* The abstract SAX parser class.
*
* This class represents a SAX parser. It is a abstract calss that must be
* implemented by the real parser that must extend this class
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @copyright <EFBFBD> 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @package phing.parser
*/
abstract class AbstractSAXParser {
/** The AbstractHandler object. */
protected $handler;
/**
* Constructs a SAX parser
*/
function __construct() {}
/**
* Sets options for PHP interal parser. Must be implemented by the parser
* class if it should be used.
*/
abstract function parserSetOption($opt, $val);
/**
* Sets the current element handler object for this parser. Usually this
* is an object using extending "AbstractHandler".
*
* @param AbstractHandler $obj The handler object.
*/
function setHandler( $obj) {
$this->handler = $obj;
}
/**
* Method that gets invoked when the parser runs over a XML start element.
*
* This method is called by PHP's internal parser functions and registered
* in the actual parser implementation.
* It gives control to the current active handler object by calling the
* <code>startElement()</code> method.
*
* @param object the php's internal parser handle
* @param string the open tag name
* @param array the tag's attributes if any
* @throws Exception - Exceptions may be thrown by the Handler
*/
function startElement($parser, $name, $attribs) {
$this->handler->startElement($name, $attribs);
}
/**
* Method that gets invoked when the parser runs over a XML close element.
*
* This method is called by PHP's internal parser funcitons and registered
* in the actual parser implementation.
*
* It gives control to the current active handler object by calling the
* <code>endElement()</code> method.
*
* @param object the php's internal parser handle
* @param string the closing tag name
* @throws Exception - Exceptions may be thrown by the Handler
*/
function endElement($parser, $name) {
$this->handler->endElement($name);
}
/**
* Method that gets invoked when the parser runs over CDATA.
*
* This method is called by PHP's internal parser functions and registered
* in the actual parser implementation.
*
* It gives control to the current active handler object by calling the
* <code>characters()</code> method. That processes the given CDATA.
*
* @param resource $parser php's internal parser handle.
* @param string $data the CDATA
* @throws Exception - Exceptions may be thrown by the Handler
*/
function characters($parser, $data) {
$this->handler->characters($data);
}
/**
* Entrypoint for parser. This method needs to be implemented by the
* child classt that utilizes the concrete parser
*/
abstract function parse();
}

View file

@ -0,0 +1,144 @@
<?php
/*
* $Id: DataTypeHandler.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/RuntimeConfigurable.php';
/**
* Configures a Project (complete with Targets and Tasks) based on
* a XML build file.
* <p>
* Design/ZE2 migration note:
* If PHP would support nested classes. All the phing/parser/*Filter
* classes would be nested within this class
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing.parser
*/
class DataTypeHandler extends AbstractHandler {
private $target;
private $element;
private $wrapper;
/**
* Constructs a new DataTypeHandler and sets up everything.
*
* @param AbstractSAXParser $parser The XML parser (default: ExpatParser)
* @param AbstractHandler $parentHandler The parent handler that invoked this handler.
* @param ProjectConfigurator $configurator The ProjectConfigurator object
* @param Target $target The target object this datatype is contained in (null for top-level datatypes).
*/
function __construct(AbstractSAXParser $parser, AbstractHandler $parentHandler, ProjectConfigurator $configurator, $target = null) { // FIXME b2 typehinting
parent::__construct($parser, $parentHandler);
$this->target = $target;
$this->configurator = $configurator;
}
/**
* Executes initialization actions required to setup the data structures
* related to the tag.
* <p>
* This includes:
* <ul>
* <li>creation of the datatype object</li>
* <li>calling the setters for attributes</li>
* <li>adding the type to the target object if any</li>
* <li>adding a reference to the task (if id attribute is given)</li>
* </ul>
*
* @param string the tag that comes in
* @param array attributes the tag carries
* @throws ExpatParseException if attributes are incomplete or invalid
* @access public
*/
function init($propType, $attrs) {
// shorthands
$project = $this->configurator->project;
$configurator = $this->configurator;
try {//try
$this->element = $project->createDataType($propType);
if ($this->element === null) {
throw new BuildException("Unknown data type $propType");
}
if ($this->target !== null) {
$this->wrapper = new RuntimeConfigurable($this->element, $propType);
$this->wrapper->setAttributes($attrs);
$this->target->addDataType($this->wrapper);
} else {
$configurator->configure($this->element, $attrs, $project);
$configurator->configureId($this->element, $attrs);
}
} catch (BuildException $exc) {
throw new ExpatParseException($exc, $this->parser->getLocation());
}
}
/**
* Handles character data.
*
* @param string the CDATA that comes in
* @access public
*/
function characters($data) {
$project = $this->configurator->project;
try {//try
$this->configurator->addText($project, $this->element, $data);
} catch (BuildException $exc) {
throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation());
}
}
/**
* Checks for nested tags within the current one. Creates and calls
* handlers respectively.
*
* @param string the tag that comes in
* @param array attributes the tag carries
* @access public
*/
function startElement($name, $attrs) {
$nef = new NestedElementHandler($this->parser, $this, $this->configurator, $this->element, $this->wrapper, $this->target);
$nef->init($name, $attrs);
}
/**
* Overrides endElement for data types. Tells the type
* handler that processing the element had been finished so
* handlers know they can perform actions that need to be
* based on the data contained within the element.
*
* @param string the name of the XML element
* @return void
*/
function endElement($name) {
$this->element->parsingComplete();
parent::endElement($name);
}
}

View file

@ -0,0 +1,31 @@
<?php
/*
* $Id: ExpatParseException.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/BuildException.php';
/**
* This class throws errors for Expat, the XML processor.
*
* @author Andreas Aderhold, andi@binarycloud.com
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @package phing.parser
*/
class ExpatParseException extends BuildException {}

View file

@ -0,0 +1,140 @@
<?php
/*
* $Id: ExpatParser.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/parser/AbstractSAXParser.php';
include_once 'phing/parser/ExpatParseException.php';
include_once 'phing/system/io/IOException.php';
include_once 'phing/system/io/FileReader.php';
/**
* This class is a wrapper for the PHP's internal expat parser.
*
* It takes an XML file represented by a abstract path name, and starts
* parsing the file and calling the different "trap" methods inherited from
* the AbstractParser class.
*
* Those methods then invoke the represenatative methods in the registered
* handler classes.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing.parser
*/
class ExpatParser extends AbstractSAXParser {
/** @var resource */
private $parser;
/** @var Reader */
private $reader;
private $file;
private $buffer = 4096;
private $error_string = "";
private $line = 0;
/** @var Location Current cursor pos in XML file. */
private $location;
/**
* Constructs a new ExpatParser object.
*
* The constructor accepts a PhingFile object that represents the filename
* for the file to be parsed. It sets up php's internal expat parser
* and options.
*
* @param Reader $reader The Reader Object that is to be read from.
* @param string $filename Filename to read.
* @throws Exception if the given argument is not a PhingFile object
*/
function __construct(Reader $reader, $filename=null) {
$this->reader = $reader;
if ($filename !== null) {
$this->file = new PhingFile($filename);
}
$this->parser = xml_parser_create();
$this->buffer = 4096;
$this->location = new Location();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, array($this,"startElement"),array($this,"endElement"));
xml_set_character_data_handler($this->parser, array($this, "characters"));
}
/**
* Override PHP's parser default settings, created in the constructor.
*
* @param string the option to set
* @throws mixed the value to set
* @return boolean true if the option could be set, otherwise false
* @access public
*/
function parserSetOption($opt, $val) {
return xml_parser_set_option($this->parser, $opt, $val);
}
/**
* Returns the location object of the current parsed element. It describes
* the location of the element within the XML file (line, char)
*
* @return object the location of the current parser
* @access public
*/
function getLocation() {
if ($this->file !== null) {
$path = $this->file->getAbsolutePath();
} else {
$path = $this->reader->getResource();
}
$this->location = new Location($path, xml_get_current_line_number($this->parser), xml_get_current_column_number($this->parser));
return $this->location;
}
/**
* Starts the parsing process.
*
* @param string the option to set
* @return int 1 if the parsing succeeded
* @throws ExpatParseException if something gone wrong during parsing
* @throws IOException if XML file can not be accessed
* @access public
*/
function parse() {
while ( ($data = $this->reader->read()) !== -1 ) {
if (!xml_parse($this->parser, $data, $this->reader->eof())) {
$error = xml_error_string(xml_get_error_code($this->parser));
$e = new ExpatParseException($error, $this->getLocation());
xml_parser_free($this->parser);
throw $e;
}
}
xml_parser_free($this->parser);
return 1;
}
}

View file

@ -0,0 +1,76 @@
<?php
/*
* $Id: Location.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Stores the file name and line number of a XML file
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing.parser
*/
class Location {
private $fileName;
private $lineNumber;
private $columnNumber;
/**
* Constructs the location consisting of a file name and line number
*
* @param string the filename
* @param integer the line number
* @param integer the column number
* @access public
*/
function Location($fileName = null, $lineNumber = null, $columnNumber = null) {
$this->fileName = $fileName;
$this->lineNumber = $lineNumber;
$this->columnNumber = $columnNumber;
}
/**
* Returns the file name, line number and a trailing space.
*
* An error message can be appended easily. For unknown locations,
* returns empty string.
*
* @return string the string representation of this Location object
* @access public
*/
function toString() {
$buf = "";
if ($this->fileName !== null) {
$buf.=$this->fileName;
if ($this->lineNumber !== null) {
$buf.= ":".$this->lineNumber;
}
$buf.=":".$this->columnNumber;
}
return (string) $buf;
}
function __toString () {
return $this->toString();
}
}

View file

@ -0,0 +1,186 @@
<?php
/*
* $Id: NestedElementHandler.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/IntrospectionHelper.php';
include_once 'phing/TaskContainer.php';
/**
* The nested element handler class.
*
* This class handles the occurance of runtime registered tags like
* datatypes (fileset, patternset, etc) and it's possible nested tags. It
* introspects the implementation of the class and sets up the data structures.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing.parser
*/
class NestedElementHandler extends AbstractHandler {
/**
* Reference to the parent object that represents the parent tag
* of this nested element
* @var object
*/
private $parent;
/**
* Reference to the child object that represents the child tag
* of this nested element
* @var object
*/
private $child;
/**
* Reference to the parent wrapper object
* @var object
*/
private $parentWrapper;
/**
* Reference to the child wrapper object
* @var object
*/
private $childWrapper;
/**
* Reference to the related target object
* @var object the target instance
*/
private $target;
/**
* Constructs a new NestedElement handler and sets up everything.
*
* @param object the ExpatParser object
* @param object the parent handler that invoked this handler
* @param object the ProjectConfigurator object
* @param object the parent object this element is contained in
* @param object the parent wrapper object
* @param object the target object this task is contained in
* @access public
*/
function __construct($parser, $parentHandler, $configurator, $parent, $parentWrapper, $target) {
parent::__construct($parser, $parentHandler);
$this->configurator = $configurator;
if ($parent instanceof TaskAdapter) {
$this->parent = $parent->getProxy();
} else {
$this->parent = $parent;
}
$this->parentWrapper = $parentWrapper;
$this->target = $target;
}
/**
* Executes initialization actions required to setup the data structures
* related to the tag.
* <p>
* This includes:
* <ul>
* <li>creation of the nested element</li>
* <li>calling the setters for attributes</li>
* <li>adding the element to the container object</li>
* <li>adding a reference to the element (if id attribute is given)</li>
* </ul>
*
* @param string the tag that comes in
* @param array attributes the tag carries
* @throws ExpatParseException if the setup process fails
* @access public
*/
function init($propType, $attrs) {
$configurator = $this->configurator;
$project = $this->configurator->project;
// introspect the parent class that is custom
$parentClass = get_class($this->parent);
$ih = IntrospectionHelper::getHelper($parentClass);
try {
if ($this->parent instanceof UnknownElement) {
$this->child = new UnknownElement(strtolower($propType));
$this->parent->addChild($this->child);
} else {
$this->child = $ih->createElement($project, $this->parent, strtolower($propType));
}
$configurator->configureId($this->child, $attrs);
if ($this->parentWrapper !== null) {
$this->childWrapper = new RuntimeConfigurable($this->child, $propType);
$this->childWrapper->setAttributes($attrs);
$this->parentWrapper->addChild($this->childWrapper);
} else {
$configurator->configure($this->child, $attrs, $project);
$ih->storeElement($project, $this->parent, $this->child, strtolower($propType));
}
} catch (BuildException $exc) {
throw new ExpatParseException("Error initializing nested element <$propType>", $exc, $this->parser->getLocation());
}
}
/**
* Handles character data.
*
* @param string the CDATA that comes in
* @throws ExpatParseException if the CDATA could not be set-up properly
* @access public
*/
function characters($data) {
$configurator = $this->configurator;
$project = $this->configurator->project;
if ($this->parentWrapper === null) {
try {
$configurator->addText($project, $this->child, $data);
} catch (BuildException $exc) {
throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation());
}
} else {
$this->childWrapper->addText($data);
}
}
/**
* Checks for nested tags within the current one. Creates and calls
* handlers respectively.
*
* @param string the tag that comes in
* @param array attributes the tag carries
* @access public
*/
function startElement($name, $attrs) {
//print(get_class($this) . " name = $name, attrs = " . implode(",",$attrs) . "\n");
if ($this->child instanceof TaskContainer) {
// taskcontainer nested element can contain other tasks - no other
// nested elements possible
$tc = new TaskHandler($this->parser, $this, $this->configurator, $this->child, $this->childWrapper, $this->target);
$tc->init($name, $attrs);
} else {
$neh = new NestedElementHandler($this->parser, $this, $this->configurator, $this->child, $this->childWrapper, $this->target);
$neh->init($name, $attrs);
}
}
}

View file

@ -0,0 +1,81 @@
<?php
/*
* $Id: PhingXMLContext.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Track the current state of the Xml parse operation.
*
* @author Bryan Davis <bpd@keynetics.com>
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing.parser
*/
class PhingXMLContext {
/**
* Constructor
* @param $project the project to which this antxml context belongs to
*/
public function __construct ($project) {
$this->project = $project;
}
/** The project to configure. */
private $project;
private $configurators = array();
public function startConfigure ($cfg) {
$this->configurators[] = $cfg;
}
public function endConfigure () {
array_pop($this->configurators);
}
public function getConfigurator () {
$l = count($this->configurators);
if (0 == $l) {
return null;
} else {
return $this->configurators[$l - 1];
}
}
/** Impoerted files */
private $importStack = array();
public function addImport ($file) {
$this->importStack[] = $file;
}
public function getImportStack () {
return $this->importStack;
}
/**
* find out the project to which this context belongs
* @return project
*/
public function getProject() {
return $this->project;
}
} //end PhingXMLContext

View file

@ -0,0 +1,373 @@
<?php
/*
* $Id: ProjectConfigurator.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/system/io/BufferedReader.php';
include_once 'phing/system/io/FileReader.php';
include_once 'phing/BuildException.php';
include_once 'phing/system/lang/FileNotFoundException.php';
include_once 'phing/system/io/PhingFile.php';
include_once 'phing/parser/PhingXMLContext.php';
include_once 'phing/IntrospectionHelper.php';
/**
* The datatype handler class.
*
* This class handles the occurance of registered datatype tags like
* FileSet
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright <EFBFBD> 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing.parser
*/
class ProjectConfigurator {
public $project;
public $locator;
public $buildFile;
public $buildFileParent;
/** Targets in current file */
private $currentTargets;
/** Synthetic target that will be called at the end to the parse phase */
private $parseEndTarget;
/** Name of the current project */
private $currentProjectName;
private $isParsing = true;
/**
* Indicates whether the project tag attributes are to be ignored
* when processing a particular build file.
*/
private $ignoreProjectTag = false;
/**
* Static call to ProjectConfigurator. Use this to configure a
* project. Do not use the new operator.
*
* @param object the Project instance this configurator should use
* @param object the buildfile object the parser should use
* @access public
*/
public static function configureProject(Project $project, PhingFile $buildFile) {
$pc = new ProjectConfigurator($project, $buildFile);
$pc->parse();
}
/**
* Constructs a new ProjectConfigurator object
* This constructor is private. Use a static call to
* <code>configureProject</code> to configure a project.
*
* @param object the Project instance this configurator should use
* @param object the buildfile object the parser should use
* @access private
*/
function __construct(Project $project, PhingFile $buildFile) {
$this->project = $project;
$this->buildFile = new PhingFile($buildFile->getAbsolutePath());
$this->buildFileParent = new PhingFile($this->buildFile->getParent());
$this->currentTargets = array();
$this->parseEndTarget = new Target();
}
/**
* find out the build file
* @return the build file to which the xml context belongs
*/
public function getBuildFile() {
return $this->buildFile;
}
/**
* find out the parent build file of this build file
* @return the parent build file of this build file
*/
public function getBuildFileParent() {
return $this->buildFileParent;
}
/**
* find out the current project name
* @return current project name
*/
public function getCurrentProjectName() {
return $this->currentProjectName;
}
/**
* set the name of the current project
* @param name name of the current project
*/
public function setCurrentProjectName($name) {
$this->currentProjectName = $name;
}
/**
* tells whether the project tag is being ignored
* @return whether the project tag is being ignored
*/
public function isIgnoringProjectTag() {
return $this->ignoreProjectTag;
}
/**
* sets the flag to ignore the project tag
* @param flag to ignore the project tag
*/
public function setIgnoreProjectTag($flag) {
$this->ignoreProjectTag = $flag;
}
public function &getCurrentTargets () {
return $this->currentTargets;
}
public function isParsing () {
return $this->isParsing;
}
/**
* Creates the ExpatParser, sets root handler and kick off parsing
* process.
*
* @throws BuildException if there is any kind of execption during
* the parsing process
* @access private
*/
protected function parse() {
try {
// get parse context
$ctx = $this->project->getReference("phing.parsing.context");
if (null == $ctx) {
// make a new context and register it with project
$ctx = new PhingXMLContext($this->project);
$this->project->addReference("phing.parsing.context", $ctx);
}
//record this parse with context
$ctx->addImport($this->buildFile);
if (count($ctx->getImportStack()) > 1) {
// this is an imported file
// modify project tag parse behavior
$this->setIgnoreProjectTag(true);
}
// push action onto global stack
$ctx->startConfigure($this);
$reader = new BufferedReader(new FileReader($this->buildFile));
$parser = new ExpatParser($reader);
$parser->parserSetOption(XML_OPTION_CASE_FOLDING,0);
$parser->setHandler(new RootHandler($parser, $this));
$this->project->log("parsing buildfile ".$this->buildFile->getName(), Project::MSG_VERBOSE);
$parser->parse();
$reader->close();
// mark parse phase as completed
$this->isParsing = false;
// execute delayed tasks
$this->parseEndTarget->main();
// pop this action from the global stack
$ctx->endConfigure();
} catch (Exception $exc) {
throw new BuildException("Error reading project file", $exc);
}
}
/**
* Delay execution of a task until after the current parse phase has
* completed.
*
* @param Task $task Task to execute after parse
*/
public function delayTaskUntilParseEnd ($task) {
$this->parseEndTarget->addTask($task);
}
/**
* Configures an element and resolves eventually given properties.
*
* @param object the element to configure
* @param array the element's attributes
* @param object the project this element belongs to
* @throws Exception if arguments are not valid
* @throws BuildException if attributes can not be configured
* @access public
*/
public static function configure($target, $attrs, Project $project) {
if ($target instanceof TaskAdapter) {
$target = $target->getProxy();
}
// if the target is an UnknownElement, this means that the tag had not been registered
// when the enclosing element (task, target, etc.) was configured. It is possible, however,
// that the tag was registered (e.g. using <taskdef>) after the original configuration.
// ... so, try to load it again:
if ($target instanceof UnknownElement) {
$tryTarget = $project->createTask($target->getTaskType());
if ($tryTarget) {
$target = $tryTarget;
}
}
$bean = get_class($target);
$ih = IntrospectionHelper::getHelper($bean);
foreach ($attrs as $key => $value) {
if ($key == 'id') {
continue;
// throw new BuildException("Id must be set Extermnally");
}
$value = self::replaceProperties($project, $value, $project->getProperties());
try { // try to set the attribute
$ih->setAttribute($project, $target, strtolower($key), $value);
} catch (BuildException $be) {
// id attribute must be set externally
if ($key !== "id") {
throw $be;
}
}
}
}
/**
* Configures the #CDATA of an element.
*
* @param object the project this element belongs to
* @param object the element to configure
* @param string the element's #CDATA
* @access public
*/
public static function addText($project, $target, $text = null) {
if ($text === null || strlen(trim($text)) === 0) {
return;
}
$ih = IntrospectionHelper::getHelper(get_class($target));
$text = self::replaceProperties($project, $text, $project->getProperties());
$ih->addText($project, $target, $text);
}
/**
* Stores a configured child element into its parent object
*
* @param object the project this element belongs to
* @param object the parent element
* @param object the child element
* @param string the XML tagname
* @access public
*/
public static function storeChild($project, $parent, $child, $tag) {
$ih = IntrospectionHelper::getHelper(get_class($parent));
$ih->storeElement($project, $parent, $child, $tag);
}
// The following two properties are a sort of hack
// to enable a static function to serve as the callback
// for preg_replace_callback(). Clearly we cannot use object
// variables, since the replaceProperties() is called statically.
// This is IMO better than using global variables in the callback.
private static $propReplaceProject;
private static $propReplaceProperties;
/**
* Replace ${} style constructions in the given value with the
* string value of the corresponding data types. This method is
* static.
*
* @param object the project that should be used for property look-ups
* @param string the string to be scanned for property references
* @param array proeprty keys
* @return string the replaced string or <code>null</code> if the string
* itself was null
*/
public static function replaceProperties(Project $project, $value, $keys) {
if ($value === null) {
return null;
}
// These are a "hack" to support static callback for preg_replace_callback()
// make sure these get initialized every time
self::$propReplaceProperties = $keys;
self::$propReplaceProject = $project;
// Because we're not doing anything special (like multiple passes),
// regex is the simplest / fastest. PropertyTask, though, uses
// the old parsePropertyString() method, since it has more stringent
// requirements.
$sb = $value;
$iteration = 0;
// loop to recursively replace tokens
while (strpos($sb, '${') !== false)
{
$sb = preg_replace_callback('/\$\{([^\$}]+)\}/', array('ProjectConfigurator', 'replacePropertyCallback'), $sb);
// keep track of iterations so we can break out of otherwise infinite loops.
$iteration++;
if ($iteration == 5)
{
return $sb;
}
}
return $sb;
}
/**
* Private [static] function for use by preg_replace_callback to replace a single param.
* This method makes use of a static variable to hold the
*/
private static function replacePropertyCallback($matches)
{
$propertyName = $matches[1];
if (!isset(self::$propReplaceProperties[$propertyName])) {
self::$propReplaceProject->log('Property ${'.$propertyName.'} has not been set.', Project::MSG_VERBOSE);
return $matches[0];
} else {
self::$propReplaceProject->log('Property ${'.$propertyName.'} => ' . self::$propReplaceProperties[$propertyName], Project::MSG_DEBUG);
}
return self::$propReplaceProperties[$propertyName];
}
/**
* Scan Attributes for the id attribute and maybe add a reference to
* project.
*
* @param object the element's object
* @param array the element's attributes
*/
public function configureId($target, $attr) {
if (isset($attr['id']) && $attr['id'] !== null) {
$this->project->addReference($attr['id'], $target);
}
}
}

View file

@ -0,0 +1,176 @@
<?php
/*
* $Id: ProjectHandler.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/parser/AbstractHandler.php';
require_once 'phing/system/io/PhingFile.php';
/**
* Handler class for the <project> XML element This class handles all elements
* under the <project> element.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright (c) 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing.parser
*/
class ProjectHandler extends AbstractHandler {
/**
* The phing project configurator object.
* @var ProjectConfigurator
*/
private $configurator;
/**
* Constructs a new ProjectHandler
*
* @param object the ExpatParser object
* @param object the parent handler that invoked this handler
* @param object the ProjectConfigurator object
* @access public
*/
function __construct($parser, $parentHandler, $configurator) {
$this->configurator = $configurator;
parent::__construct($parser, $parentHandler);
}
/**
* Executes initialization actions required to setup the project. Usually
* this method handles the attributes of a tag.
*
* @param string the tag that comes in
* @param array attributes the tag carries
* @param object the ProjectConfigurator object
* @throws ExpatParseException if attributes are incomplete or invalid
* @access public
*/
function init($tag, $attrs) {
$def = null;
$name = null;
$id = null;
$desc = null;
$baseDir = null;
$ver = null;
// some shorthands
$project = $this->configurator->project;
$buildFileParent = $this->configurator->buildFileParent;
foreach ($attrs as $key => $value) {
if ($key === "default") {
$def = $value;
} elseif ($key === "name") {
$name = $value;
} elseif ($key === "id") {
$id = $value;
} elseif ($key === "basedir") {
$baseDir = $value;
} elseif ($key === "description") {
$desc = $value;
} elseif ($key === "phingVersion") {
$ver = $value;
} else {
throw new ExpatParseException("Unexpected attribute '$key'");
}
}
// these things get done no matter what
if (null != $name) {
$canonicalName = self::canonicalName($name);
$this->configurator->setCurrentProjectName($canonicalName);
$project->setUserProperty("phing.file.{$canonicalName}",
(string) $this->configurator->getBuildFile());
}
if (!$this->configurator->isIgnoringProjectTag()) {
if ($def === null) {
throw new ExpatParseException(
"The default attribute of project is required");
}
$project->setDefaultTarget($def);
if ($name !== null) {
$project->setName($name);
$project->addReference($name, $project);
}
if ($id !== null) {
$project->addReference($id, $project);
}
if ($desc !== null) {
$project->setDescription($desc);
}
if($ver !== null) {
$project->setPhingVersion($ver);
}
if ($project->getProperty("project.basedir") !== null) {
$project->setBasedir($project->getProperty("project.basedir"));
} else {
if ($baseDir === null) {
$project->setBasedir($buildFileParent->getAbsolutePath());
} else {
// check whether the user has specified an absolute path
$f = new PhingFile($baseDir);
if ($f->isAbsolute()) {
$project->setBasedir($baseDir);
} else {
$project->setBaseDir($project->resolveFile($baseDir, new PhingFile(getcwd())));
}
}
}
}
}
/**
* Handles start elements within the <project> tag by creating and
* calling the required handlers for the detected element.
*
* @param string the tag that comes in
* @param array attributes the tag carries
* @throws ExpatParseException if a unxepected element occurs
* @access public
*/
function startElement($name, $attrs) {
$project = $this->configurator->project;
$types = $project->getDataTypeDefinitions();
if ($name == "target") {
$tf = new TargetHandler($this->parser, $this, $this->configurator);
$tf->init($name, $attrs);
} elseif (isset($types[$name])) {
$tyf = new DataTypeHandler($this->parser, $this, $this->configurator);
$tyf->init($name, $attrs);
} else {
$tf = new TaskHandler($this->parser, $this, $this->configurator);
$tf->init($name, $attrs);
}
}
static function canonicalName ($name) {
return preg_replace('/\W/', '_', strtolower($name));
}
}

View file

@ -0,0 +1,82 @@
<?php
/*
* $Id: RootHandler.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/parser/AbstractHandler.php';
include_once 'phing/parser/ExpatParseException.php';
include_once 'phing/parser/ProjectHandler.php';
/**
* Root filter class for a phing buildfile.
*
* The root filter is called by the parser first. This is where the phing
* specific parsing starts. RootHandler decides what to do next.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @package phing.parser
*/
class RootHandler extends AbstractHandler {
/**
* The phing project configurator object
*/
private $configurator;
/**
* Constructs a new RootHandler
*
* The root filter is required so the parser knows what to do. It's
* called by the ExpatParser that is instatiated in ProjectConfigurator.
*
* It recieves the expat parse object ref and a reference to the
* configurator
*
* @param AbstractSAXParser $parser The ExpatParser object.
* @param ProjectConfigurator $configurator The ProjectConfigurator object.
*/
function __construct(AbstractSAXParser $parser, ProjectConfigurator $configurator) {
$this->configurator = $configurator;
parent::__construct($parser, $this);
}
/**
* Kick off a custom action for a start element tag.
*
* The root element of our buildfile is the &lt;project&gt; element. The
* root filter handles this element if it occurs, creates ProjectHandler
* to handle any nested tags & attributes of the &lt;project&gt; tag,
* and calls init.
*
* @param string $tag The xml tagname
* @param array $attrs The attributes of the tag
* @throws ExpatParseException if the first element within our build file
* is not the &gt;project&lt; element
*/
function startElement($tag, $attrs) {
if ($tag === "project") {
$ph = new ProjectHandler($this->parser, $this, $this->configurator);
$ph->init($tag, $attrs);
} else {
throw new ExpatParseException("Unexpected tag <$tag> in top-level of build file.", $this->parser->getLocation());
}
}
}

View file

@ -0,0 +1,180 @@
<?php
/*
* $Id: TargetHandler.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/parser/AbstractHandler.php';
/**
* The target handler class.
*
* This class handles the occurance of a <target> tag and it's possible
* nested tags (datatypes and tasks).
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @package phing.parser
*/
class TargetHandler extends AbstractHandler {
/**
* Reference to the target object that represents the currently parsed
* target.
* @var object the target instance
*/
private $target;
/**
* The phing project configurator object
* @var ProjectConfigurator
*/
private $configurator;
/**
* Constructs a new TargetHandler
*
* @param object the ExpatParser object
* @param object the parent handler that invoked this handler
* @param object the ProjectConfigurator object
*/
function __construct(AbstractSAXParser $parser, AbstractHandler $parentHandler, ProjectConfigurator $configurator) {
parent::__construct($parser, $parentHandler);
$this->configurator = $configurator;
}
/**
* Executes initialization actions required to setup the data structures
* related to the tag.
* <p>
* This includes:
* <ul>
* <li>creation of the target object</li>
* <li>calling the setters for attributes</li>
* <li>adding the target to the project</li>
* <li>adding a reference to the target (if id attribute is given)</li>
* </ul>
*
* @param string the tag that comes in
* @param array attributes the tag carries
* @throws ExpatParseException if attributes are incomplete or invalid
*/
function init($tag, $attrs) {
$name = null;
$depends = "";
$ifCond = null;
$unlessCond = null;
$id = null;
$description = null;
foreach($attrs as $key => $value) {
if ($key==="name") {
$name = (string) $value;
} else if ($key==="depends") {
$depends = (string) $value;
} else if ($key==="if") {
$ifCond = (string) $value;
} else if ($key==="unless") {
$unlessCond = (string) $value;
} else if ($key==="id") {
$id = (string) $value;
} else if ($key==="description") {
$description = (string)$value;
} else {
throw new ExpatParseException("Unexpected attribute '$key'", $this->parser->getLocation());
}
}
if ($name === null) {
throw new ExpatParseException("target element appears without a name attribute", $this->parser->getLocation());
}
// shorthand
$project = $this->configurator->project;
// check to see if this target is a dup within the same file
if (isset($this->configurator->getCurrentTargets[$name])) {
throw new BuildException("Duplicate target: $targetName",
$this->parser->getLocation());
}
$this->target = new Target();
$this->target->setName($name);
$this->target->setIf($ifCond);
$this->target->setUnless($unlessCond);
$this->target->setDescription($description);
// take care of dependencies
if (strlen($depends) > 0) {
$this->target->setDepends($depends);
}
$usedTarget = false;
// check to see if target with same name is already defined
$projectTargets = $project->getTargets();
if (isset($projectTargets[$name])) {
$project->log("Already defined in main or a previous import, " .
"ignore {$name}", Project::MSG_VERBOSE);
} else {
$project->addTarget($name, $this->target);
if ($id !== null && $id !== "") {
$project->addReference($id, $this->target);
}
$usedTarget = true;
}
if ($this->configurator->isIgnoringProjectTag() &&
$this->configurator->getCurrentProjectName() != null &&
strlen($this->configurator->getCurrentProjectName()) != 0) {
// In an impored file (and not completely
// ignoring the project tag)
$newName = $this->configurator->getCurrentProjectName() . "." . $name;
if ($usedTarget) {
// clone needs to make target->children a shared reference
$newTarget = clone $this->target;
} else {
$newTarget = $this->target;
}
$newTarget->setName($newName);
$ct = $this->configurator->getCurrentTargets();
$ct[$newName] = $newTarget;
$project->addTarget($newName, $newTarget);
}
}
/**
* Checks for nested tags within the current one. Creates and calls
* handlers respectively.
*
* @param string the tag that comes in
* @param array attributes the tag carries
*/
function startElement($name, $attrs) {
// shorthands
$project = $this->configurator->project;
$types = $project->getDataTypeDefinitions();
if (isset($types[$name])) {
$th = new DataTypeHandler($this->parser, $this, $this->configurator, $this->target);
$th->init($name, $attrs);
} else {
$tmp = new TaskHandler($this->parser, $this, $this->configurator, $this->target, null, $this->target);
$tmp->init($name, $attrs);
}
}
}

View file

@ -0,0 +1,234 @@
<?php
/*
* $Id: TaskHandler.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/UnknownElement.php';
/**
* The task handler class.
*
* This class handles the occurance of a <task> tag and it's possible
* nested tags (datatypes and tasks) that may be unknown off bat and are
* initialized on the fly.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright <EFBFBD> 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @package phing.parser
*/
class TaskHandler extends AbstractHandler {
/**
* Reference to the target object that contains the currently parsed
* task
* @var object the target instance
*/
private $target;
/**
* Reference to the target object that represents the currently parsed
* target. This must not necessarily be a target, hence extra variable.
* @var object the target instance
*/
private $container;
/**
* Reference to the task object that represents the currently parsed
* target.
* @var Task
*/
private $task;
/**
* Wrapper for the parent element, if any. The wrapper for this
* element will be added to this wrapper as a child.
* @var RuntimeConfigurable
*/
private $parentWrapper;
/**
* Wrapper for this element which takes care of actually configuring
* the element, if this element is contained within a target.
* Otherwise the configuration is performed with the configure method.
* @see ProjectHelper::configure(Object,AttributeList,Project)
*/
private $wrapper;
/**
* The phing project configurator object
* @var ProjectConfigurator
*/
private $configurator;
/**
* Constructs a new TaskHandler and sets up everything.
*
* @param AbstractSAXParser The ExpatParser object
* @param object $parentHandler The parent handler that invoked this handler
* @param ProjectConfigurator $configurator
* @param TaskContainer $container The container object this task is contained in (null for top-level tasks).
* @param RuntimeConfigurable $parentWrapper Wrapper for the parent element, if any.
* @param Target $target The target object this task is contained in (null for top-level tasks).
*/
function __construct(AbstractSAXParser $parser, $parentHandler, ProjectConfigurator $configurator, $container = null, $parentWrapper = null, $target = null) {
parent::__construct($parser, $parentHandler);
if (($container !== null) && !($container instanceof TaskContainer)) {
throw new Exception("Argument expected to be a TaskContainer, got something else");
}
if (($parentWrapper !== null) && !($parentWrapper instanceof RuntimeConfigurable)) {
throw new Exception("Argument expected to be a RuntimeConfigurable, got something else.");
}
if (($target !== null) && !($target instanceof Target)) {
throw new Exception("Argument expected to be a Target, got something else");
}
$this->configurator = $configurator;
$this->container = $container;
$this->parentWrapper = $parentWrapper;
$this->target = $target;
}
/**
* Executes initialization actions required to setup the data structures
* related to the tag.
* <p>
* This includes:
* <ul>
* <li>creation of the task object</li>
* <li>calling the setters for attributes</li>
* <li>adding the task to the container object</li>
* <li>adding a reference to the task (if id attribute is given)</li>
* <li>executing the task if the container is the &lt;project&gt;
* element</li>
* </ul>
*
* @param string $tag The tag that comes in
* @param array $attrs Attributes the tag carries
* @throws ExpatParseException if attributes are incomplete or invalid
*/
function init($tag, $attrs) {
// shorthands
try {
$configurator = $this->configurator;
$project = $this->configurator->project;
$this->task = $project->createTask($tag);
} catch (BuildException $be) {
// swallow here, will be thrown again in
// UnknownElement->maybeConfigure if the problem persists.
print("Swallowing exception: ".$be->getMessage() . "\n");
}
// the task is not known of bat, try to load it on thy fly
if ($this->task === null) {
$this->task = new UnknownElement($tag);
$this->task->setProject($project);
$this->task->setTaskType($tag);
$this->task->setTaskName($tag);
}
// add file position information to the task (from parser)
// should be used in task exceptions to provide details
$this->task->setLocation($this->parser->getLocation());
$configurator->configureId($this->task, $attrs);
if ($this->container) {
$this->container->addTask($this->task);
}
// Top level tasks don't have associated targets
// FIXME: if we do like Ant 1.6 and create an implicitTarget in the projectconfigurator object
// then we don't need to check for null here ... but there's a lot of stuff that will break if we
// do that at this point.
if ($this->target !== null) {
$this->task->setOwningTarget($this->target);
$this->task->init();
$this->wrapper = $this->task->getRuntimeConfigurableWrapper();
$this->wrapper->setAttributes($attrs);
/*
Commenting this out as per thread on Premature configurate of ReuntimeConfigurables
with Matthias Pigulla: http://phing.tigris.org/servlets/ReadMsg?list=dev&msgNo=251
if ($this->parentWrapper !== null) { // this may not make sense only within this if-block, but it
// seems to address current use cases adequately
$this->parentWrapper->addChild($this->wrapper);
}
*/
} else {
$this->task->init();
$configurator->configure($this->task, $attrs, $project);
}
}
/**
* Executes the task at once if it's directly beneath the <project> tag.
*/
protected function finished() {
if ($this->task !== null && $this->target === null && $this->container === null) {
try {
$this->task->perform();
} catch (Exception $e) {
$this->task->log($e->getMessage(), Project::MSG_ERR);
throw $e;
}
}
}
/**
* Handles character data.
*
* @param string $data The CDATA that comes in
*/
function characters($data) {
if ($this->wrapper === null) {
$configurator = $this->configurator;
$project = $this->configurator->project;
try { // try
$configurator->addText($project, $this->task, $data);
} catch (BuildException $exc) {
throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation());
}
} else {
$this->wrapper->addText($data);
}
}
/**
* Checks for nested tags within the current one. Creates and calls
* handlers respectively.
*
* @param string $name The tag that comes in
* @param array $attrs Attributes the tag carries
*/
function startElement($name, $attrs) {
$project = $this->configurator->project;
if ($this->task instanceof TaskContainer) {
//print("TaskHandler::startElement() (TaskContainer) name = $name, attrs = " . implode(",",$attrs) . "\n");
$th = new TaskHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
$th->init($name, $attrs);
} else {
//print("TaskHandler::startElement() name = $name, attrs = " . implode(",",$attrs) . "\n");
$tmp = new NestedElementHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
$tmp->init($name, $attrs);
}
}
}