diff --git a/src/Factories/FilterFactory.php b/src/Factories/FilterFactory.php new file mode 100644 index 0000000..1850812 --- /dev/null +++ b/src/Factories/FilterFactory.php @@ -0,0 +1,37 @@ + + */ +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; + } + +} diff --git a/src/Helpers/PostFilter.php b/src/Helpers/PostFilter.php new file mode 100644 index 0000000..be20817 --- /dev/null +++ b/src/Helpers/PostFilter.php @@ -0,0 +1,36 @@ + + */ +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; + } + +} diff --git a/src/Helpers/PreFilter.php b/src/Helpers/PreFilter.php new file mode 100644 index 0000000..5d6f768 --- /dev/null +++ b/src/Helpers/PreFilter.php @@ -0,0 +1,36 @@ + + */ +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; + } + +} diff --git a/src/Interfaces/FilterInterface.php b/src/Interfaces/FilterInterface.php new file mode 100644 index 0000000..f17cbd7 --- /dev/null +++ b/src/Interfaces/FilterInterface.php @@ -0,0 +1,18 @@ + + */ +interface FilterInterface +{ + +}