Reputation: 2243
In my following composer.json
I am requiring extensions, which are in the same Git repository as the whole project. So I add in the repositories
section and later I do composer req vendor/site_package:@dev
in order to require my local extension.
Now I realized, that some classes of the extension are not autoloaded.
Do I need to additional add the autoload
part as shown below in the composer.json
of the project?
{
"name": "site-package",
"description": "Base composer.json",
"repositories": [
{
"type": "path",
"url": "./packages/*"
}
],
"require": {
"typo3/cms-backend": "^10.4",
"typo3/cms-belog": "^10.4",
"typo3/cms-beuser": "^10.4",
"typo3/cms-core": "^10.4",
...
"vendor/site_package": "@dev",
"georgringer/news": "^8",
...
},
"autoload": {
"classmap": [
"public/typo3conf/ext/site_package/Classes"
],
"psr-4": {
"Vendor\\SitePackage\\": "public/typo3conf/ext/site_package/Classes"
}
},
"extra": {
"typo3/cms": {
"root-dir": "public",
"web-dir": "public"
}
},
"config": {
"vendor-dir": "vendor",
"bin-dir": "bin"
},
"scripts": {
"typo3-cms-scripts": [
"typo3cms install:generatepackagestates",
"typo3cms install:fixfolderstructure"
],
"post-autoload-dump": [
"@typo3-cms-scripts"
]
}
}
In ext:site_package
I have the following autoload section as well:
"autoload": {
"psr-4": {
"Vendor\\SitePackage\\": "Classes",
}
},
Do I need both? Why?
Upvotes: 1
Views: 1507
Reputation: 7939
You should never mix those 2 composer.json
.
As you already follow the approach of having a directory packages
(which is a good thing) each extension inside there needs an own composer.json
file which of course also needs a section
"psr-4": {
"Vendor\\MyExt\\": "Classes"
}
By requiring this package, this autoload information will be used.
If you would still have the custom extension inside typo3conf/ext/my_ext
, that composer.json
file would not be taken into account and you need something like
"psr-4": {
"Vendor\\MyExt\\": "typo3conf/ext/myext/Classes"
}
Upvotes: 2
Reputation: 3747
The autoload
part is only needed in your site package composer.json
. It's not necessary to put it also in the composer.json
in your root folder.
Please refer to the documentation how the composer.json
of your site package should look like.
If you still have problems with autoloading, try composer dump-autoload
or remove the extension and require it again. And make sure to check the upper-/lowercase of your namespace. It's case sensitive. If you change that after you required the site package, you need to remove and require the package again.
Upvotes: 2