Skip to content

Commit

Permalink
+~ Filter/Sorter draft #15 #21
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaselkowski committed Feb 1, 2016
1 parent 7422a83 commit c36de59
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Factories/FilterFactory.php
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;
}

}
36 changes: 36 additions & 0 deletions src/Helpers/PostFilter.php
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;
}

}
36 changes: 36 additions & 0 deletions src/Helpers/PreFilter.php
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;
}

}
18 changes: 18 additions & 0 deletions src/Interfaces/FilterInterface.php
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
{

}

0 comments on commit c36de59

Please sign in to comment.