88use Kettasoft \Filterable \Support \Payload ;
99use Illuminate \Support \Traits \ForwardsCalls ;
1010use Kettasoft \Filterable \Engines \Foundation \Engine ;
11- use Kettasoft \Filterable \Support \ConditionNormalizer ;
1211use Kettasoft \Filterable \Engines \Foundation \Attributes \AttributeContext ;
1312use Kettasoft \Filterable \Engines \Foundation \Attributes \AttributePipeline ;
13+ use Kettasoft \Filterable \Engines \Foundation \Clause ;
14+ use Kettasoft \Filterable \Engines \Foundation \ClauseFactory ;
15+ use Kettasoft \Filterable \Engines \Foundation \Parsers \Dissector ;
1416
1517class Invokeable extends Engine
1618{
@@ -37,40 +39,42 @@ public function execute(Builder $builder): Builder
3739 {
3840 $ this ->builder = $ builder ;
3941
42+ // Set allowed fields from $filters property automatically.
43+ $ this ->context ->setAllowedFields ($ this ->context ->getFilterAttributes ());
44+
4045 foreach ($ this ->context ->getFilterAttributes () as $ filter ) {
41- $ value = $ this ->context ->getRequest ()->get ($ filter );
4246
43- if (($ this ->context ->hasIgnoredEmptyValues () || config ('filterable.engines.invokable.ignore_empty_values ' )) && !$ value ) {
47+ $ dissector = Dissector::parse ($ this ->context ->getRequest ()->get ($ filter ), $ this ->defaultOperator ());
48+
49+ $ payload = new Payload ($ filter , $ dissector ->operator , $ this ->sanitizeValue ($ filter , $ dissector ->value ), $ dissector ->value );
50+
51+ $ clause = (new ClauseFactory ($ this ))->make ($ payload );
52+
53+ if (($ this ->context ->hasIgnoredEmptyValues () || config ('filterable.engines.invokable.ignore_empty_values ' )) && !$ clause ->value ) {
4454 continue ;
4555 }
4656
4757 $ method = $ this ->getMethodName ($ filter );
4858
49- $ this ->initializeFilters ($ filter , $ method , $ value );
59+ $ this ->initializeFilters ($ filter , $ method , $ clause -> getPayload () );
5060 }
5161
5262 return $ this ->builder ;
5363 }
5464
5565 /**
5666 * Initialize the filter methods and resolve value.
67+ * @param string $key
5768 * @param string $method
58- * @param mixed $value
69+ * @param Payload $payload
5970 * @return void
6071 */
61- protected function initializeFilters (string $ key , string $ method , mixed $ value ): void
72+ protected function initializeFilters (string $ key , string $ method , Payload $ payload ): void
6273 {
63- $ clause = ConditionNormalizer::normalize ($ value , '= ' );
64-
65- $ operator = $ clause ['operator ' ];
66- $ val = $ clause ['value ' ];
67-
6874 if (! method_exists ($ this ->context , $ method )) {
6975 return ;
7076 }
7177
72- $ payload = new Payload ($ key , $ operator , $ this ->sanitizeValue ($ key , $ val ), $ val );
73-
7478 $ attrContext = new AttributeContext (
7579 $ this ->builder ,
7680 $ payload ,
0 commit comments