2. What’s composer?
● Tool for dependency management in PHP applications
● Command line app written in PHP
● Manages packages on a per-project basis (unlike Apt, Yum etc.)
● Strongly inspired by similar projects in other languages like npm or bundler
● Suppose:
○ You have a project that depends on a number of libraries.
○ Some of those libraries depend on other libraries.
● Composer:
○ Enables you to declare the libraries you depend on.
○ Finds out which versions of which packages can and need to be installed, and installs them
(meaning it downloads them into your project).
“
3. composer: Basic Usage
● Everything related to composer is a kept in a
composer.json at project or package root
● Package names:
○ vendor/package-name
● Versions:
○ Semantic versioning: x.y.z[-stability]
■ x: Major version (potentially breaking changes)
■ y: Minor version (new, compatible functionality)
■ z: Patch version (bug fixes)
■ stability flag: Flag stating the stability of a
pre-release (e.g. 2.0.0-alpha)
○ Branch names, prefixed by dev- (e.g. dev-master)
○ Specific revisions (e.g. dev-master#9823928)
{
"name": "netresearch/project",
"require": {
"typo3/cms": "6.2.*"
},
"require-dev": {
"phpunit/phpunit": "^4.2"
}
}
7. composer: Common commands
● composer init
○ Assistant to create the composer.json for a new project
● composer install [--optimize-autoloader]
○ Installs all packages at their state locked in composer.lock
○ If composer.lock isn’t present, it does the same as composer update
○ Generates autoloader
● composer update
○ Installs the latest package versions (matching the required constraints)
○ Uninstalls packages that are installed but not required anymore
○ Generates autoloader
● composer show [--installed]
○ Shows the installed packages and their versions
● composer require "package=1.2.7"
○ Adds package to require in composer.json and installs it
8. composer: The lock file
● composer.lock
○ Lists packages & versions
○ Replaces composer.json
○ Created by composer install (installs your dependencies)
○ Updated by composer update (updates your dependencies)
○ SHOULD be committed in your VCS and shipped with your releases
● Benefits
○ Everyone on a team works with exactly the same dependency versions
○ When deploying, all machines run exactly the same dependency versions
○ Users will never get dependency versions that you did not test with
● Cons
○ Hindering during development: The exact revision of dev packages is locked => rebase and
merge are painful
○ => Workaround: Advanced checkout, merge and deployment with kite
“
9. What’s kite?
● Yet another build automation tool inspired by TYPO3.Surf
● Everything in PHP: The tool itself as well as all configuration
● ECMA like variable access:
○ Sub tasks can access variables from parent but can set them on their own as well
○ Advanced logic during execution possible by using expressions
(utilizing Symfony Expression Language)
● Node based:
○ Unlimited number of remote targets possible
○ Nodes can be set globally or only for specific (sub) tasks
○ Remote tasks operate on all current nodes
● Dry-Run available by design (yet the tasks to include need to be configured)
● Originally planned and built as TYPO3 extension but later on ported to
generic composer package - installable globally or per project
10. kite: Task organization
● Tasks
○ Smallest, predefined steps (currently: answer, break, callback, choose, composer, confirm,
evaluate, exit, fs, git, include, iterate, output, phar, remoteShell, sub, tar, tryCatch)
● Workflows
○ Sets of tasks predefined in classes
○ Top level workflows can expose command line arguments and options
● Jobs
○ Available as commands on command line
○ Set of tasks and/or workflows defined in arrays (in arbitrary depth)
○ Configurable command line arguments and options
● Presets
○ Configuration presets (including f.i. common jobs)
● Configuration file (typo3conf/Kite.php, app/etc/kite.php, kite.php)
○ Defines the jobs; can load and override presets
11. kite: Common jobs
● kite [help command]
○ Gives a list of all available commands (jobs) or shows help for the given one
● kite checkout [--merge] branch
○ Goes through all composer packages and checks out the branch there if it’s available
○ After checking out the branch on a package it goes through all packages requiring it and
updates the version constraint to that branch
○ When --merge is passed, the currently checked out branch is merged into the branch to
checkout
● kite merge [--squash] [--message=”Message”] branch
○ Goes through all composer packages and merges the branch into the currently checked out
● kite package-foreach [--git] command
○ Runs a command for each composer package (optionally only dev packages)
● kite cc, kite ccr [stage]
○ Clears caches locally (cc) or on all nodes of a specific stage
12. kite: Deployment jobs
● kite deploy [stage]
○ Runs the deployment for all nodes on the given or selected stage
● kite rollout [stage]
○ Runs the deployment for all nodes for each stage until (including) the given stage
13. Links
- Composer homepage and documentation
http://getcomposer.org
http://slides.seld.be/ (lists slides for some advanced composer talks)
- Packagist
http://packagist.org
- Kite on github
https://github.com/netresearch/kite
- Kite on packagist
https://packagist.org/packages/netresearch/kite
- Kite task and workflow reference
https://github.com/netresearch/kite/blob/master/docs/reference.rst