Skip to content

Instantly share code, notes, and snippets.

@cedricziel
Last active October 27, 2021 08:12
Show Gist options
  • Save cedricziel/08ea469db5197e24552c to your computer and use it in GitHub Desktop.
Save cedricziel/08ea469db5197e24552c to your computer and use it in GitHub Desktop.

Revisions

  1. cedricziel revised this gist Apr 15, 2016. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -79,4 +79,8 @@ require_once($composerAutoloadFile);

    ## Notes

    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 versions. I therefore propose you creat **one** such container extension per project.
    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 versions. I therefore propose you creat **one** such container extension per project.

    ## Edit

    * added an example package that's actually used: https://github.com/cedricziel/typo3-ext-slugify
  2. cedricziel revised this gist Jun 2, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,14 @@ Say you want to use the (awesome) markdown library, you need a way to get it in.

    ## Why a separate composer.json?

    Each extension gets a root `composer.json` sooner or later - but this one is irrelevant for now as we dont want to rely on the standard TYPO3 CMS classloader, but rather use the functionality offered by composer to create an autoloader for us.

    For now, the package manager also awaited (TYPO3) packages to exist for every library you require.

    ## Code

    Note: You have to create all this in an extension. I put emphasis on the point that it should be a separate extension.

    ### composer.json

    Create a file `composer.json` in your container extension in `Resources/Private` (you can use `composer init`):
  3. cedricziel revised this gist Jun 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -73,4 +73,4 @@ require_once($composerAutoloadFile);

    ## Notes

    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.
    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 versions. I therefore propose you creat **one** such container extension per project.
  4. cedricziel revised this gist Jun 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -73,4 +73,4 @@ require_once($composerAutoloadFile);

    ## Notes

    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.
    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.
  5. cedricziel revised this gist Jun 2, 2015. 3 changed files with 76 additions and 24 deletions.
    76 changes: 76 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    Motivation
    ==========

    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.

    ## How

    1. Use a container extension with a private namespace
    2. Create composer.json
    3. Include the autoloader for both contexts
    5. profit

    ## Why a separate composer.json?

    ## Code

    ### composer.json

    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.

    ### ext_tables.php && ext_localconf.php

    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);
    ```

    ## Notes

    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.
    15 changes: 0 additions & 15 deletions composer.json
    Original file line number Diff line number Diff line change
    @@ -1,15 +0,0 @@
    {
    "name": "cziel/project-name",
    "config": {
    "vendor-dir": "Libraries"
    },
    "require": {
    "michelf/php-markdown": "~1.4"
    },
    "authors": [
    {
    "name": "Cedric Ziel",
    "email": "[email protected]"
    }
    ]
    }
    9 changes: 0 additions & 9 deletions ext_tables.php
    Original file line number Diff line number Diff line change
    @@ -1,9 +0,0 @@
    <?php
    if (!defined('TYPO3_MODE')) {
    die('Access denied.');
    }

    $composerAutoloadFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY)
    . 'Resources/Private/Libraries/autoload.php';

    require_once($composerAutoloadFile);
  6. cedricziel created this gist Dec 17, 2014.
    15 changes: 15 additions & 0 deletions composer.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {
    "name": "cziel/project-name",
    "config": {
    "vendor-dir": "Libraries"
    },
    "require": {
    "michelf/php-markdown": "~1.4"
    },
    "authors": [
    {
    "name": "Cedric Ziel",
    "email": "[email protected]"
    }
    ]
    }
    9 changes: 9 additions & 0 deletions ext_tables.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <?php
    if (!defined('TYPO3_MODE')) {
    die('Access denied.');
    }

    $composerAutoloadFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY)
    . 'Resources/Private/Libraries/autoload.php';

    require_once($composerAutoloadFile);