[TYPO3-english] TYPO3 via Composer integration

Viktor Livakivskyi invisible.kinder at gmail.com
Tue Mar 17 19:41:05 CET 2015


Hi, list.

I'd like to use Composer's autoloader in TYPO3 project and ude it not only for core classes, but also for our custom extensions (which will not be published to TER nor to Packagist).

Second goal is to have "vendor" directory out of www-root folder.

Third goal is to be ready for 7.x, while we're on a 6.2 still.

After reading lot [1] of [2] articles [3] and personal tries and errors I found that following is minial contents of composer.json, located at your root:
{
  "repositories": [
    {
      "type": "composer",
      "url": "http://composer.typo3.org/"
    }
  ],
  "config": {
    "vendor-dir": "Packages/Libraries",
    "bin-dir": "bin"
  },
  "require": {
    "typo3/cms": "~6.2",
   },
 }

I had to adjust repositories location, becasue for some reason composer wasn't able to get TYPO3 from Packagist by default.
I had to add "Packages/Libraries" as vendor dir, because Bootstrap of TYPO3 6.2 in combination with environment variable TYPO3_COMPOSER_AUTOLOAD looks exactly into these folders located either in www-root or one folder upper [4].

So far so good.
If I want to include any other public extension into project, it is also possible with "require" section.

But how should I correctly include our custom extensions?

My first approach was to put them into "replace" section with "self.version", but seems, that Composer does nothing with them: resulting psr-4 class-map doesn't contain section, mentioned in "autoload" of typo3conf/ext/my_ext/composer.json.

Second idea was to include extension in normal "require" section, but then it means, that each of our custom extensiosn must have it's own repository, which would comjplicate the structure.

Third idea was to remove any ext/my_ext/composer.json from custom extensions and put all psr-4 mappings into "autoload" section of root composer.json. This means, that also some external libraries dependencies need to be put there es well.
This solution looks like the most suitable, though it is not the most "clean".

What are the best practives or your own experience here?


[1]: http://wiki.typo3.org/ComposerClassLoader
[2]: http://composer.typo3.org/
[3]: http://blog.cedric-ziel.com/articles/creating-a-typo3-installation-by-composer/
[4]: https://github.com/TYPO3/TYPO3.CMS/blob/TYPO3_6-2-10/typo3/sysext/core/Classes/Core/Bootstrap.php#L162-L177


More information about the TYPO3-english mailing list