DefineTask.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. require_once 'phing/Task.php';
  10. /**
  11. * Defines a constant using PHP define() method.
  12. *
  13. * This is handy if you want to initialize a constant to a value that is available only as build properties.
  14. */
  15. class DefineTask extends Task {
  16. /**
  17. * @var string
  18. */
  19. private $name;
  20. /**
  21. * @var string
  22. */
  23. private $value;
  24. /**
  25. * Sets the name for the constant.
  26. * @param string $v
  27. */
  28. public function setName($v) {
  29. $this->name = $v;
  30. }
  31. /**
  32. * Sets the value for the constant.
  33. * @param string $v
  34. */
  35. public function setValue($v) {
  36. $this->value = $v;
  37. }
  38. public function main() {
  39. if (!isset($this->name) || !isset($this->value)) {
  40. throw new BuildException("Both name and value params are required.", $this->getLocation());
  41. }
  42. $const = strtoupper($this->name);
  43. if (defined($const)) {
  44. $this->log("The constant $const has already been defined!", Project::MSG_ERR);
  45. } else {
  46. define($const, $this->value);
  47. $this->log("Defined $const with value " . var_export($this->value, true), Project::MSG_INFO);
  48. }
  49. }
  50. }