Finish Builder

This commit is contained in:
Oliver Davies 2017-12-30 10:28:19 +00:00
parent 922d4af8c0
commit 02dddbdaf6
2 changed files with 65 additions and 22 deletions

View file

@ -12,5 +12,44 @@ class Builder
public function build()
{
$prefix = "<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>";
$suffix = '</feed>';
$xml = collect($this->filters)->map(function ($items) {
return $this->buildEntry($items);
})->implode('');
return $prefix . $xml . $suffix;
}
/**
* @param array $items
*
* @return string
*/
private function buildEntry(array $items)
{
$entry = collect($items)->map(function ($value, $key) {
return $this->buildProperty($value, $key);
})->implode('');
return "<entry>{$entry}</entry>";
}
/**
* Build XML for a property.
*
* @param string $value
* @param string $key
*
* @return string
*/
private function buildProperty($value, $key)
{
if ($key == 'from') {
$value = collect($value)->implode('|');
}
return "<apps:property name='{$key}' value='{$value}'/>";
}
}