/build/ext/phing/classes/phing/filters/ExpandProperties.php

http://github.com/alexgorbatchev/SyntaxHighlighter · PHP · 82 lines · 19 code · 11 blank · 52 comment · 1 complexity · c72cda312670ab5a1a39c644ddc33558 MD5 · raw file

  1. <?php
  2. /*
  3. * $Id: ExpandProperties.php 325 2007-12-20 15:44:58Z hans $
  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/filters/BaseFilterReader.php';
  22. include_once 'phing/filters/ChainableReader.php';
  23. /**
  24. * Expands Phing Properties, if any, in the data.
  25. * <p>
  26. * Example:<br>
  27. * <pre><expandproperties/></pre>
  28. * Or:
  29. * <pre><filterreader classname="phing.filters.ExpandProperties'/></pre>
  30. *
  31. * @author Yannick Lecaillez <yl@seasonfive.com>
  32. * @author Hans Lellelid <hans@xmpl.org>
  33. * @version $Revision: 1.6 $
  34. * @see BaseFilterReader
  35. * @package phing.filters
  36. */
  37. class ExpandProperties extends BaseFilterReader implements ChainableReader {
  38. /**
  39. * Returns the filtered stream.
  40. * The original stream is first read in fully, and the Phing properties are expanded.
  41. *
  42. * @return mixed the filtered stream, or -1 if the end of the resulting stream has been reached.
  43. *
  44. * @exception IOException if the underlying stream throws an IOException
  45. * during reading
  46. */
  47. function read($len = null) {
  48. $buffer = $this->in->read($len);
  49. if($buffer === -1) {
  50. return -1;
  51. }
  52. $project = $this->getProject();
  53. $buffer = ProjectConfigurator::replaceProperties($project, $buffer, $project->getProperties());
  54. return $buffer;
  55. }
  56. /**
  57. * Creates a new ExpandProperties filter using the passed in
  58. * Reader for instantiation.
  59. *
  60. * @param object A Reader object providing the underlying stream.
  61. * Must not be <code>null</code>.
  62. *
  63. * @return object A new filter based on this configuration, but filtering
  64. * the specified reader
  65. */
  66. function chain(Reader $reader) {
  67. $newFilter = new ExpandProperties($reader);
  68. $newFilter->setProject($this->getProject());
  69. return $newFilter;
  70. }
  71. }