# |
Jul 19th 2017, 16:02 |
jeremyharris |
a PR might help others understand what you’re getting at :slightly_smiling_face: although, don’t get discouraged if it’s not accepted. It would be a PR a bit ahead of the finished discussion |
# |
Jul 19th 2017, 16:02 |
inoas |
basically implement Options::validate() (returns true/false) and Options::validateOrFail() |
# |
Jul 19th 2017, 16:01 |
inoas |
jeremyharris while my coding foo is mediocre if there is enough support in the core to consider this I would be willing to create a PR |
# |
Jul 19th 2017, 16:00 |
inoas |
but rather real parameters |
# |
Jul 19th 2017, 16:00 |
inoas |
but I think if you want that you should not use $options |
# |
Jul 19th 2017, 16:00 |
inoas |
the only gripe is, it does not do IDE stuff very well |
# |
Jul 19th 2017, 15:59 |
jeremyharris |
I think i’m on the same page now |
# |
Jul 19th 2017, 15:59 |
inoas |
however you are then "on your own" (aka as $options are right now) |
# |
Jul 19th 2017, 15:59 |
inoas |
that should be still possible through using type array and making it optional |
# |
Jul 19th 2017, 15:58 |
jeremyharris |
I prefer that idea to the object one. I wonder if someone will come up with a use case where they want to provide an N amount of custom keys that aren’t defined in the schema, but still validate other options |
# |
Jul 19th 2017, 15:58 |
inoas |
basically take a look at function overloading in elixir ... pattern match against different sets of parameters |
# |
Jul 19th 2017, 15:58 |
inoas |
but not when calling the function |
# |
Jul 19th 2017, 15:57 |
inoas |
there is verbosity in the validator |
# |
Jul 19th 2017, 15:57 |
inoas |
that usage should be disencouraged as much as possible |
# |
Jul 19th 2017, 15:57 |
inoas |
['types'] => ['array', 'string'], ['isOptional' => true] |
# |
Jul 19th 2017, 15:57 |
jeremyharris |
hmm, so kind of how shells work atm |
# |
Jul 19th 2017, 15:57 |
inoas |
well you would need to list all, or mark that as optional |
# |
Jul 19th 2017, 15:56 |
jeremyharris |
so you can’t have option arrays that accept user defined options, like in customer finders |
# |
Jul 19th 2017, 15:56 |
inoas |
and you would build the array but before it is consumed you would validateOrFail() |
# |
Jul 19th 2017, 15:56 |
inoas |
yes obviously |
# |
Jul 19th 2017, 15:56 |
inoas |
well the latter Elm like exception could work ;) |
# |
Jul 19th 2017, 15:56 |
jeremyharris |
oh so the validator rejects all keys that aren’t in the schema? |
# |
Jul 19th 2017, 15:56 |
inoas |
(did you mean category ;) |
# |
Jul 19th 2017, 15:55 |
inoas |
'cagetory' hash key exists but was not expected |
# |
Jul 19th 2017, 15:55 |
jeremyharris |
how would you alert the dev that this is a problem: foo(‘argAhere’, ‘argBhere’, [‘cagetory’ => ‘foo’, ‘link’ => [‘action’ => ‘bar’], ‘filters’ => ‘onSale’]); |
# |
Jul 19th 2017, 15:55 |
inoas |
"consumable" |
# |
Jul 19th 2017, 15:55 |
inoas |
it just makes sure the $options you pass to a method/function are processable/valid datatype |
# |
Jul 19th 2017, 15:54 |
inoas |
it allows for deeply nested structures, optionality, default values, data type checks ... sure it doesn't (and should not do) application state checks (does this id exist in the database) |
# |
Jul 19th 2017, 15:54 |
inoas |
https://gist.github.com/ionas/94e961bf414c78362442041081dad3ca lists all the possible options, the mandatory and optional onces... if you specify something other than that you should get an exception |
# |
Jul 19th 2017, 15:53 |
inoas |
and give it another valid data type value |
# |
Jul 19th 2017, 15:53 |
inoas |
as long as you do not accidentially type another valid hash key ;) |
# |
Jul 19th 2017, 15:53 |
inoas |
jeremyharris but it DOES solve the miss-spelling |
# |
Jul 19th 2017, 15:52 |
inoas |
set to throw an exception by default |
# |
Jul 19th 2017, 15:52 |
inoas |
so maybe you are right... bool should do |
# |
Jul 19th 2017, 15:52 |
inoas |
but meh... future apps |
# |
Jul 19th 2017, 15:52 |
inoas |
if you set it to true/exception by default, apps will break |
# |
Jul 19th 2017, 15:52 |
inoas |
if you set it to ignore/false by default people will not notice ;) |
# |
Jul 19th 2017, 15:52 |
dereuromark |
sure |
# |
Jul 19th 2017, 15:52 |
inoas |
well I think the most important thing is to notify the developer that s/he did something wrong |
# |
Jul 19th 2017, 15:51 |
dereuromark |
both meeh |
# |
Jul 19th 2017, 15:51 |
dereuromark |
a bool would suffice IMO :slightly_smiling_face: |