Skip to content

Make sure we can add resources with same name. Ie no overwrite #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2017

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Feb 15, 2017

This will fix issue #31

@z38
Copy link

z38 commented Feb 15, 2017

Thank you for the very fast response! After applying the fix, the parts are no longer overwritten.

As it stands, this is most probably a BC break as the old behavior is explicitly mentioned in the docs:

If the same $name is used twice the first resource will be overwritten.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 15, 2017

Thank you. I missed that... I wonder why I would write that.

I need to do some more research before I can merge this. It seams to be the right thing to do but Im not sure..

@Nyholm
Copy link
Member Author

Nyholm commented Feb 16, 2017

So, here is what I concluded:

$builder->addResource('foo', 'content');

// Same as
$builder->addResource('whatever', 'content', ['content-disposition'=>'form-data; name="foo"']);

One could remove the first parameter of addResource and put it in the options array as a header (like the example above) or a new "name" key. But neither are not preferable since 99% of the cases you would never use the third parameter of addResource (options array). You would only care about the first two.


Resource names SHOULD be unique. If same name is used one SHOULD use the array syntax. Ie "foo[0]", "foo[1]" etc. But this is not a hard requirement (MUST) and I think we should be flexible rather then opinionated.

I vote for merging this PR in the current state and release 0.2.0.


The difference between 0.1.x and 0.2.0 would be that all resources you add to the builder will be added to the stream. You cannot overwrite. Though, resources may have the same POST name and some servers cannot handle that.

## 0.1.6 - 2017-02-16

### Fixed

- Performance improvements by avoid using `uniqid()`.
- Make sure one can add resources with same name without overwrite.
Copy link

Choose a reason for hiding this comment

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

This line is probably no longer needed (assuming the changes will only be part of the 0.2.0 release)

@z38
Copy link

z38 commented Feb 16, 2017

Sounds great! Thank you for taking a look at this and fixing it so quickly!

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

agree that if http allows it, we should support it. and your solution looks fine.

not sure i understand your point about moving the first parameter into the options. are you saying the name is optional? i feel like the name is more than an option, so we should keep it separate. we could switch $resource and $name and have a $name=null. but not sure if we need to do that, people can just pass '' as name, or a random hash.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 16, 2017

I agree with you.

I just wanted to mention that one could remove the first parameter because it is redundant and not strictly needed. But I think we should keep it since it is way more convenient and covers 99% of the cases. I expect it to be an edge case to configure your own headers.

@Nyholm Nyholm merged commit c78d9e7 into master Feb 17, 2017
@Nyholm Nyholm deleted the issue-31 branch February 17, 2017 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants