TYPO3: How to use external PHP libraries in Extbase Extension (no composer installation)
You can just use composer in your local environment.
composer init
composer req <neded packages>
composer u
- Move the
vendor/
into youryour_extension/Resources/Private/PHP/ThirdPartyLibrary/
- Adjust the autoload path into the
vendor/
that you just moved.
You can have a look into the Shariff Extension
They placed the external library in Resources/Private/Shariff/vendor/
https://bitbucket.org/reelworx/rx_shariff/src/master/Resources/Private/Shariff/
And Autoload the files in
https://bitbucket.org/reelworx/rx_shariff/src/master/Classes/Shariff.php
Using the libraries in your controller
The libraries need to have namespaces already if you want to use them in your controller.
Since your in TYPO3 V10 you can use the new symfony dependency injection that is implemented into TYPO3 now: https://usetypo3.com/dependency-injection.html
your_extension/Classes/Controller/YourController.php
/**
* @var ThirdPartyLibrary
*/
protected $thirdPartyLibrary;
/**
* @param ThirdPartyLibrary $thirdPartyLibrary
*/
public function __construct(ThirdPartyLibrary $thirdPartyLibrary)
{
$this->thirdPartyLibrary = $thirdPartyLibrary;
}
your_extension/Configuration/Services.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Vendor\Namespace\:
resource: '../Resources/Private/PHP/ThirdPartyLibrary/*'
You will need to load the class for your library. I not sure which library your using.
Place the below code in your ext_localconf.php
<?php
$composerAutoloadFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('yourExtKey') . 'Resources/Private/PHP/ThirdPartyLibrary/vendor/autoload.php';
require_once($composerAutoloadFile);
Now, you can use the library class wherever you want to use it. Make sure you dump cache as well as autoload class from TYPO3 Backend!