[英]TYPO3 7.6 - How can I autoload composer packages?
I've created a TYPO3 7.6 extension with the extension builder. 我已经使用扩展构建器创建了TYPO3 7.6扩展。 Now I want to add and autoload composer installed packages. 现在,我想添加并自动加载composer安装的软件包。 I read that ext_autoload.php won't be loaded since TYPO3 version 7 in general. 我读到,从TYPO3 7版开始,一般不会加载ext_autoload.php。 For this you should use the ext_emconf.php
OR the composer.json
in the root path of your extension. 为此,您应该在扩展的根路径中使用ext_emconf.php
或 composer.json
。
So I've setup the following composer.json
and installed it with the composer.phar. 因此,我设置了以下composer.json
并将其与composer.phar一起安装。
{
"require": {
"hybridauth/hybridauth": "v3.0.0-rc.1"
},
"config": {
"vendor-dir": "Vendor"
},
"autoload": {
"psr-4": {
"Vendor\\Package\\": "Classes"
},
"classmap": [
"Vendor/hybridauth/hybridauth/src"
]
}
}
Now there is the Vendor/hybridauth/hybridauth/src
as expected but the autoloader of TYPO3 doesn't find for example the Vendor/hybridauth/hybridauth/src/Hybridauth.php
defined class Hybridauth
. 现在按预期提供了Vendor/hybridauth/hybridauth/src
,但是TYPO3的自动加载器找不到例如Vendor/hybridauth/hybridauth/src/Hybridauth.php
定义的类Hybridauth
。 I've checked it with: 我已经检查过:
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(get_declared_classes());
What did I miss? 我错过了什么? What do I have to add/change/rethink? 我必须添加/更改/重新思考什么?
Your json file content like below. 您的json文件内容如下所示。
{
"require": {
"hybridauth/hybridauth": "v3.0.0-rc.1"
},
"config": {
"vendor-dir": "Vendor"
},
"autoload": {
"psr-4": {
"vendor\\extensionName\\": "Classes"
},
"classmap": [
"Vendor/hybridauth/hybridauth/src/"
],
"files": [
"Vendor/hybridauth/hybridauth/src/Hybridauth.php"
]
}
}
It was my fault. 这都是我的错。 TYPO3 already autoloads already the psr-4 called environments. TYPO3已经自动加载了称为psr-4的环境。 But I had to have add the autoloader of Hybridauth itself as well like: 但是我必须添加Hybridauth本身的自动加载器,例如:
<?php
namespace Vendor\Package\Service;
require_once dirname(dirname(dirname(__FILE__))) . '/Vendor/autoload.php';
class SomeService extends \TYPO3\CMS\Sv\AbstractAuthenticationService{
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.