splitting out Unirest\File and updating README

This commit is contained in:
Ahmad Nassri
2015-01-14 18:31:21 -05:00
parent ed2a2df982
commit be9bca1d5a
7 changed files with 64 additions and 66 deletions

View File

@@ -1,5 +1,6 @@
<?php
require_once dirname(__FILE__) . '/Unirest/File.php';
require_once dirname(__FILE__) . '/Unirest/Method.php';
require_once dirname(__FILE__) . '/Unirest/Response.php';
require_once dirname(__FILE__) . '/Unirest/Request.php';

19
src/Unirest/File.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
namespace Unirest;
class File
{
/**
* Prepares a file for upload. To be used inside the parameters declaration for a request.
* @param string $path The file path
*/
public static function add($filename, $mimetype = '', $postname = '')
{
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $mimetype = '', $postname = '');
} else {
return sprintf('@%s;filename=%s;type=%s', $filename, $postname ?: basename($filename), $mimetype);
}
}
}

View File

@@ -20,9 +20,6 @@ interface Method
const OPTIONS = 'OPTIONS';
const TRACE = 'TRACE';
// RFC3744
const ACL = 'ACL';
// RFC3253
const BASELINE = 'BASELINE';

View File

@@ -173,19 +173,6 @@ class Request
return self::send(Method::TRACE, $url, $body, $headers, $username, $password);
}
/**
* Prepares a file for upload. To be used inside the parameters declaration for a request.
* @param string $path The file path
*/
public static function file($filename, $mimetype = '', $postname = '')
{
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $mimetype = '', $postname = '');
} else {
return sprintf('@%s;filename=%s;type=%s', $filename, $postname ?: basename($filename), $mimetype);
}
}
/**
* This function is useful for serializing multidimensional arrays, and avoid getting
* the 'Array to string conversion' notice

View File

@@ -4,7 +4,6 @@ namespace Unirest;
class Response
{
public $code;
public $raw_body;
public $body;
@@ -39,9 +38,8 @@ class Response
if (function_exists('http_parse_headers')) {
return http_parse_headers($raw_headers);
} else {
$headers = array();
$key = '';
$headers = array();
foreach (explode("\n", $raw_headers) as $i => $h) {
$h = explode(':', $h, 2);