[TYPO3-mvc] Using external libraries within Extbase Extension
Hauke Stange
hstange at eheundjanneck.de
Wed Aug 3 16:12:58 CEST 2011
On Wed, 2011-08-03 at 15:31 +0200, Hauke Stange wrote:
> On Wed, 2011-08-03 at 13:34 +0200, Hauke Stange wrote:
> > Hi there.
> >
> > I just want to know if there is a preferred way for using external
> > libraries within an extension. In my case I have to use some existing
> > code which uses some of the PEAR libraries.
> >
> > Is there a way for putting the files in a certain directory similar to
> > the /Service/ or /Utility/ directories?
>
> Ok, my first guess (dirty hack) was wrong. I copied the needed Libraries
> to 'EXT:/Resources/Libraries/PEAR/' and included the following lines of
> code where needed...
>
> $extensionPath = t3lib_extMgm::extPath('gpqg');
> $pearPath = $extensionPath . 'Resources/Libraries/PEAR/';
> if (! set_include_path($pearPath . PATH_SEPARATOR . get_include_path()))
> {
> throw new Exception("What the heck!!!");
> }
> require_once 'Net/SFTP.php';
> $sftp = new Net_SFTP(Sftp::host, Sftp::port);
>
> The Autoloader(s) from Typo3 / Extbase of course failed to load the
> 'Net_SFTP' class.
Ok, still searching for a solution I just tried this
"createAutoloadRegistryForExtension"-stuff from Extbase...
$extensionPath = t3lib_extMgm::extPath('gpqg');
$pearPath = $extensionPath . 'Resources/Libraries/PEAR/';
$classMap= array(
'net_sftp' => "'{$pearPath}Net/SFTP.php'"
);
Tx_Extbase_Utility_Extension::createAutoloadRegistryForExtension(
'gpqg', $extensionPath, $classMap);
$sftp = new Net_SFTP(Sftp::host, Sftp::port);
The corresponding ext_autoload.php file looks like this:
$extensionClassesPath = t3lib_extMgm::extPath('gpqg') . 'Classes/';
return array(
// All my Extbase classes come here first...
'net_sftp' => '/path/to/Resources/Libraries/PEAR/Net/SFTP.php',
);
Still not happy,
Hauke
More information about the TYPO3-project-typo3v4mvc
mailing list