简体   繁体   English

autoload bitbucket repository + composer.json

[英]autoload bitbucket repository + composer.json

I want to add a bitbucket repository to my vendor folder using composer. 我想使用composer将bitbucket存储库添加到我的vendor文件夹中。 This is what I have in my composer.json: 这就是我在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. 我在bitbucket存储库中没有composer.json,我想通过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? 如何确保这也在自动装带器中?

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. 当您指定包存储库时,您基本上提供了该包的composer.json中的所有详细信息(如果有的话)。 For autoloading to work, an autoload property for the package must be specified. 要使自动加载工作,必须指定程序包的autoload属性。 The composer manual has details on the autoload property . 作曲家手册有关于autoload属性的详细信息

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. 如果您的bitbucket存储库符合PSR-0或PSR-4,您只需指定正确的标准,以及要加载的类存储在存储库中的位置。 For example, with PSR-4 and your classes stored in the src/ directory: 例如,使用PSR-4和您的类存储在src/目录中:

{
    "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. 否则,您可以使用classmap指定要扫描带有类的.php.inc文件的目录或文件。 For example, if the class you are attempting to load is located in the file SimpleUser/UserServiceProvider.php in your repository: 例如,如果您尝试加载的类位于存储库中的SimpleUser/UserServiceProvider.php文件中:

{
    "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" ]
                }
            }
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM