Help:Using Composer

From semantic-mediawiki.org
(Redirected from Help:Using Composer)
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]

Shared hosting[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

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]

Starting with Semantic MediaWiki 3.0.0Released on 11 October 2018 and compatible with MW 1.27.0 - 1.31.x. tarballs will no longer be provided.1 Alternatively you will have to create an individual file release on a machine that allows command line access. The script to do so is available at "SemanticMediaWiki/IndividualFileRelease" which also works for Semantic MediaWiki 2.5.x.
It is strongly recommended to not just create an individual file release of Semantic MediaWiki and related extensions but to also include MediaWiki itself in the process as the script which is available at "SemanticMediaWiki/IndividualFileRelease" does.

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

Access to a server or computer is needed for this to work, so you might have to ask somebody to do this for you.

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:

  1. Copy the following file to you local computer: "IndividualFileRelease.sh"
  2. Change permissions of the file with
    chmod 700 IndividualFileRelease.sh
    
  3. Run the script with
    ./IndividualFileRelease.sh
    
  4. Move the resulting files to your webspace.
  5. Do the rest of the installation of Semantic MediaWiki and enjoy!

See also Installation

FAQ[edit]

See also[edit]