Composer Tips & Tricks

Composer Tips & Tricks

Presented at the Bulgaria PHP User Group meeting in March 2016.
https://www.facebook.com/events/1538125716485720/

B823b2c0a620c82547e71f84cfa15682?s=128

Haralan Dobrev

March 10, 2016
Tweet

Transcript

  1. Composer Tips & Tricks Making the most of using Composer

  2. What is Composer? PHP dependency manager

  3. Authors of Composer Jordi Boggiano @Seldaek Nils Adermann @naderman

  4. • composer.json • composer init • composer install • composer

    update • composer require • composer.lock Composer basics
  5. composer create-project • Bootstraps your project from another package •

    Installs dependencies • Provide hooks to execute scripts
  6. • composer create-project fabpot/silex-skeleton <path> • composer create-project --repository-url=https://repo. magento.com/

    magento/project-community-edition <path> • composer create-project <your vendor>/<your template> foo composer create-project
  7. clippings/composer-init • Inspired by grunt-init • composer global require clippings/composer-init

    • composer-init use clippings/package-template • Learn more at github.com/clippings/composer-init
  8. composer update --with-dependencies composer update --with-dependencies vendor/package Updates only a

    package with its dependencies. Does not touch the rest of the packages. composer require --update-with-dependencies
  9. composer remove --update-with-dependencies --update-with-dependencies is now the default for composer

    remove composer remove
  10. composer update --prefer-lowest composer update --prefer-lowest --prefer-stable But when would

    you want that? Testing a library
  11. Travis CI Build Matrix php: - 5.3 - 5.4 -

    5.5 - 5.6 - 7 - hhvm env: - DEPS=normal - DEPS=highest - DEPS=lowest
  12. Travis CI Build Matrix install: - if [ "$DEPS" =

    "normal" ]; then composer install; fi; - if [ "$DEPS" = "highest" ]; then composer update; fi; - if [ "$DEPS" = "lowest" ]; then composer update --prefer-lowest --prefer- stable; fi;
  13. Travis CI Build Matrix

  14. config.platform { "config": { "platform": { "php": "5.6" } }

    }
  15. composer install --prefer-source Differences between: • source • dist •

    auto When to use --prefer-source?
  16. config.preferred-install { "config": { "preferred-install": { "clippings/*": "source", "*": "auto"

    } } }
  17. composer install --prefer-dist --no-dev config.preferred-install

  18. .gitattributes export-ignore tests export-ignore .travis.yml export-ignore .gitattributes export-ignore .gitignore export-ignore

  19. composer test { "scripts": { "test": "phpunit" } } composer

    test
  20. composer run-script composer run-script lint { "require-dev": { "squizlabs/php_codesniffer": "^2.5"

    }, "scripts": { "lint": "phpcs" } }
  21. composer depends Shows which packages depend on a package

  22. $ composer depends symfony/yaml phpunit/phpunit 4.8.23 requires symfony/yaml (~2.1|~3.0) composer

    depends
  23. composer prohibits

  24. composer prohibits $ composer prohibits symfony/yaml:2.0 phpunit/phpunit 4.8.23 requires symfony/yaml

    (~2.1|~3.0)
  25. extra.branch-alias { "extra": { "branch-alias": { "dev-master": "1.0-dev" } }

    }
  26. VCS repositories { "repositories": [ { "type": "vcs", "url": "https://github.com/clippings/php-gacx"

    } ] }
  27. extra.branch-alias { "extra": { "branch-alias": { "dev-master": "1.0-dev" } }

    } Read more at getcomposer.org/doc/articles/aliases.md
  28. Bonus: Facebook mention-bot

  29. Facebook mention-bot Learn more at github.com/facebook/mention-bot

  30. Who? @hkdobrev CTO @ Clippings.com clippings.github.io Thanks!