duandong1869
2015-05-04 21:49
浏览 157

使用composer加载git repo - 自动加载问题

I have a github repository https://github.com/KoulSlou/UPS and I would like to add it to my project.

In project root I created composer.json file and defined the following autoloading properties:

{
    "autoload": {
        "files": [
            "libraries/Ups/Ups.php",
            "libraries/Ups/Ups_Base.php",
            "libraries/Ups/Ups_Base_Response.php",
            "libraries/Ups/Ups_Live_Rates.php"
        ]
    }
}

When I run

php composer.phar install 

repository is being downloaded, but it looks like autoloader is not working. When I try to initialize one of the classes

$test = new Ups()

I got the following error:

Fatal error: Class 'Ups' not found in application/....

Did I define "autoload" property incorrectly?

图片转代码服务由CSDN问答提供 功能建议

我有一个github存储库 https://github.com/KoulSlou/UPS 我想将它添加到我的项目中。

在项目根目录中我创建了composer.json文件 并定义了以下自动加载属性:

  {
“autoload”:{
“files”:[
“libraries / Ups / Ups.php”,
  “libraries / Ups / Ups_Base.php”,
“libraries / Ups / Ups_Base_Response.php”,
“libraries / Ups / Ups_Live_Rates.php”
] 
} 
} 
   
 
 

当我运行

  php composer.phar install 
   
 
 

存储库是 正在下载,但看起来自动加载器无法正常工作。 当我尝试初始化其中一个类

  $ test = new Ups()
   
 
 

我得到了 以下错误:

 致命错误:在应用程序/ .... 
   
 
 

中找不到类'Ups' 我是否错误地定义了“autoload”属性?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongmale0656 2015-05-21 04:52
    已采纳

    Finaly, I have found out what was the problem. composer.json file in the project I was trying to load - UPS library -was invalid. I was able to download files when I ran:

    composer.phar install
    

    but it looks like composer.json file was ignored. I found it out when I ran

    composer.phar update
    

    and got

    No valid composer.json was found
    

    With option -v I got error that "name" is undefined index. So, I simply added "name" field to the composer.json. Final version is:

    {
        "name":"KoulSlou/UPS",
        "autoload": {
            "files": [
                "libraries/Ups/Ups.php",
                "libraries/Ups/Ups_Base.php",
                "libraries/Ups/Ups_Base_Response.php",
                "libraries/Ups/Ups_Live_Rates.php"
             ]
        }
    }
    
    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题