mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-02-02 08:57:31 +00:00
Add implode method
Ensure that imploded values are wrapped with the correct prefix and suffix, and have the correct separators.
This commit is contained in:
parent
6ccf830d23
commit
f32d4a5139
|
@ -63,7 +63,7 @@ class Builder
|
|||
private function buildProperty($value, $key)
|
||||
{
|
||||
if (collect(['from', 'to'])->contains($key)) {
|
||||
$value = collect($value)->implode('|');
|
||||
$value = $this->implode($value);
|
||||
}
|
||||
|
||||
return vsprintf("<apps:property name='%s' value='%s'/>", [
|
||||
|
@ -71,4 +71,12 @@ class Builder
|
|||
htmlentities($value),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implode values with the appropriate prefix, suffix and separator.
|
||||
*/
|
||||
private function implode($value, $separator = '|')
|
||||
{
|
||||
return sprintf('(%s)', collect($value)->implode($separator));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class BuilderTest extends TestCase
|
|||
|
||||
$expected = <<<EOF
|
||||
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>
|
||||
<entry><apps:property name='from' value='foo@example.com|test@example.com'/><apps:property name='label' value='Some label'/><apps:property name='shouldArchive' value='true'/></entry>
|
||||
<entry><apps:property name='from' value='(foo@example.com|test@example.com)'/><apps:property name='label' value='Some label'/><apps:property name='shouldArchive' value='true'/></entry>
|
||||
<entry><apps:property name='hasTheWord' value='from:bar@example.com'/><apps:property name='shouldStar' value='true'/><apps:property name='shouldAlwaysMarkAsImportant' value='true'/></entry>
|
||||
</feed>
|
||||
EOF;
|
||||
|
|
Loading…
Reference in a new issue