是composer的autoload必须有相同的文件结构?
It's that composer's autoload must have the same document structure?
问题是当我使用 symfony 2.7 时,我将自己的包上传到 composer packagist。
首先,我尝试 composer.json 那样
{
"name" : "funmi/sms-bundle",
"description" : "a develop components from funmitech",
"type" : "symfony-bundle",
"authors" : [{
"name" : "funmi",
"email" : "1535399875@qq.com"
}],
"keywords" : [
"funmi develop"
],
"license" : [
"MIT"
],
"require" : {
},
"autoload" : {
"psr-0" : {
"Funmi\SmsBundle" : ""
}
},
"target-dir" : "",
"repositories" : [{
}],
"extra" : {
"branch-alias" : {
"dev-master" : "1.0-dev"
}
}
}
但是当我在 appkernel.php 中新建 Funmi\SmsBundle\FunmiSmsBunle() 时,它说
namespace not exist
,然后我将目标目录的值更改为 /
或 src/
,但它仍然不起作用。
它仅在我将 target-dir
值设置为 Funmi\SmsBundle
时有效,现在问题是为什么我必须这样设置?
target-dir
已弃用,请勿使用。
我希望您的包 class 位于根目录中,对吗?这意味着您需要配置 PSR-4 自动加载器:
"autoload" : {
"psr-4" : {
"Funmi\SmsBundle\" : ""
}
},
这会将自动加载器配置为在 /FunmiSmsBundle.php
中搜索 Funmi\SmsBundle\FunmiSmsBundle
。
问题是当我使用 symfony 2.7 时,我将自己的包上传到 composer packagist。 首先,我尝试 composer.json 那样
{
"name" : "funmi/sms-bundle",
"description" : "a develop components from funmitech",
"type" : "symfony-bundle",
"authors" : [{
"name" : "funmi",
"email" : "1535399875@qq.com"
}],
"keywords" : [
"funmi develop"
],
"license" : [
"MIT"
],
"require" : {
},
"autoload" : {
"psr-0" : {
"Funmi\SmsBundle" : ""
}
},
"target-dir" : "",
"repositories" : [{
}],
"extra" : {
"branch-alias" : {
"dev-master" : "1.0-dev"
}
}
}
但是当我在 appkernel.php 中新建 Funmi\SmsBundle\FunmiSmsBunle() 时,它说
namespace not exist
,然后我将目标目录的值更改为 /
或 src/
,但它仍然不起作用。
它仅在我将 target-dir
值设置为 Funmi\SmsBundle
时有效,现在问题是为什么我必须这样设置?
target-dir
已弃用,请勿使用。
我希望您的包 class 位于根目录中,对吗?这意味着您需要配置 PSR-4 自动加载器:
"autoload" : {
"psr-4" : {
"Funmi\SmsBundle\" : ""
}
},
这会将自动加载器配置为在 /FunmiSmsBundle.php
中搜索 Funmi\SmsBundle\FunmiSmsBundle
。