mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-01-22 20:17:31 +00:00
Split and store the conditions for a filter
This commit is contained in:
parent
af985e8b37
commit
1578cc81a3
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Opdavies\GmailFilterBuilder\Model;
|
||||
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
|
||||
class Filter
|
||||
{
|
||||
/**
|
||||
|
@ -9,6 +11,14 @@ class Filter
|
|||
*/
|
||||
private $properties = [];
|
||||
|
||||
/** @var Collection */
|
||||
private $conditions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->conditions = new Collection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
|
@ -26,6 +36,10 @@ class Filter
|
|||
{
|
||||
$this->properties['hasTheWord'] = $value;
|
||||
|
||||
$this->conditions = $this->conditions->merge(
|
||||
new Collection(preg_split('/\s+/', $value))
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -271,4 +285,9 @@ class Filter
|
|||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
public function getConditions(): Collection
|
||||
{
|
||||
return $this->conditions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,4 +320,14 @@ class FilterTest extends TestCase
|
|||
->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function conditions_can_be_split_and_stored()
|
||||
{
|
||||
$filter = Filter::create()
|
||||
->has('to:me@example.com subject:Something')
|
||||
->archive();
|
||||
|
||||
$this->assertCount(2, $filter->getConditions());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue