无法加载Composer程序包

时间:2012-10-13 21:35:50

标签: php package composer-php httpful

我是使用composer软件包的新手。我有一些工作,但我遇到了一个我想使用的谷歌地图包,我无法正确加载它。

php-google-maps 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...
?>

此操作失败,显示消息Class 'PHPGoogleMaps\Map' not found

composer.json文件:

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

1 个答案:

答案 0 :(得分:1)

对于PHPGoogleMaps包,composer.json中存在一个错误。安装后的目录结构不遵循PSR-0自动加载标准。

我提交了PR修复问题,但在修复之前,您可以为包定义自己的存储库(更改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"
            }
        }
    ]
}