duandong1869 2015-05-04 21:49
浏览 169
已采纳

使用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?

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀