diff --git a/classes/phing/tasks/defaults.properties b/classes/phing/tasks/defaults.properties index b0db9a39a3..a3d55d2d8f 100644 --- a/classes/phing/tasks/defaults.properties +++ b/classes/phing/tasks/defaults.properties @@ -186,6 +186,7 @@ pathtofileset=phing.tasks.ext.property.PathToFileSet propertycopy=phing.tasks.ext.property.PropertyCopy propertyregex=phing.tasks.ext.property.RegexTask propertyselector=phing.tasks.ext.property.PropertySelector +urlencode=phing.tasks.ext.property.URLEncodeTask var=phing.tasks.ext.property.Variable sortlist=phing.tasks.ext.property.SortList zsdtvalidate=phing.tasks.ext.zendserverdeploymenttool.zsdtValidateTask diff --git a/classes/phing/tasks/ext/property/URLEncodeTask.php b/classes/phing/tasks/ext/property/URLEncodeTask.php new file mode 100644 index 0000000000..3d2d060a61 --- /dev/null +++ b/classes/phing/tasks/ext/property/URLEncodeTask.php @@ -0,0 +1,71 @@ +. + */ + +/** + * @author Siad Ardroumli + * @package phing.tasks.ext.property + */ +class URLEncodeTask extends AbstractPropertySetterTask +{ + /** @var string */ + private $value = ''; + + /** @var Reference */ + private $ref; + + public function setValue(string $value) + { + $this->value = urlencode($value); + } + + public function getValue(Project $p): string + { + if ($this->ref !== null) { + $this->setValue($this->ref->getReferencedObject($p)); + } + + return $this->value; + } + + public function setRefid(Reference $ref) + { + $this->ref = $ref; + } + + public function __toString() + { + return $this->value; + } + + protected function validate() + { + parent::validate(); + if ($this->value === null && $this->ref === null) { + throw new BuildException('You must specify value or refid with the name attribute', + $this->getLocation()); + } + } + + public function main() + { + parent::validate(); + $val = $this->getValue($this->getProject()); + $this->setPropertyValue($val); + } +} diff --git a/docs/guide/en/source/appendixes/optionaltasks.xml b/docs/guide/en/source/appendixes/optionaltasks.xml index b029cf10df..91d2985c61 100644 --- a/docs/guide/en/source/appendixes/optionaltasks.xml +++ b/docs/guide/en/source/appendixes/optionaltasks.xml @@ -10448,6 +10448,66 @@ description="Measures the size of the project and counts the tests"> casesensitive="false" /> + + URLEncodeTask + The URLEncode task will encode a given property for use within a a URL string. This value which is + actually set will be encoded via the urlencode() function. Typically, you must do this + for all parameter values within a URL. + + + Attributes + + + + + + + + + Name + Type + Description + Default + Required + + + + + property + String + The name of the property to set. + n/a + Yes + + + override + Boolean + If the property is already set, should we change it's value. Can be true or false + false + No + + + value + String + The value of the property. + n/a + No, if refid is specified + + + refid + String + The id of a saved reference whose value will be the value of the property. + n/a + No, if value is specified + + + +
+ + Example + <urlencode name="file.location" value="C:\\wwwhome\\my reports\\report.xml" /> + +
rSTTask diff --git a/etc/phing-grammar.rng b/etc/phing-grammar.rng index f9b6fcd9fb..48798cb0cb 100644 --- a/etc/phing-grammar.rng +++ b/etc/phing-grammar.rng @@ -197,6 +197,7 @@ + @@ -5500,6 +5501,23 @@ + + + + + + + + + + + + + + + + + diff --git a/test/classes/phing/tasks/ext/property/URLEncodeTaskTest.php b/test/classes/phing/tasks/ext/property/URLEncodeTaskTest.php new file mode 100644 index 0000000000..bc78201a17 --- /dev/null +++ b/test/classes/phing/tasks/ext/property/URLEncodeTaskTest.php @@ -0,0 +1,46 @@ +. + */ + +/** + * Tests the URLEncode Task + * + * @author Siad Ardroumli + * @package phing.tasks.ext.property + */ +class URLEncodeTaskTest extends BuildFileTest +{ + public function setUp() + { + $this->configureProject( + PHING_TEST_BASE . '/etc/tasks/ext/property/URLEncodeTaskTest.xml' + ); + } + + public function testURLEncodeTask() + { + $this->executeTarget(__FUNCTION__); + $this->assertPropertyEquals('test1', '%C3%B6%C3%B6%C3%B6%C3%B6'); + } + + public function testRefid() + { + $this->executeTarget(__FUNCTION__); + $this->assertPropertyEquals('test2', '%C3%BC%C3%BC%C3%BC%C3%BC'); + } +} diff --git a/test/etc/tasks/ext/property/URLEncodeTaskTest.xml b/test/etc/tasks/ext/property/URLEncodeTaskTest.xml new file mode 100644 index 0000000000..a86b072269 --- /dev/null +++ b/test/etc/tasks/ext/property/URLEncodeTaskTest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + +