【问题标题】:ApiPlatform & Mercure (private topics)ApiPlatform & Mercure(私人主题)
【发布时间】:2020-07-04 14:00:18
【问题描述】:

我的架构基于 Symfony 4.4 / ApiPLatform / Mercure / Angular 9。我通过在我的 resources.yaml ApiPlatform conf 文件中添加 mercure:true 从 Mercure 进行了简单的推送。现在我需要将更新设为私有。因此,对于 ApiPlatform,我必须添加参数 private:true。 但 API 响应现在是:

自 Mercure 0.10 起,目标不再存在。将更新标记为私有,或将 Mercure 组件降级到版本 0.3

这是我的 yaml 配置:

resources:
    App\Entity\Order:
        attributes:
            mercure:
                - private: true
                - topics: ['object.getMercureTopics()']

正确的配置应该是什么?

【问题讨论】:

    标签: symfony api-platform.com mercure


    【解决方案1】:

    事实上,ExpressionLanguage 并没有像我想的那样在每个选项中进行评估,只有在配置的选项是字符串时才会评估。 因此,如果需要 ExpressionLanguage 主题(或其他所有内容),解决方案如下:

    public function getMercureOptions()
    {
        $topic = sprintf(
            '%s/%s',
            self::MERCURE_TOPIC_PREFIX,
            $this->getSomethingFromTheObject()
        );
    
        return [
            "private" => true,
            "topics" => [$topic]
        ];
    }
    

    然后,yaml 配置文件应该是:

    resources:
        App\Entity\Order:
            attributes:
                mercure: "object.getMercureOptions()"
    

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2014-10-16
      • 2021-05-09
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 2012-03-30
      • 1970-01-01
      • 2010-11-20
      相关资源
      最近更新 更多