Bug #57604

PackageManager is unable to resolve composer PSR-4 namespaces

Added by Jacob Rasmussen over 1 year ago. Updated about 1 month ago.

Status:Closed Start date:2014-04-03
Priority:Should have Due date:
Assigned To:- % Done:

0%

Category:Package Manager Spent time: -
Target version:-
TYPO3 Version:6.2 Is Regression:No
PHP Version: Sprint Focus:
Complexity:

Description

Currently the package manager is only able to resolve PSR-0 namespaces.

This makes it impossible to include composer packages which rely on PSR-4 namespaces, such as Pelago\Emogrifier, unless the composer autoloader is included manually in a TYPO3 extension.

Steps to reproduce

Create a composer.json in the root of site path like this:

{
  "config": {
    "vendor-dir": "Packages/Libraries" 
  },
  "minimum-stability": "dev" 
  "require": {
    "pelago/emogrifier": "*" 
  }
}

Run "composer install" in the path in order to fetch the package

Ensure typo3conf/PackageStates.php is updated - this can be done by uninstalling and installing a TYPO3 extension.

Activate the package manually by editing PackageStates.php, as it currently isn't possible to activate composer packages through the UI or CLI

Try to instantiate the \Pelago\Emogrifier class which will fail


Related issues

related to Core - Task #64361: Improve class loading performance Resolved 2015-01-19
related to Core - Bug #54491: PackageManager doesn't solve/recognize real composer pack... Under Review 2013-12-18

History

#1 Updated by Mathias Brodala 10 months ago

Actually the whole autoloading is a mess. First you have to put your classes into Classes/ since that path is hardcoded and written to the PackageStates.php. But then you must not actually use psr-0 within that directory but psr-4 instead. If you specify psr-4 instead, the package key is converted from Vendor.Package to vendor.package and classes cannot be found anymore.

If you manually fix the casing in the PackageStates.php, the classes are found again. Funny: if you enter the extension manager then, the package in question shows up twice as Vendor.Package and vendor.package. Removing both from PackageStates.php leaves only vendor.package again upon next scan.

Summarized for Vendor\Package\Class:

  • psr-0 + Classes/Vendor/Package/Class.php: correct, but not found
  • psr-4 + Classes/Class.php: correct, but not found
  • psr-0 + Classes/Class.php: incorrect, but found

Conclusion: Neither psr-0 nor psr-4 are properly supported.

#2 Updated by Peter Niederlag 5 months ago

  • Status changed from New to Needs Feedback

As the composer autoloader was added into the Core with version 6.2.10 this problem might have been solved by now.

Can you please recheck if the problem is still present for you on > 6.2.10?

Please have a look at http://wiki.typo3.org/ComposerClassLoader for more details

#3 Updated by Mathias Brodala 5 months ago

It seems to work with the current 6.2.11, even without preferring the Composer autoloader.

#4 Updated by Mathias Brodala 5 months ago

Apparently the important bit is the "type": "typo3-cms-extension" option in the Composer manifest of the extension. If it is present, the described issue can be avoided.

#5 Updated by Alexander Opitz about 1 month ago

So we can close this issue?

#6 Updated by Mathias Brodala about 1 month ago

Yes, works for me.

#7 Updated by Alexander Opitz about 1 month ago

  • Status changed from Needs Feedback to Closed

Also available in: Atom PDF