Created Explode Strategy for hydrator#6227
Created Explode Strategy for hydrator#6227ojhaujjwal wants to merge 1 commit intozendframework:masterfrom
Conversation
There was a problem hiding this comment.
This is a general description, it does not describe what this method does.
|
Just trying to break things 😃 $strategy = new ExplodeStrategy();
$strategy->setValueDelimiter(null);
$result = $strategy->hydrate('foo');
// Warning: explode(): Empty delimiter in...$strategy = new ExplodeStrategy();
$strategy->setValueDelimiter('');
$result = $strategy->hydrate('foo');
// Warning: explode(): Empty delimiter in...Explode has a third parameter (http://www.php.net/explode), should that be covered as well? |
|
@Martin-P Thank you for providing the details. |
|
@Martin-P Hey. I have done some changes. Please comment. |
|
Will this PR get merged for 2.4? |
There was a problem hiding this comment.
Not sure if it needs implementation, but should 1 (as a string) be allowed as well?
$strategy->setExplodeLimit('1');There was a problem hiding this comment.
We may use is_numeric instead of is_int.
There was a problem hiding this comment.
is_numeric allows too many things, like e.g. hexadecimal values. If you implement it, ctype_digit is more accurate.
if (!ctype_digit((string) $explodeLimit)) {However ctype_digit does not allow negative values:
var_dump(ctype_digit('-1')); // falseCasting to int could also be an option, but I'm not sure that is the way to do this.
There was a problem hiding this comment.
We need some expert's help.
ping @Ocramius
There was a problem hiding this comment.
You could cast to int and replace the default value of nullwith 0. If you cast everything to int the implementation will be more simple
|
This will need a documentation PR to add it to the list of available implementations |
|
@ojhaujjwal @weierophinney does this seem like a common enough use case to warrant including in core? Just a thought: would it be better to provide a more generalized adapter to |
|
@adamlundrigan One use case is that it can be used in forms to take comma separated input from the user. |
753c990 to
26af277
Compare
…for the `Zend\Stdlib\Hydrator\Strategy` namespace
…he `Zend\Stdlib\Hydrator\Strategy` exceptions
…isallow `null` `$delimiter` in constructor
…valid (not-hydratable) type
… invalid (not-hydratable) type
…hydrate integer/double values
…hydrate integer/double values
…rate()` return values
… to be hydrated by `ExplodeStrategy#hydrate()`
… bijectively
… bijectively
…ertEquals` wherever possible
…o `null`, not to an empty `string`
… object type being hydrated
…de-strategy' into develop Close zendframework/zendframework#6227
Too simple and self-explanatory.
Please see the tests.