[英]How to autoload a repository in composer which does not follow PSR-0 or PSR-4?
So, I'm trying to use jcleblanc/reddit-php-sdk , but it follows no standards whatsoever and does not have a repository available, so I've had to manually define it myself in my composer.json
file: 因此,我尝试使用jcleblanc / reddit-php-sdk ,但是它没有任何标准,并且没有可用的存储库,因此我不得不自己在
composer.json
文件中手动定义它:
"repositories" : [{
"type": "package",
"package": {
"name": "jcleblanc/reddit-php-sdk",
"version": "dev-master",
"source": {
"url": "https://github.com/jcleblanc/reddit-php-sdk",
"type": "git",
"reference": "origin/master"
},
"autoload": {
"classmap": ["reddit-php-sdk/", "/", "reddit.php", "config.php"]
}
}
}],
Directory structure in vendor/
here: vendor/
目录结构:
However, when I then run composer dump-autoload
, the classes in this project are not autoloaded, and don't appear in any of the autoload_*.php
composer files. 但是,当我随后运行
composer dump-autoload
,该项目中的类不会自动加载,并且不会出现在任何autoload_*.php
composer文件中。 This means I of course get a "Class 'reddit' not found"
error whenever I try and use it. 这意味着,当我尝试使用它时,我当然会收到
"Class 'reddit' not found"
错误"Class 'reddit' not found"
。
Solutions? 解决方案?
You can use Composer's file
autoloading . 您可以使用Composer的
file
自动加载功能 。
{
"autoload": {
"files": ["src/MyLibrary/functions.php"]
}
}
However, that's more geared towards helper function files and I've not tried it with a Class file (although there's no reason it shouldn't work). 但是,它更适合于辅助函数文件,并且我没有在Class文件中进行过尝试(尽管没有理由不起作用)。
最终自己分叉了项目,但事实证明原始项目还是被破坏了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.