Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It's that composer's autoload must have the same document structure?

the question is when I use symfony 2.7,I upload my own bundle onto composer packagist. First I try my composer.json like that

{
"name" : "funmi/sms-bundle",
"description" : "a develop components from funmitech",
"type" : "symfony-bundle",
"authors" : [{
    "name" : "funmi",
    "email" : "[email protected]"
}],
"keywords" : [
    "funmi develop"
],
"license" : [
    "MIT"
],
"require" : {
},
"autoload" : {
    "psr-0" : {
        "Funmi\\SmsBundle" : ""
    }
},
"target-dir" : "",
"repositories" : [{
}],
"extra" : {
    "branch-alias" : {
        "dev-master" : "1.0-dev"
    }
  }
}

But when I new Funmi\SmsBundle\FunmiSmsBunle() in appkernel.php it says

namespace not exist

,than I change the target-dir's value to / or src/ but it still not work. It only work when I set target-dir value to Funmi\SmsBundle,now the problem is why i must set like that?

like image 319
LeeDD Avatar asked Nov 26 '25 20:11

LeeDD


1 Answers

target-dir is deprecated, do not use it.

I expect that your bundle class lives in the root directory, correct? That means you need to configure the PSR-4 autoloader:

"autoload" : {
    "psr-4" : {
        "Funmi\\SmsBundle\\" : ""
    }
},

This configures the autoloader to search for Funmi\SmsBundle\FunmiSmsBundle in /FunmiSmsBundle.php.

like image 124
Wouter J Avatar answered Nov 29 '25 13:11

Wouter J