TaskAdapter.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * $Id: TaskAdapter.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/Task.php';
  22. /**
  23. * Use introspection to "adapt" an arbitrary ( not extending Task, but with
  24. * similar patterns).
  25. *
  26. * @author Andreas Aderhold <andi@binarycloud.com>
  27. * @copyright © 2001,2002 THYRELL. All rights reserved
  28. * @version $Revision: 905 $
  29. * @package phing
  30. */
  31. class TaskAdapter extends Task {
  32. /** target object */
  33. private $proxy;
  34. /**
  35. * Main entry point.
  36. * @return void
  37. */
  38. function main() {
  39. if (method_exists($this->proxy, "setProject")) {
  40. try { // try to set project
  41. $this->proxy->setProject($this->project);
  42. } catch (Exception $ex) {
  43. $this->log("Error setting project in " . get_class($this->proxy) . Project::MSG_ERR);
  44. throw new BuildException($ex);
  45. }
  46. } else {
  47. throw new Exception("Error setting project in class " . get_class($this->proxy));
  48. }
  49. if (method_exists($this->proxy, "main")) {
  50. try { //try to call main
  51. $this->proxy->main($this->project);
  52. } catch (Exception $ex) {
  53. $this->log("Error in " . get_class($this->proxy), Project::MSG_ERR);
  54. throw new BuildException($ex->getMessage());
  55. }
  56. } else {
  57. throw new BuildException("Your task-like class '" . get_class($this->proxy) ."' does not have a main() method");
  58. }
  59. }
  60. /**
  61. * Set the target object.
  62. * @param object $o
  63. * @return void
  64. */
  65. function setProxy($o) {
  66. $this->proxy = $o;
  67. }
  68. /**
  69. * Gets the target object.
  70. * @return object
  71. */
  72. function getProxy() {
  73. return $this->proxy;
  74. }
  75. }