1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-11-30 04:39:21 +01:00

Merge pull request #393 from bantu/stream-registration

Add Net_SFTP_Stream::register()

* bantu/stream-registration:
  Use get_called_class() if available.
  Add Net_SFTP_Stream::register() for easier autoloading.
  Add unit test for (to be added) Net_SFTP_Stream::register().
This commit is contained in:
Andreas Fischer 2014-06-27 14:14:15 +02:00
commit af8f350050
2 changed files with 50 additions and 3 deletions

View File

@ -126,6 +126,22 @@ class Net_SFTP_Stream
*/
var $notification;
/**
* Registers this class as a URL wrapper.
*
* @param optional String $protocol The wrapper name to be registered.
* @return Boolean True on success, false otherwise.
* @access public
*/
static function register($protocol = 'sftp')
{
if (in_array($protocol, stream_get_wrappers(), true)) {
return false;
}
$class = function_exists('get_called_class') ? get_called_class() : __CLASS__;
return stream_wrapper_register($protocol, $class);
}
/**
* The Constructor
*
@ -783,6 +799,4 @@ class Net_SFTP_Stream
}
}
if (function_exists('stream_wrapper_register')) {
stream_wrapper_register('sftp', 'Net_SFTP_Stream');
}
Net_SFTP_Stream::register();

View File

@ -0,0 +1,33 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIV Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'Net/SFTP/Stream.php';
class Unit_Net_SFTPStreamTest extends PhpseclibTestCase
{
protected $protocol = 'sftptest';
public function setUp()
{
parent::setUp();
if (in_array($this->protocol, stream_get_wrappers())) {
stream_wrapper_unregister($this->protocol);
}
}
public function testRegisterFromSideEffect()
{
// Including the file registers 'sftp' as a stream.
$this->assertContains('sftp', stream_get_wrappers());
}
public function testRegisterWithArgument()
{
Net_SFTP_Stream::register($this->protocol);
$this->assertContains($this->protocol, stream_get_wrappers());
}
}