3

Packagist does not allow package names to have capital letters. To workaround this, it recommends using hyphens -. Thus my package name went from TableCreator to table-creator. Unfortunately, this seems to have prevented my library from autoloading with the following error message:

Class 'Company\TableCreator\DatabaseField' not found

This error message disappears as soon as I manually include the specific file rather than relying on the vendor/autoload.php file.

My packages composer.json file is as follows

{
    "name": "company/table-creator",
    "type": "library",
    "description": "Package creating or editing MySQL tables.",
    "keywords": ["mysql", "mysqli","models"],
    "license": "MIT",
    "authors": [
        {
            "name": "xxx xxx",
            "email": "xxx@xxx.org",
            "role": "Developer"
        }
    ],
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "psr-4": {
            "company\\table-creator\\": ""
        }
    }
}

The namespace declared in the file is still namespace Company\TableCreator;

What do I need to tweak in the composer config for the classes to autload now that the package name has a hyphen?

Programster
  • 12,242
  • 9
  • 49
  • 55
  • seems like this was also my case, however not yet investigated why, but the solution below did not seem to help to load my hyphen-less class, anyway packagist needs packages without capital letters, however I still think package can be named in lowercase and classes can stay snake-case – FantomX1 Jun 28 '20 at 21:29

1 Answers1

3

You need to revert the change to the PSR-4 namespace prefix:

{
    "autoload": {
        "psr-4": {
            "Company\\TableCreator\\": ""
        }
    }
}
localheinz
  • 9,179
  • 2
  • 33
  • 44