EchoTask.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /*
  3. * $Id: EchoTask.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. include_once 'phing/Task.php';
  22. /**
  23. * Echos a message to the logging system or to a file
  24. *
  25. * @author Michiel Rook <michiel.rook@gmail.com>
  26. * @author Andreas Aderhold, andi@binarycloud.com
  27. * @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
  28. * @package phing.tasks.system
  29. */
  30. class EchoTask extends Task {
  31. protected $msg = "";
  32. protected $file = "";
  33. protected $append = false;
  34. protected $level = "info";
  35. function main() {
  36. switch ($this->level)
  37. {
  38. case "error": $loglevel = Project::MSG_ERR; break;
  39. case "warning": $loglevel = Project::MSG_WARN; break;
  40. case "info": $loglevel = Project::MSG_INFO; break;
  41. case "verbose": $loglevel = Project::MSG_VERBOSE; break;
  42. case "debug": $loglevel = Project::MSG_DEBUG; break;
  43. }
  44. if (empty($this->file))
  45. {
  46. $this->log($this->msg, $loglevel);
  47. }
  48. else
  49. {
  50. if ($this->append)
  51. {
  52. $handle = fopen($this->file, "a");
  53. }
  54. else
  55. {
  56. $handle = fopen($this->file, "w");
  57. }
  58. fwrite($handle, $this->msg);
  59. fclose($handle);
  60. }
  61. }
  62. /** setter for file */
  63. function setFile($file)
  64. {
  65. $this->file = (string) $file;
  66. }
  67. /** setter for level */
  68. function setLevel($level)
  69. {
  70. $this->level = (string) $level;
  71. }
  72. /** setter for append */
  73. function setAppend($append)
  74. {
  75. $this->append = $append;
  76. }
  77. /** setter for message */
  78. function setMsg($msg) {
  79. $this->setMessage($msg);
  80. }
  81. /** alias setter */
  82. function setMessage($msg) {
  83. $this->msg = (string) $msg;
  84. }
  85. /** Supporting the <echo>Message</echo> syntax. */
  86. function addText($msg)
  87. {
  88. $this->msg = (string) $msg;
  89. }
  90. }