Skip to content

Instantly share code, notes, and snippets.

@jeffsrepoaccount
Created November 11, 2016 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffsrepoaccount/03525d2b2ff3432ee31643528c9d8ef9 to your computer and use it in GitHub Desktop.
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.
<?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