Hello!

I have idea to make possible to send files with CURL from string.
CURL library has few options to make it as easy as possible:
CURLFORM_BUFFER, CURLFORM_BUFFERPTR, and CURLFORM_BUFFERLENGTH.

But I got many problems with integration of this feature in current php
curl file attachment design.

Class CURLFile has one required $filename property, and two optional
properties $mimetype and $postname.
In my case we need two required properties $buffer and $postname, and one
optional $mimetype.

Also we have function curl_file_create, which just like alias function for
CURLFile constructor with same arguments.

So I tried to implement feature by different ways:
1) Create new class CURLFileBuffer by simple copy-paste code from CURLFile.
(pull-request https://github.com/php/php-src/pull/1217 - code was removed,
sorry)
positive:
- No BC break
- API similar to CURLFile
negative:
- A lot of code duplication, hard to support in future.

Thanks to Tony2001 and S.Malyshev for reviewing.

2) Integrate new feature to exists CURLFile class. (pull-request
https://github.com/php/php-src/pull/1283)
positive:
- One class for new and old features
- No code duplication
- No BC break (* except some little not obviously cases)
negative:
- Not clear behavior if developer will set $filename and $buffer in same
time. It require more documentation and not obviously for developers.
- Not clear which values of $filename we must ignore to start use $buffer.
- etc.

Thanks to S.Malyshev for reviewing.

3) Like #2, but make CURLFile immutable after instance creation by
curl_file_create and curl_file_buffer_create functions (or by little
modified constructors).
positive:
- Clear behavior.
negative:
- Great BC break: CURLFile has public properties and setters methods.

I like it, I think it will be great to make CURLFile immutable, but I'm
sure no one want such BC. =(

4) Like #1, but move code duplication to common C code, used by two
classes.
It's impossible, because this classes so simple, so 95% of code like that:

>

/* {{{ proto string CURLFile::getFilename()

   Get file name */

ZEND_METHOD(CURLFile, getFilename)

{

curlfile_get_property("name", INTERNAL_FUNCTION_PARAM_PASSTHRU);

}

/* }}} */

So both classes required such doc block ({{{ proto ...) and call
 *_property methods.

5) Like #1, but move code duplication to abstract class, for example
CURLFileAbstract.

So we move $mimetype and $postname to abstract class, $filename to
CURLFile, $buffer to CURLFileBuffer class.
They will have own constructors with own arguments requiring.

positive:
- No BC break
- less code duplication
negative:
- new abstract class, used ONLY for less code duplication in curl
extension, it has no sense for developers.

6+) Your variant, please provide it.


As you can see, so little change, like using few simple options from curl
library, require so long mail, few pull-requests and too many time from
internal php people.
But I believe, we can do it.
Thank you, and please help me to finish this small feature.



-- 
With regards, Alexander Moskalev
ir...@irker.net
ir...@php.net
a.moska...@corp.badoo.com

Reply via email to