Reputation: 1344
According to this http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html from TYPO3 V6 , using namespaces is encouraged and that any PHP file should contain only ONE class. Quoting from the above link
- In TYPO3 every class must reside in its own file, i.e. there should
be only one class per PHP file
- Use the class naming convention and file location.
My extension is built using extension builder.
It uses the twitter API library and there is one file config.php
which is to be used.
This file contains multiple classes
in it.
The question is, to use this config.php , following the two conditions, should I divide the config.php
into multiple php files, each with a single class in it ?
Or is there a really neat way to go about this ?
Upvotes: 0
Views: 3307
Reputation: 842
By following http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html the right way is to create an ext_autoload.php file in the root folder of your extension containing this:
$libraryClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('your_ext_key') . 'Relative/Path/Of/Your/External/Library/';
return array(
'class_name_to_call' => $libraryClassesPath . 'class_file.php',
);
Save this code in /typo3conf/ext/myext/ext_autoload.php
$libraryClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('myext') . 'Resources/Private/Library/';
return array(
'FPDF' => $libraryClassesPath . 'fpdf/fpdf.php',
);
clear the cache
use FPDF everywhere in your extension by calling:
$pdf = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('FPDF');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
Upvotes: 3
Reputation: 2761
Leave the external code as it is. The coding guidelines are just for the extension and core development itself, you don't need to modify extenal libraries to match that guideline.
Simply include the external scripts with
require_once t3lib_extMgm::siteRelPath('your_extension_key') . 'Path/to/the/Script.php';
and start using them.
Upvotes: 3