如何在PHP 7下扩展Femanager控制器 [英] How to extend femanager controller under php 7

查看:314
本文介绍了如何在PHP 7下扩展Femanager控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于使用的是PHP 7.0和更高版本,因此php的严格模式会生成如下警告:

Since using PHP 7.0 and higher, the strict mode of php generates warnings like this:

PHP Warning: Declaration of In2code\Femanagerextended\Controller\EditController::updateAction(In2code\Femanagerextended\Domain\Model\User $user) should be compatible with In2code\Femanager\Controller\EditController::updateAction(In2code\Femanager\Domain\Model\User $user) in ($PATH)\typo3conf\ext\femanagerextended\Classes\Controller\EditController.php line 17

当尝试使用手册最佳实践部分中描述的方式扩展TYPO3 Extension femanager的现有控制器时:

when trying to extend an existing controller of the TYPO3 Extension femanager using the described way in the best practice section of the manual:

<?php
namespace In2code\Femanagerextended\Controller;
use In2code\Femanager\Controller\EditController as EditControllerFemanager;
use In2code\Femanagerextended\Domain\Model\User;
/**
 * Class EditController
 *
 * @package In2code\Femanagerextended\Controller
 */
class EditController extends EditControllerFemanager
{
    /**
     * action update
     *
     * @param User $user
     * @validate $user In2code\Femanager\Domain\Validator\ServersideValidator
     * @validate $user In2code\Femanager\Domain\Validator\PasswordValidator
     * @return void
     */
     public function updateAction(User $user)
     {
         parent::updateAction($user);
     }
}

推荐答案

Wolfgang Klinger提出的一种可行解决方案是对\ TYPO3 \ CMS \ Extbase \ Mvc \ Controller \ Argument类进行XClass

A possible solution, worked out by Wolfgang Klinger, is to XClass the \TYPO3\CMS\Extbase\Mvc\Controller\Argument class.

此类具有受保护的属性"dataType",该属性通常没有设置器.

This class has a protected property "dataType", which usually has no setter.

使用TYPO3的XClass机制,可以添加setDataType方法来启用此属性的手动覆盖.

Using the XClass mechanism of TYPO3 it is possible to add a setDataType method to enable the manual overriding of this property.

为此,现在可以覆盖扩展的edit/invitation/new-controller的(魔术)初始化动作中通常自动检测到的数据类型.

Armed with this, it's now possible to overwrite the usually automatic detected data type inside the (magic) initialize actions of the extending edit/invitation/new-controller.

重要的是,不要更改普通"动作(newAction,createAction ...)的类型提示和注释,但要在相应的初始化动作中添加以下内容:

The important thing is, not to change the type hints and annotations of the "normal" Actions (newAction, createAction ...), but add something like this to the corresponding initialize actions:

public function initializeNewAction()
{
    if ($this->arguments->hasArgument('user')) {
        // Workaround to avoid php7 warnings of wrong type hint.
        /** @var \Mediagear\Jdcompetition\Xclass\Extbase\Mvc\Controller\Argument $user */
        $user = $this->arguments['user'];
        $user->setDataType(\Vendor\Extension\Domain\Model\User::class);
    }
}

这篇关于如何在PHP 7下扩展Femanager控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆