autoload bitbucket repository + composer.json(自动加载 bitbucket 存储库 + composer.json)
问题描述
我想使用 Composer 将 bitbucket 存储库添加到我的供应商文件夹中.这就是我在 composer.json 中的内容:
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"
}
}
}
]
}
我的 bitbucket 存储库中没有想要通过 composer 添加的 composer.json.现在,当我运行我的应用程序时,出现以下错误:
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 'SimpleUserUserServiceProvider' not found in app/bootstrap.php on line 82
我如何确保它也在自动加载器中?
How can I make sure this is also in the autoloader?
推荐答案
当您指定一个包存储库时,您基本上提供了该包的 composer.json(如果有的话)中的所有详细信息.要使自动加载工作,必须指定包的 autoload 属性.作曲家手册有关于autoload属性的详细信息.
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.
如果您的 bitbucket 存储库符合 PSR-0 或 PSR-4,您只需指定正确的标准,以及要加载的类在存储库中的存储位置.例如,使用 PSR-4 并将您的类存储在 src/ 目录中:
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/" }
}
}
}
]
}
否则,您可以使用 classmap 指定要扫描的目录或文件,以查找带有类的 .php 或 .inc 文件.例如,如果您尝试加载的类位于存储库中的文件 SimpleUser/UserServiceProvider.php 中:
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" ]
}
}
}
]
}
这篇关于自动加载 bitbucket 存储库 + composer.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自动加载 bitbucket 存储库 + composer.json
基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
