I got TYPO3 v10.2 running without Composer. I am creating an extension and want to include some third party PHP libraries into my Extbase Extension. I already read in the TYPO3 docs that those should be placed in Resources/Private/PHP/ThirdPartyLibrary
but how can I include them there ? Is it still possible with composer require
or should I just download the third party library resources and unzip it there ? How can I use the namespace/Classes from the external Library in the Controller or general in my Extension ?
What is the best way to do this without AND with composer ? Would like to know both ways. Thanks so far!
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!
© 2022 - 2024 — McMap. All rights reserved.