简体   繁体   中英

Cannot load phpseclib library installed with composer in CakePHP application

I would like to use phpseclib librabry in my CakePHP 2.8 application. After installation of all dependencies into app/Vendor directory I am trying to try phpseclib installation .

But I am not able to load library:

include('Net/SFTP.php');
$sftp = new Net_SFTP('127.0.0.1');

but this error occures:

Error: Class 'Net_SFTP' not found

In AppController I'm loading auto-generated include and I thought it must be done:

require_once ROOT . DS . 'vendors' . DS . 'autoload.php';

What am I missing?

If your using composer then you just need to include composers autoloader. You don't need to include the specific libraries (thats the point of composers autoloader).

If you look at the source code of the library you'll notice that it's namespaced ( https://github.com/phpseclib/phpseclib/blob/2.0.4/phpseclib/Net/SFTP.php#L38 ). So you need either import the namespace with the use statement, or:

$sftp = new phpseclib\\Net\\SFTP('127.0.0.1');

If you did composer require phpseclib/phpseclib instead of composer require phpseclib/phpseclib:~1.0 you're using 2.0. Net_SFTP is only in the 1.0 branch. In the 2.0 branch it's \\phpseclib\\Net\\SFTP.

http://phpseclib.sourceforge.net/2.0.html elaborates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM