Created
November 11, 2016 19:25
-
-
Save jeffsrepoaccount/03525d2b2ff3432ee31643528c9d8ef9 to your computer and use it in GitHub Desktop.
Retrieves an item from a phing delimited list property by index, or null if index is not set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'phing/Task.php'; | |
/** | |
* Retrieves and sets a property based on the requested key index | |
*/ | |
class ListItemByKeyTask extends Task | |
{ | |
protected $taskname = 'listitembykey'; | |
protected $key; | |
protected $property; | |
protected $returnval; | |
protected $delimeter = ','; | |
public function init() | |
{ | |
} | |
public function main() | |
{ | |
$items = explode($this->delimeter, $this->project->getProperty($this->property)); | |
$key = (int)$this->project->getProperty($this->key); | |
if(isset($items[$key])) { | |
$this->project->setProperty($this->returnval, $items[$key]); | |
} | |
return null; | |
} | |
public function setKey($key) | |
{ | |
$this->key = $key; | |
} | |
public function setProperty($property) | |
{ | |
$this->property = $property; | |
} | |
public function setReturnval($returnVal) | |
{ | |
$this->returnval = $returnVal; | |
} | |
public function setDelimeter($delim) | |
{ | |
$this->delimeter = $delim; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment