ikucheriavenko
8/30/2017 - 10:30 AM

HATEOAS

HATEOAS

<?php

namespace AppBundle\Serializer\Hateoas;

use AppBundle\Entity\Brand;
use AppBundle\Entity\UserBrandRegistry;
use Hateoas\Configuration as Hateoas;
use Hateoas\Configuration\Metadata\ClassMetadataInterface;
use Hateoas\Representation\Factory\PagerfantaFactory;

/**
 * Class BrandRelationProvider
 * @package AppBundle\Serializer\Hateoas
 */
class BrandRelationProvider
{
    const MEMBERS_FIELD = 'members';

    /**
     * @param Brand $brand
     * @param ClassMetadataInterface $classMetadata
     *
     * @return array
     */
    public function addMembersRelation(Brand $brand, ClassMetadataInterface $classMetadata)
    {
        return;
        if ($brand->getMembers()) {

            return array_map(
                function ($brandRegistry) {
                    /** @var UserBrandRegistry $brandRegistry */
                    return new Hateoas\Relation(
                        static::MEMBERS_FIELD,
                        new Hateoas\Route(
                            'get_user_by_id',
                            ['id' => $brandRegistry->getMember()->getId()]
                        )
                    );
                },
                $brand->getMembers()->toArray()
            );
        }
    }
}