首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >您要注册的类不可用[TYPO3 8.7.26]

您要注册的类不可用[TYPO3 8.7.26]
EN

Stack Overflow用户
提问于 2019-06-20 10:06:04
回答 1查看 463关注 0票数 0

我正在TYPO3中安装自创建的扩展。我的composer.json文件ar location /var/www/html/typo3 3如下所示:

代码语言:javascript
复制
{
        "repositories": [{
                        "type": "composer",
                        "url": "https://composer.typo3.org/"
                },
                {
                        "type": "package",
                        "package": {
                                "name": "Bm/ah-content-api",
                                "version": "0.0.1",
                                "type": "typo3-cms-extension",
                                "source": {
                                        "url": "https://user@bitbucket.org/company/ah_config_typo3.git",
                                        "type": "git",
                                        "reference": "master"
                                },
                                "autoload": {
                                        "psr-4": {
                                                "bm\\ah-content-api\\": "typo3conf/ext/ah-contentapi/Classes"
                                        }
                                }
                        }
                },

                {
                        "type": "package",
                        "package": {
                                "name": "Bm/ah-contentelements",
                                "version": "0.0.1",
                                "type": "typo3-cms-extension",
                                "source": {
                                        "url": "https://user@bitbucket.org/company/ah_contentelements_typo3.git",
                                        "type": "git",
                                        "reference": "master"
                                },
                                "autoload": {
                                        "psr-4": {
                                                "bm\\ah-contentelements\\": "typo3conf/ext/ah-contentelements/Classes",
                                        }
                                }
                        }
                }
        ],
"name": "typo3/cms-base-distribution",
        "description": "TYPO3 CMS Base Distribution",
        "license": "GPL-2.0-or-later",
        "require": {
                "helhum/typo3-console": "^4.9.3 || ^5.2",
                "typo3/cms-about": "^8.7.10",
                "typo3/cms-belog": "^8.7.10",
                "typo3/cms-beuser": "^8.7.10",
                "typo3/cms-context-help": "^8.7.10",
                "typo3/cms-documentation": "^8.7.10",
                "typo3/cms-felogin": "^8.7.10",
                "typo3/cms-fluid-styled-content": "^8.7.10",
                "typo3/cms-form": "^8.7.10",
                "typo3/cms-func": "^8.7.10",
                "typo3/cms-impexp": "^8.7.10",
                "typo3/cms-info": "^8.7.10",
                "typo3/cms-info-pagetsconfig": "^8.7.10",
                "typo3/cms-rte-ckeditor": "^8.7.10",
                "typo3/cms-setup": "^8.7.10",
                "typo3/cms-sys-note": "^8.7.10",
                "typo3/cms-t3editor": "^8.7.10",
                "typo3/cms-tstemplate": "^8.7.10",
                "typo3/cms-viewpage": "^8.7.10",
                "typo3/cms-wizard-crpages": "^8.7.10",
                "typo3/cms-wizard-sortpages": "^8.7.10",
                "dmitryd/typo3-realurl": "2.*",
                "GridElementsTeam/Gridelements": "8.2.*",
                "clickstorm/cs_seo": "3.*",
                "Bm/ah-content-api": "0.0.1",
                "Bm/ah-contentelements": "0.0.1"
        },
        "scripts": {
                "typo3-cms-scripts": [
                        "typo3cms install:fixfolderstructure",
                        "typo3cms install:generatepackagestates"
                ],
                "post-autoload-dump": [
                        "@typo3-cms-scripts"
                ]
        },
        "extra": {
                "typo3/cms": {
                        "web-dir": "public"
                },
                "helhum/typo3-console": {
                        "comment": "This option is not needed ay more for helhum/typo3-console 5.x",
                        "install-extension-dummy": false
                }
        }
}

扩展的数据存储在git repos中。在根目录中使用每个composer.json文件:

代码语言:javascript
复制
{
  "name": "Bm/ah-contentelements",
  "type": "typo3-cms-extension",
  "description": "descr,
  "homepage": "http://www.company.de/",
  "suggest": {
  },
  "require": {
    "typo3/cms-core": ">=8.0.0,<9.0"
  },
  "author": [
    {
      "name": "name",
      "email": "sdsd@company.de"
    }
  ],
  "autoload": {
    "psr-4": {
      "Bm\\AhContentelements\\": "Classes/"
    }
  }
}

代码语言:javascript
复制
 {
    "name": "bm/ah-content-api",
    "type": "typo3-cms-extension",
    "description": "Content API Extension",
    "homepage": "http://www.company.de/",
    "license": [
        "GPL-2.0+"
    ],
    "require": {
        "typo3/cms-core": ">=7.5.0,<9.0"
    },
    "autoload": {
        "psr-4": {
            "Bm\\AhContentapi\\": "Classes/"
        }
    },
    "replace": {
        "ah_contentapi": "self.version",
        "typo3-ter/ah_contentapi" : "self.version"
    }
}

我运行了以下命令:

sudo composer update

sudo composer dump-autoload

不过,在TYPO3中仍有一些类不可用。

当我试图运行时出现错误消息:

代码语言:javascript
复制
#1411840171: The class "Bm\AhContentelements\Rendering\VideoTagRenderer" you are trying to register is not available

我使用的是TYPO3 8.7.26

VideoTagRenderer:

代码语言:javascript
复制
<?php
namespace Bm\AhContentelements\Rendering;


/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\FileReference;

/**
 * Class VideoTagRenderer
 */
class VideoTagRenderer extends \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer
{
    /**
     * Mime types that can be used in the HTML Video tag
     *
     * @var array
     */
    protected $possibleMimeTypes = ['video/mp4', 'video/webm', 'video/quicktime', 'video/ogg', 'application/ogg'];

    /**
     * Returns the priority of the renderer
     * This way it is possible to define/overrule a renderer
     * for a specific file type/context.
     * For example create a video renderer for a certain storage/driver type.
     * Should be between 1 and 100, 100 is more important than 1
     *
     * @return int
     */
    public function getPriority()
    {
        return 2;
    }

    /**
     * Check if given File(Reference) can be rendered
     *
     * @param FileInterface $file File or FileReference to render
     * @return bool
     */
    public function canRender(FileInterface $file)
    {
        return in_array($file->getMimeType(), $this->possibleMimeTypes, true);
    }

    /**
     * Render for given File(Reference) HTML output
     *
     * @param FileInterface $file
     * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
     * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
     * @param array $options controls = TRUE/FALSE (default TRUE), autoplay = TRUE/FALSE (default FALSE), loop = TRUE/FALSE (default FALSE)
     * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
     * @return string
     */
    public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false)
    {

        // If autoplay isn't set manually check if $file is a FileReference take autoplay from there
        if (!isset($options['autoplay']) && $file instanceof FileReference) {
            $autoplay = $file->getProperty('autoplay');
            if ($autoplay !== null) {
                $options['autoplay'] = $autoplay;
            }
        }

        $attributes = [];
        if ((int)$width > 0) {
            $attributes[] = 'width="' . (int)$width . '"';
        }
        if ((int)$height > 0) {
            $attributes[] = 'height="' . (int)$height . '"';
        }
        if (!isset($options['controls']) || !empty($options['controls'])) {
            $attributes[] = 'controls';
        }
        if (!empty($options['autoplay'])) {
            $attributes[] = 'autoplay';
        }
        if (!empty($options['muted'])) {
            $attributes[] = 'muted';
        }
        if (!empty($options['loop'])) {
            $attributes[] = 'loop';
        }
        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
            if (!empty($options[$key])) {
                $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
            }
        }

        $extension = $file->getExtension();
        if ('ogv' == $extension) {
            $extension = 'ogg';
        }

        $useMimetype = 'video/'.$extension;


        return sprintf(
            '<video%s><source src="%s" type="%s"></video>',
            empty($attributes) ? '' : ' ' . implode(' ', $attributes),
            htmlspecialchars($file->getPublicUrl($usedPathsRelativeToCurrentScript)),
            $useMimetype
        );
    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-06-20 11:15:16

正如链接的文章:中提到的,问题是您的包中的composer.json被忽略了。

相反,您必须在主composer.json文件中设置正确的psr-4。我修复了提供的片段以匹配它:

代码语言:javascript
复制
    "autoload": {
      "psr-4": {
        "Bm\\AhContentapi\\": "typo3conf/ext/ah-contentapi/Classes"
      }
    }

    "autoload": {
      "psr-4": {
        "Bm\\AhContentelements\\": "typo3conf/ext/ah-contentelements/Classes"
      }
    }

http://blog.pepa.info/php-html-css/composer/composer-not-autoloading-your-package/

Sidenote:移除额外的>helhum/typo3-控制台部分\它不再需要

编辑1:

只要扩展已经是vcs代码的一部分(签入),您就可以简单地避免存储库部分,只需将以下内容添加到主composer.json文件中:

代码语言:javascript
复制
"autoload": {
  "psr-4": {
    "Bm\\AhContentelements\\": "typo3conf/ext/ah-contentelements/Classes",
    "Bm\\AhContentapi\\": "typo3conf/ext/ah-contentapi/Classes"
  }
}

如果扩展是,而不是vcs/git的一部分,您只需使用版本9中的约定,并在名为Packages/ TYPO3根目录的文件夹中提取自己的扩展。然后添加以下“存储库”条目,而不是当前的包条目:

代码语言:javascript
复制
    {
        "type": "path",
        "url": "Packages/*",
        "options": {
            "symlink": true
        }
    }

在下一个编写器运行之后,您应该会看到您的扩展现在已经链接起来了。

记住三件事:

  1. 基于windows文件系统的Symlink行为可以在compsoer符号链接期间创建不正确的符号链接。然后再正确地重新创建它们。
  2. 重新检查路径,并注意由于路径不正确而产生的任何问题。
  3. composer installcomposer update的差异
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56683618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档