Search code examples
phpgitcomposer-phpautoloader

Load git repo with composer - autoloading issue


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?


Solution

  • 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"
             ]
        }
    }