jnemecz
jnemecz

Reputation: 3608

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?

Upvotes: 1

Views: 1706

Answers (2)

neubert
neubert

Reputation: 16782

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.

Upvotes: 1

Lee
Lee

Reputation: 10603

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');

Upvotes: 1

Related Questions