mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-09-04 04:35:33 +01:00
Start using Symfony Components
This commit is contained in:
parent
b61178b9b0
commit
bc3dae9c48
9 changed files with 131 additions and 13 deletions
241
src/Model/Filter.php
Normal file
241
src/Model/Filter.php
Normal file
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\GmailFilterBuilder;
|
||||
|
||||
class Filter
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $properties = [];
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function has($value)
|
||||
{
|
||||
$this->properties['hasTheWord'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function hasNot($value)
|
||||
{
|
||||
$this->properties['doesNotHaveTheWord'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $values
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function from($values)
|
||||
{
|
||||
$this->properties['from'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $values
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function to($values)
|
||||
{
|
||||
$this->properties['to'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function subject($subject)
|
||||
{
|
||||
$this->properties['subject'] = $subject;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function hasAttachment()
|
||||
{
|
||||
$this->properties['hasAttachment'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function excludeChats()
|
||||
{
|
||||
$this->properties['excludeChats'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function label($label)
|
||||
{
|
||||
$this->properties['label'] = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function archive()
|
||||
{
|
||||
$this->properties['shouldArchive'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function labelAndArchive($label)
|
||||
{
|
||||
$this->label($label)->archive();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function spam()
|
||||
{
|
||||
$this->properties['shouldSpam'] = 'true';
|
||||
$this->properties['shouldNeverSpam'] = 'false';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function neverSpam()
|
||||
{
|
||||
$this->properties['shouldSpam'] = 'false';
|
||||
$this->properties['shouldNeverSpam'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function trash()
|
||||
{
|
||||
$this->properties['shouldTrash'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
$this->properties['markAsRead'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function star()
|
||||
{
|
||||
$this->properties['shouldStar'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function forward($to)
|
||||
{
|
||||
$this->properties['forwardTo'] = $to;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function important()
|
||||
{
|
||||
$this->properties['shouldAlwaysMarkAsImportant'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function notImportant()
|
||||
{
|
||||
$this->properties['shouldNeverMarkAsImportant'] = 'true';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $category
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function categorise($category)
|
||||
{
|
||||
$this->properties['smartLabelToApply'] = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue