As long as composer support in CMS is "not there yet", you need to get around somehow.
Say you want to use the (awesome) markdown library, you need a way to get it in.
- Use a container extension with a private namespace
- Create composer.json
- Include the autoloader for both contexts
- profit
Create a file composer.json in your container extension in Resources/Private (you can use composer init):
{
"name": "cedricziel/packagename",
"config": {
"vendor-dir": "Libraries"
},
"require": {
"michelf/php-markdown": "~1.4"
},
"authors": [
{
"name": "Cedric Ziel",
"email": "cedric @t cedric-ziel.com"
}
]
}
Note the vendor-dir directive. This allows you to determine where composer will put the libs and the class loader you have to include.
I cant explain the exact sematics very well, but you will want to have both. Otherwise your classes wont load in a cached context.
ext_tables.php
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
$composerAutoloadFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY)
. 'Resources/Private/Libraries/autoload.php';
require_once($composerAutoloadFile);
ext_localconf.php
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
$composerAutoloadFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY)
. 'Resources/Private/Libraries/autoload.php';
require_once($composerAutoloadFile);
This is a workaround - let me get this straight. Problems could arise if you do that overly often with many different libraries and end up with different loadable classes. I therefore propose you creat one such container extension per project.
I think it would be better when you use
Resources/Private/PHPas path for your composer.json. Or not?