-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7422a83
commit c36de59
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
namespace Maslosoft\Signals\Factories; | ||
|
||
use Maslosoft\Signals\Signal; | ||
|
||
/** | ||
* FilterFactory | ||
* | ||
* @author Piotr Maselkowski <pmaselkowski at gmail.com> | ||
*/ | ||
class FilterFactory | ||
{ | ||
|
||
public static function create(Signal $signal, $interface) | ||
{ | ||
$filters = []; | ||
$di = $signal->getDi(); | ||
foreach ($signal->filters as $config) | ||
{ | ||
$filter = $di->apply($config); | ||
if (!$filter instanceof $interface) | ||
{ | ||
continue; | ||
} | ||
$filters[] = $filter; | ||
} | ||
return $filters; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
namespace Maslosoft\Signals\Helpers; | ||
|
||
use Maslosoft\Signals\Interfaces\PostFilterInterface; | ||
use Maslosoft\Signals\Interfaces\SignalInterface; | ||
use Maslosoft\Signals\Signal; | ||
|
||
/** | ||
* PostFilter | ||
* | ||
* @author Piotr Maselkowski <pmaselkowski at gmail.com> | ||
*/ | ||
class PostFilter | ||
{ | ||
|
||
public static function filter(Signal $signals, $injected, SignalInterface $signal) | ||
{ | ||
$preFilters = $signals->getFilters(PostFilterInterface::class); | ||
foreach ($preFilters as $filter) | ||
{ | ||
if (!$filter->filter($injected, $signal)) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
namespace Maslosoft\Signals\Helpers; | ||
|
||
use Maslosoft\Signals\Interfaces\PreFilterInterface; | ||
use Maslosoft\Signals\Interfaces\SignalInterface; | ||
use Maslosoft\Signals\Signal; | ||
|
||
/** | ||
* PreFilter | ||
* | ||
* @author Piotr Maselkowski <pmaselkowski at gmail.com> | ||
*/ | ||
class PreFilter | ||
{ | ||
|
||
public static function filter(Signal $signals, $fqn, SignalInterface $signal) | ||
{ | ||
$preFilters = $signals->getFilters(PreFilterInterface::class); | ||
foreach ($preFilters as $filter) | ||
{ | ||
if (!$filter->filter($fqn, $signal)) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
namespace Maslosoft\Signals\Interfaces; | ||
|
||
/** | ||
* | ||
* @author Piotr Maselkowski <pmaselkowski at gmail.com> | ||
*/ | ||
interface FilterInterface | ||
{ | ||
|
||
} |