composer.json
-- required in Composer-based installations
Introduction
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your extension depends on and it will manage (install/update) them for you.
Packagist is the main Composer repository. It
aggregates public PHP packages installable with Composer. Composer packages
can be published by the package maintainers on Packagist to be installable in an
easy way via the composer require
command.
Attention
When a Composer package with the type typo3-
is published on
Packagist, it may be made available in the
TYPO3 Extension Repository
automatically. See
TYPO3 TER Packagist Integration
for more information.
About the composer.json file
Note
While the file composer.
is currently not strictly required
for an extension to function properly in legacy non-Composer installations
it is recommended to keep it in any public extension that is published to
TYPO3 Extension Repository (TER).
Including a composer.
is strongly recommended for a number of
reasons:
-
The file
composer.
is required for documentation that should appear on docs.typo3.org.json See Migration: From Sphinx to PHP-based rendering for more information on the necessary changes for rendering of extension documentation.
-
Working with Composer in general is strongly recommended for TYPO3.
If you are not using Composer for your projects yet, see Migrate a TYPO3 project to Composer in the "Upgrade Guide".
Minimal composer.json
This is a minimal composer.
for a TYPO3 extension:
- The vendor name is
My
.Vendor - The extension key is
my_
.extension
Subsequently:
- The PHP namespace will be
\My
Vendor\ My Extension - The Composer package name will be
my-
vendor/ my- extension
{
"name": "my-vendor/my-extension",
"type": "typo3-cms-extension",
"description": "An example extension",
"license": "GPL-2.0-or-later",
"require": {
"typo3/cms-core": "^12.4 || ^13.4"
},
"autoload": {
"psr-4": {
"MyVendor\\MyExtension\\": "Classes/"
}
},
"extra": {
"typo3/cms": {
"extension-key": "my_extension"
}
}
}
- see composer.json schema for general Composer information
- see Properties below for TYPO3 specific hints
Changed in version 11.4
The ordering of installed extensions and their dependencies are loaded from
the composer.
file, instead of ext_
in
Composer-based installations.
Note
Extension authors should ensure that the information in the
composer.
file is in sync with the one in the extension's
ext_emconf.php file. This is especially important
regarding constraints like depends
, conflicts
and
suggests
. Use the equivalent settings in composer.
require
, conflict
and suggest
to set dependencies and ensure a
specific loading order.
Extended composer.json
See also
Please see Extension testing for
further changes to composer.
for testing extensions.
{
"name": "my-vendor/my-extension",
"type": "typo3-cms-extension",
"description": "An example extension",
"license": "GPL-2.0-or-later",
"require": {
"php": "^8.1",
"typo3/cms-backend": "^12.4 || ^13.4",
"typo3/cms-core": "^12.4 || ^13.4"
},
"require-dev": {
"typo3/coding-standards": "^0.7.1"
},
"authors": [
{
"name": "John Doe",
"role": "Developer",
"email": "john.doe@example.org",
"homepage": "https://johndoe.example.org/"
}
],
"keywords": [
"typo3",
"blog"
],
"support": {
"issues": "https://example.org/my-issues-tracker"
},
"funding": [
{
"type": "other",
"url:": "https://example.org/funding/my-vendor"
}
],
"autoload": {
"psr-4": {
"MyVendor\\MyExtension\\": "Classes/"
}
},
"extra": {
"typo3/cms": {
"extension-key": "my_extension"
}
}
}
- See composer.json schema for general Composer information.
- See Properties below for TYPO3-specific hints.
Properties
name
(required)
The name has the format: <my-
. "Dashed extension
key" means that every underscore (_
) has been changed to a dash (-
).
You must be owner of the vendor name and should register it on
Packagist. Typically, the name will correspond to
your namespaces used in the Classes/
folder, but with different
uppercase / lowercase spelling, for example: The PHP namespace
\John
may be johndoe/
in
composer.
.
description
(required)
Description of your extension (1 line).
type
(required)
Use typo3-
for third-party extensions.
The Resources/
folder will be symlinked into the
_assets/ folder of your web root.
Additionally, typo3-
is available for system extensions.
See typo3/cms-composer-installers
(required by typo3/
).
license
(recommended)
Has to be GPL-
or GPL-
.
See: https://typo3.org/project/licenses/.
require
(required)
At least, you will need to require typo3/
in the according version(s).
You should add other system extensions and third-party extensions, if your
extension depends on them.
In Composer-based installations the loading order of extensions and their
dependencies is derived from require
and suggest
.
suggest
You should add other system extensions and third-party extensions, if your extension has an optional dependency on them.
In Composer-based installations the loading order of extensions and their
dependencies is derived from require
and suggest
.
autoload
(required)
The autoload section defines the namespace/path mapping for
PSR-
. In TYPO3 we follow
the convention that all classes (except test classes) are in the directory
Classes/
.
extra.typo3/cms.extension-key
(required)
Not providing this property will emit a deprecation notice and will fail in future versions.
Hint
The property extension-
means the literal string extension-
,
not your actual extension key. The value on the right side should be your
actual extension key.
Example for extension key my_
:
Properties no longer used
replace with typo3-ter
vendor name
This was used previously as long as the TER Composer Repository was
relevant. Since the TER Composer Repository is deprecated, the typo3-
entry
within replace
is not required.
replace with "ext_key": "self.version"
This was used previously, but is not compatible with latest Composer
versions and will result in a warning using composer validate
or
result in an error with Composer version 2.0+:
Deprecation warning: replace.ext_key is invalid, it should have a vendor name, a forward slash, and a package name.
The vendor and package name can be words separated by -, . or _. The complete name should match
"^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$".
Make sure you fix this as Composer 2.0 will error.
See comment on helhum/composer.json and revisions on helhum/composer.json.
More Information
Not TYPO3-specific:
TYPO3-specific:
- The section on testing (in this manual) contains
further information about adding additional properties to
composer.
that are relevant for testing.json - The Composer plugin (not extension) typo3/cms-composer-installers is responsible for TYPO3-specific Composer installation. Reading the README file and source code can be helpful to understand how it works.