Search code examples
phppackagecomposer-phphttpful

Can't Load Composer Package


I'm new to using composer packages. I've gotten a few to work, but I came across a Google Maps package I'd like to use and I can't get it to load properly.

php-google-maps package

My attempt at using the package:

<?php

require './vendor/autoload.php';

use \PHPGoogleMaps\Service\Geocoder;
use \PHPGoogleMaps\Service\GeocodeError;
use \PHPGoogleMaps\Service\GeocodeResult;
use \PHPGoogleMaps\Service\GeocodeException;

$map = new \PHPGoogleMaps\Map;
// Rest of GMap code goes here...
?>

This fails with the message Class 'PHPGoogleMaps\Map' not found

composer.json File:

{
    "require" : {
        "nategood/httpful":"*",
        "nesbot/carbon": "dev-master",
        "php-google-maps/php-google-maps": "dev-master"
    }
}

Solution

  • There's a bug in the composer.json for PHPGoogleMaps package. Directory structure after the installation doesn't follow PSR-0 autoloading standard.

    I submitted a PR fixing the problem but until it's fixed you can define your own repository for the package (changing the target-dir):

    {
        "require" : {
            "nategood/httpful":"*",
            "nesbot/carbon": "dev-master",
            "jakzal/php-google-maps": "dev-master"
        },
        "repositories": [
            {
                "type": "package",
                "package": {
                    "name": "jakzal/php-google-maps",
                    "version": "dev-master",
                    "source": {
                        "url": "https://github.com/galen/PHPGoogleMaps",
                        "type": "git",
                        "reference": "master"
                    },
                    "autoload": {
                        "psr-0": {"PHPGoogleMaps": ""}
                    },
                    "target-dir": "PHPGoogleMaps"
                }
            }
        ]
    }