Status: | effective |
Progress: | 100% |
Version: | 3.0.0+ |
Composer usage | |
---|---|
Some information about how to use Composer | |
Keywords | |
Table of Contents | |
Composer is a dependency manager for PHP. For a more in-depth understanding on how Composer works and how to interpret the composer.json
file, see Composer net.tuts tutorial.
Installation[edit]
Hosting with shell access[edit]
- Installing Composer globally (recommended)
[edit]
Download composer.phar
using
curl -sS https://getcomposer.org/installer | php
into the same folder where the composer.json
file is located (Installing Composer locally).
The next step is to run php composer.phar install
in order to download all necessary libraries (into the extension/ or vendor/
directory).
- Related links
- Using Composer on a VPS that runs Ubuntu
- Installing Composer on a shared Dreamhost Server
- PHP Composer on shared hosting
Usage[edit]
Adding packages[edit]
Installing a package can be done by running composer require "PackageNameIs:ForVersion"
.
The require
command consists of two parts, the name of the package and second devided by a colon represents the version to be installed.
~/^ usage and meaning[edit]
The tilde section describes its expected behavior in detail but in short it allows to specify a range of allowed release tags. If with the next composer update
execution a new update is available (new release, bugfix etc.) it will be automatically pulled together with all its dependencies. Something like ~2.3
indicates an equivalence to >= 2.0, < 3.0
.
Fetching a distinct release[edit]
If for some reason you want to use a different release other than the latest available "~4.2"
then using a distinct release tag without the ~
is a viable option but it will lock the release to a specific version and available updates (for bugfixes etc.) will not be fetched on the next composer update
run therefore it is not the preferred option.
Remove packages[edit]
Remove the PackageNameIs
from the composer.json
repositories section and run composer update
.
Update packages and dependencies[edit]
If a new release is available run composer update
and if for some reason you need to pull directly from master (using git pull/git fetch
) it is recommended that after executing git
you run composer dump-autoload
from the MW root directory.
Using development versions[edit]
composer require mediawiki/semantic-media-wiki "@dev-thenameofthebranchyouwanttotest"
Using development fork[edit]
Sometimes you may want to load a package directly from a version control system (VCS) like on GitHub. There are a few use cases for this. The most common one is maintaining your own fork during softwatre development time. To use your own fork, change the "composer.json" file as follows:
"require": {
"mediawiki/semantic-result-formats": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/gesinn-it/SemanticResultFormats"
}
]
Now, run
composer update --prefer-source
Improve autoloader[edit]
Composer recommends to use dump-autoload together with option -o
to get a faster autoloader especially for production environments. dump-autoload
will convert PSR-0/4 packages into a classmap in order to optimize the loading of classes.
Individual file release[edit]
When creating a file release make sure that the respective platform setups are matching in respect of PHP to avoid issues arising from mismatches.2
If due to some configuration restrictions on part of the hosting company or missing command line access, it is suggested to run a local copy and upload the generated files together with the /vendor
directory to the target destination:
- Copy the following file to you local computer: "IndividualFileRelease.sh"
- Change permissions of the file with
chmod 700 IndividualFileRelease.sh
- Run the script with
./IndividualFileRelease.sh
- Move the resulting files to your webspace.
- Do the rest of the installation of Semantic MediaWiki and enjoy!
See also Installation
FAQ[edit]
See also[edit]
References
- ^ Semantic MediaWiki: GitHub issue gh:smw:3346
- ^ | Semantic MediaWiki: GitHub issue gh:smw:4098