Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Created Explode Strategy for hydrator #6227

Conversation

ojhaujjwal
Copy link
Contributor

Too simple and self-explanatory.
Please see the tests.

}

/**
* Converts the given value so that it can be hydrated by the hydrator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a general description, it does not describe what this method does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below

@Martin-P
Copy link
Contributor

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?

@ojhaujjwal
Copy link
Contributor Author

@Martin-P Thank you for providing the details.

@ojhaujjwal
Copy link
Contributor Author

@Martin-P Hey. I have done some changes. Please comment.

@ojhaujjwal
Copy link
Contributor Author

Will this PR get merged for 2.4?

*/
public function setExplodeLimit($explodeLimit)
{
if (!is_int($explodeLimit)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it needs implementation, but should 1 (as a string) be allowed as well?

$strategy->setExplodeLimit('1');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use is_numeric instead of is_int.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')); // false

Casting to int could also be an option, but I'm not sure that is the way to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some expert's help.
ping @Ocramius

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@adamlundrigan
Copy link
Contributor

This will need a documentation PR to add it to the list of available implementations

@adamlundrigan
Copy link
Contributor

@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 Zend\Serializer, and add some sort of array-to-separator imploder there? That would take care of this use case plus make other serialization formats available with no extra effort

@ojhaujjwal
Copy link
Contributor Author

@adamlundrigan One use case is that it can be used in forms to take comma separated input from the user.

* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2015 ;)

@ojhaujjwal ojhaujjwal force-pushed the feature/explode-hydrator-strategy branch from 753c990 to 26af277 Compare January 3, 2015 03:50
@Ocramius Ocramius self-assigned this Jan 3, 2015
Ocramius added a commit that referenced this pull request Jan 3, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
…for the `Zend\Stdlib\Hydrator\Strategy` namespace
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
…he `Zend\Stdlib\Hydrator\Strategy` exceptions
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
…isallow `null` `$delimiter` in constructor
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
… to be hydrated by `ExplodeStrategy#hydrate()`
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants