Skip to content

Commit

Permalink
Improved DX on adding path filter to file extractors
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Sep 26, 2024
1 parent 7f5b831 commit db9a18b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/core/etl/src/Flow/ETL/Extractor/FileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

interface FileExtractor
{
public function addFilter(Filter $filter) : void;
public function withPathFilter(Filter $filter) : self;

/**
* @deprecated Use withPathFilter instead
*/
public function addFilter(Filter $filter) : self;

public function filter() : Filter;

Expand Down
24 changes: 17 additions & 7 deletions src/core/etl/src/Flow/ETL/Extractor/PathFiltering.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,35 @@ trait PathFiltering
{
private ?Filter $filter = null;

public function addFilter(Filter $filter) : void
/**
* @deprecated Use withPathFilter instead
*/
public function addFilter(Filter $filter) : self
{
return $this->withPathFilter($filter);
}

public function filter() : Filter
{
return $this->filter ?? new OnlyFiles();
}

public function withPathFilter(Filter $filter) : self
{
if ($this->filter === null) {
$this->filter = $filter;

return;
return $this;
}

if ($this->filter instanceof Filters) {
$this->filter = $this->filter->add($filter);

return;
return $this;
}

$this->filter = new Filters($this->filter, $filter);
}

public function filter() : Filter
{
return $this->filter ?? new OnlyFiles();
return $this;
}
}

0 comments on commit db9a18b

Please sign in to comment.