4

I want to add a bitbucket repository to my vendor folder using composer. This is what I have in my composer.json:

{
    "require": {
        "silex/silex": "~1.1",
        "doctrine/dbal": "2.2.*",
        "twig/twig" : "1.*",
        "symfony/twig-bridge": "~2.3",
        "twitter/bootstrap": "*",
        "symfony/assetic-bundle": "2.1.*",
        "leafo/lessphp": "*",
        "silex/web-profiler": "~1.0",
        "symfony/security": "~2.3",
        "symfony/form": "~2.3",
        "symfony/validator": "~2.3",
        "symfony/config": "~2.3",
        "symfony/translation": "~2.3",
        "monolog/monolog": ">=1.0.0",
        "symfony/yaml": "~2.3",
        "jasongrimes": "dev-master"
    },
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "jasongrimes",
                "version": "dev-master",
                "source": {
                    "url": "mybitbucketurl",
                    "type": "git",
                    "reference": "origin/master"
                }
            }
        }
    ]
}

I don't have a composer.json in my bitbucket repository that I want to add through composer. Now when I run my application I get the following error:

Fatal error: Class 'SimpleUser\UserServiceProvider' not found in app/bootstrap.php on line 82

How can I make sure this is also in the autoloader?

nielsv
  • 6,540
  • 35
  • 111
  • 215
  • Shouldn't it be only `master` inside `reference`? Apart from that it's almost identical to what I use to clone a GitHub repository into my vendors. – Paulo Freitas Apr 22 '14 at 13:53
  • your error doesn't relate to composer or bitbucket, PHP just cannot load the class – Hieu Vo Apr 22 '14 at 18:45
  • Where is the SimpleUser\UserServiceProvider coming from? are you trying to PSR-0 autoload it? – Joseph Apr 24 '14 at 16:17

1 Answers1

17

When you specify a package repository, you are basically providing all of the details that would be in that package's composer.json if it had one. For autoloading to work, an autoload property for the package must be specified. The composer manual has details on the autoload property.

If your bitbucket repository conforms to PSR-0 or PSR-4, you simply need to specify the correct standard, and where the classes to be loaded are stored in the repository. For example, with PSR-4 and your classes stored in the src/ directory:

{
    "require": {
        "jasongrimes": "dev-master"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "jasongrimes",
                "version": "dev-master",
                "source": {
                    "url": "mybitbucketurl",
                    "type": "git",
                    "reference": "origin/master"
                },
                "autoload": {
                    "psr-4": { "": "src/" }
                }
            }
        }
    ]
}

Otherwise, you can use classmap to specify directories or files to be scanned for .php or .inc files with classes. For example, if the class you are attempting to load is located in the file SimpleUser/UserServiceProvider.php in your repository:

{
    "require": {
        "jasongrimes": "dev-master"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "jasongrimes",
                "version": "dev-master",
                "source": {
                    "url": "mybitbucketurl",
                    "type": "git",
                    "reference": "origin/master"
                },
                "autoload": {
                    "classmap": [ "SimpleUser/UserServiceProvider.php" ]
                }
            }
        }
    ]
}
kloor
  • 236
  • 2
  • 3