我刚刚将我的第一个composer.json包添加到我创建的API中。
https://github.com/elvanto/api-php
这是我的文件的副本
{
"name": "elvanto/api-php",
"type": "library",
"description": "API PHP Library for elvanto church management software.",
"keywords": ["elvanto", "api"],
"homepage": "https://github.com/elvanto/api-php/",
"license": "MIT",
"authors": [
{
"name": "Ben Sinclair",
"homepage": "http://elvanto.com",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"classmap": [
"."
]
}
}
当我尝试使用Composer安装软件包时,我在终端
中得到了这个-$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Generating autoload files
在我的vendor /文件夹中,它会加载自动加载文件但不包含我的类文件:
autoload.php
composer/autoload_classmap.php
composer/autoload_namespaces.php
composer/autoload_real.php
composer/ClassLoader.php
我做错了吗?我尝试将composer.json文件更改为以下(我见过其他软件包)但我得到了一个完全不同的错误:
"autoload": {
"classmap": [
"elvanto_API.php"
]
}
错误是:
[RuntimeException]
Could not scan for classes inside "elvanto_API.php" which does not appear to be a file nor a folder
我想我很接近我只需要在这个方面有一点方向:)
答案 0 :(得分:1)
你第一次就做对了。 classmap部分只是一个目录列表,您可以在其中找到要自动加载的类。您无需在此部分中指定单个类名。
如果您查看生成的vendor / composer / autoload_classmap.php文件,您会看到它已将其选中:
$ cat vendor/composer/autoload_classmap.php
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'elvanto_API' => $baseDir . '/elvanto_API.php',
);
您现在可以在自动加载的样式中使用此类:
<?php
require_once 'vendor/autoload.php';
$test = new elvanto_API();