# |
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: |
# |
Jul 19th 2017, 15:51 |
jeremyharris |
inoas yes I’m afraid of the verbosity as well. we’ve discussed validating like that, which I’m more in support for, however it doesn’t solve one of the key problems which is misspelled optional *keys* (e.g., cagetory instead of category). In a discussion I actually brought up this simple validation technique and was called out on the misspelled keys problem, something I totally didn’t think about :slightly_smiling_face: |
# |
Jul 19th 2017, 15:51 |
inoas |
set it to warn by default so that developers get notified by default but their apps do not break |
# |
Jul 19th 2017, 15:51 |
inoas |
'warn' and 'exception' |
# |
Jul 19th 2017, 15:51 |
inoas |
dereuromark https://github.com/cakephp/cakephp/issues/10723#issuecomment-316429214 - opt-in flag I'd do 3 states: 'ignore', |
# |
Jul 19th 2017, 15:35 |
inoas |
I am not a pro on php errors but maybe that means it cannot find I18n at all |
# |
Jul 19th 2017, 15:35 |
inoas |
check I18n if there is a insertArgs at all |
# |
Jul 19th 2017, 15:35 |
inoas |
and updating cakephp to 2.9 |
# |
Jul 19th 2017, 15:35 |
inoas |
and setting up a good environment with the recommended php version (like 5.6) there |
# |
Jul 19th 2017, 15:34 |
inoas |
domgeek what I would try is cakebox or homestead or puphpet.net |
# |
Jul 19th 2017, 15:34 |
inoas |
for anything else I like the new setters/getters |