简体   繁体   English

Hateoas PHP库中的组如何工作?

[英]How to work with groups in Hateoas PHP library?

I'm using Hateoas library with Symfony. 我在Symfony中使用Hateoas库。

And I have a Doctrine entity and want to restrict some of the embedded content. 我有一个Doctrine实体,想限制某些嵌入式内容。 I saw that Hateoas has exclusion for groups but I don't have any idea how to configure them and didn't found nothing about it in lib documentation. 我看到Hateoas排除了组,但是我不知道如何配置它们,并且在lib文档中也没有找到任何相关信息。 Any help would be appreciated. 任何帮助,将不胜感激。

If you define a serializer group in your entity 如果您在实体中定义序列化程序组

class Client
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     *
     * @JMS\Expose
     * @JMS\Groups({"default", "full"})
     */
    private $firstName;

    ...

}

You should also define it in the HATEOAS annotation (or the configuration system you're using) 您还应该在HATEOAS批注(或您使用的配置系统)中定义它

 * @Hateoas\Relation("_self",
 *      href = @Hateoas\Route("api_clients_get_client", parameters = {"id" = "expr(object.getId())"}, absolute = true),
 *      exclusion = @Hateoas\Exclusion(groups={"default","full"})
 * )

This makes sense as you don't want to expose your links if you're not exposing your properties. 这是有道理的,因为如果您不公开属性,则不想公开链接。

ie you have two groups "public" and "admin" 即您有两个组“公共”和“管理员”

In admin you're likely exposing things that are hidden to a public call to your api. 在管理员中,您可能会将隐藏的内容公开给您的api公开调用。 But if you don't have control over the HATEOAS links you're exposing in the calls, you'd be probably exposing unwanted links in your "public" call 但是,如果您无法控制要在呼叫中公开的HATEOAS链接,则可能会在“公开”呼叫中公开不需要的链接

Exclusion is covered in this section: https://github.com/willdurand/Hateoas#exclusion . 本节涵盖了排除: https : //github.com/willdurand/Hateoas#exclusion You should probably rephrase your question so that we can help you in a better way. 您可能应该改写您的问题,以便我们可以更好地为您提供帮助。

I personally spent quite a lot of time writing this documentation, it would be great to know what is missing ;-) 我个人花了很多时间编写此文档,很高兴知道缺少的内容;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM