Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

TYPO3 & Composer

4,486 views

Published on

How Composer helps you to manage TYPO3 extensions in your projects.

Published in: Internet

TYPO3 & Composer

  1. 1. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 and Composer Photo: arianta@flickr
  2. 2. Composer in general Armin Rüdiger Vieweg |@Twitter | 19.11.2014
  3. 3. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 What is Composer? is a Dependency Manager for PHP written in PHP URL: https://getcomposer.org
  4. 4. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 What does Composer do? ❖ Loads source code (packages) from different locations to your project ❖ Central composer repository: https://packagist.org/ ❖ Composer ♥ JSON
  5. 5. Example of a composer package: Armin Rüdiger Vieweg |@Twitter | 19.11.2014 TYPO3 Flow
  6. 6. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 First steps in Composer 1. Download composer: curl -sS https://getcomposer.org/installer | php 2. Call composer like this: ./composer.phar create-project typo3/flow >> Downloads TYPO3 Flow with all dependencies
  7. 7. What Composer also can do for you ❖ Composer puts packages per default to folder Armin Rüdiger Vieweg |@Twitter | 19.11.2014 “vendor” ❖ API existing to write own plugins ➢ Hooks/Events for every part of composer ➢ Move packages from vendor folder to own destination ❖ Create own packages
  8. 8. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 Composer’s advantages ❖ No code redundancy ❖ Easy to maintain (updates) ❖ Very flexible ❖ Standard for PHP dependency management
  9. 9. How to handle TYPO3 extensions in VCS? Armin Rüdiger Vieweg |@Twitter | 19.11.2014
  10. 10. How to handle T3 extensions in VCS? ❖ Just check them in, like any other code ➢ Standard extensions like realurl, powermail or dce ;-) are located in several repositories at the same time Armin Rüdiger Vieweg |@Twitter | 19.11.2014 ➢ Probably in different versions ➢ Very costly to keep them up to date ➢ Extrem high redundancy
  11. 11. How to handle T3 extensions in VCS? Armin Rüdiger Vieweg |@Twitter | 19.11.2014 ❖ Use SVN externals ➢ No redundancy anymore ➢ But not all extensions got a SVN repository ➢ So we had to create our own SVN repository for extensions we were using in several projects ■ Also very costly, because each new extension or version of an extension needs to get imported to SVN
  12. 12. Composer for TYPO3 Armin Rüdiger Vieweg |@Twitter | 19.11.2014
  13. 13. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 Composer for TYPO3 ❖ Works with all VCS like Git, SVN or Mercurial ❖ Requirements: ➢ A composer.json file in root of your TYPO3 project ➢ Possibility to run composer (on server or locally) ❖ URL: http://composer.typo3.org
  14. 14. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 composer.json { "repositories": [ { "type": "composer", "url": "http://composer.typo3.org/" }, { "type": "composer", "url": "http://user:pass@composer.sunzinet.com/" } ],
  15. 15. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 composer.json "replace": { "typo3/cms": "*" }, "require": { "typo3/cms-composer-installers": "*", "typo3-ter/realurl": "1.12.*", "typo3-ter/nc-staticfilecache": "2.5.1", "sunzinet/gridelements": "3.0.0", "sunzinet/t3ddy": "0.2.0", "sunzinet/sz_nc_staticfilecache": "0.4.2" } }
  16. 16. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 composer.json parts 1. Repositories ➢ List of composer repositories (with T3 extensions) 2. Replace ➢ Optional. Disables download of TYPO3 itself 3. Require ➢ Defines which extensions should be included to your project. Underscores in extkeys become minus!
  17. 17. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 Run composer ./composer.phar install ❖ Composer downloads all extensions ❖ Moves them from vendor/ to typo3conf/ext/ ➢ Because of hook which is also provided by TYPO3 Composer Repository ❖ vendor/ folder may get deleted manually
  18. 18. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 How to update extensions? ❖ Just change version number in composer.json ❖ Or add/remove extensions ❖ Perform Composer update: ./composer.phar update
  19. 19. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 Known issues ❖ Bugtracker in forge (9 bugs, 3 features, 2 tasks open) ❖ Extensions with sysext dependencies fail ➢ Because the sysext is not located in repository ➢ gridelements is such an extension ➢ And all extensions based on gridelements (like t3ddy) ➢ Ticket in forge: 60950
  20. 20. How to get your own Composer repo ❖ Composer repositories are also just JSON files ❖ Located under: domain.com/packages.json ❖ It contains packages ❖ and different versions for each package Armin Rüdiger Vieweg |@Twitter | 19.11.2014
  21. 21. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 packages.json example
  22. 22. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 Composer and Git ❖ In .gitignore you should exclude some stuff: /composer.lock /composer.phar /vendor /vendor/** /typo3conf/ext/** !/typo3conf/ext/your_own_extension !/typo3conf/ext/your_own_extension/**
  23. 23. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 .htaccess improvements ❖ In .htaccess you should also exclude access to: # Deny direct access to several files RewriteCond %{REQUEST_URI} ^/typo3_src [OR] RewriteCond %{REQUEST_URI} ^/composer.json [OR] RewriteCond %{REQUEST_URI} ^/composer.lock [OR] RewriteCond %{REQUEST_URI} ^/.gitignore [OR] RewriteCond %{REQUEST_URI} ^/.gitattributes [OR] RewriteCond %{REQUEST_URI} ^/phpci.yml RewriteRule .* / [L,R=301]
  24. 24. PHPCI, Composer and Armin Rüdiger Vieweg |@Twitter | 19.11.2014 TYPO3
  25. 25. URL: https://www.phptesting.org/ ❖ Continuous Integration based on PHP Armin Rüdiger Vieweg |@Twitter | 19.11.2014 ➢ Automated code checks: ■ PhpLoc, Mass Detector, Code Sniffer, PhpUnit ➢ Composer support ■ Execution after code checks ➢ Creation of deployable archives ➢ Report state of build back to Git GUI
  26. 26. Armin Rüdiger Vieweg |@Twitter | 19.11.2014
  27. 27. Armin Rüdiger Vieweg |@Twitter | 19.11.2014 Questions? Photo: an_untrained_eye@flickr
  28. 28. Armin Rüdiger Vieweg Photo: wi|n@stTownaitvtiecrh|@19fl.i1c1k.r2014 Thank you! POWERED BY

×