Merge pull request #672 from andrey012/sftp-put-callback-for-1.0

Fix callback parameter conflicts of SFTP put() method.

* andrey012/sftp-put-callback-for-1.0:
  callbacks - two PRs conflict sorted out. First one: e9b698fd65, fba6894474, 1cd286642e Second one: 16430d4d2e, 0cc6125f87
  documentation fix
This commit is contained in:
Andreas Fischer 2015-05-03 01:02:50 +02:00
commit ee3eb2071d

View File

@ -1765,7 +1765,7 @@ class Net_SFTP extends Net_SSH2
* If $data is a resource then it'll be used as a resource instead.
*
*
* Setting $mode to self::SOURCE_CALLBACK will use $data as callback function, which gets only one parameter -- number
* Setting $mode to NET_SFTP_CALLBACK will use $data as callback function, which gets only one parameter -- number
* of bytes to return, and returns a string if there is some data or null if there is no more data
*
* Currently, only binary mode is supported. As such, if the line endings need to be adjusted, you will need to take
@ -1793,12 +1793,12 @@ class Net_SFTP extends Net_SSH2
* @param optional Integer $mode
* @param optional Integer $start
* @param optional Integer $local_start
* @param optional callable|null $callback
* @param optional callable|null $progressCallback
* @return Boolean
* @access public
* @internal ASCII mode for SFTPv4/5/6 can be supported by adding a new function - Net_SFTP::setMode().
*/
function put($remote_file, $data, $mode = NET_SFTP_STRING, $start = -1, $local_start = -1, $callback = null)
function put($remote_file, $data, $mode = NET_SFTP_STRING, $start = -1, $local_start = -1, $progressCallback = null)
{
if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
return false;
@ -1846,13 +1846,13 @@ class Net_SFTP extends Net_SSH2
}
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.2.3
$callback = false;
$dataCallback = false;
switch (true) {
case $mode & NET_SFTP_CALLBACK;
if (!is_callable($data)) {
user_error("\$data should be is_callable if you set NET_SFTP_CALLBACK flag");
}
$callback = $data;
$dataCallback = $data;
// do nothing
break;
case is_resource($data):
@ -1881,7 +1881,7 @@ class Net_SFTP extends Net_SSH2
} else {
fseek($fp, $offset);
}
} elseif ($callback) {
} elseif ($dataCallback) {
$size = 0;
} else {
$size = strlen($data);
@ -1894,9 +1894,9 @@ class Net_SFTP extends Net_SSH2
// make the SFTP packet be exactly 4096 bytes by including the bytes in the NET_SFTP_WRITE packets "header"
$sftp_packet_size-= strlen($handle) + 25;
$i = 0;
while ($callback || ($sent < $size)) {
if ($callback) {
$temp = call_user_func($callback, $sftp_packet_size);
while ($dataCallback || ($sent < $size)) {
if ($dataCallback) {
$temp = call_user_func($dataCallback, $sftp_packet_size);
if (is_null($temp)) {
break;
}
@ -1912,8 +1912,8 @@ class Net_SFTP extends Net_SSH2
return false;
}
$sent+= strlen($temp);
if (is_callable($callback)) {
call_user_func($callback, $sent);
if (is_callable($progressCallback)) {
call_user_func($progressCallback, $sent);
}
$i++;