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