open-orchestra/open-orchestra-base-api-bundle

View on GitHub
BaseApi/Context/GroupContext.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace OpenOrchestra\BaseApi\Context;

/**
 * Class GroupContext
 *
 * This class is used to store the groups linked to a controller action through the whole request process
 */
class GroupContext
{
    const G_HIDE_ROLES = 'hide_roles';

    protected $groups = array();

    /**
     * @param string $group
     */
    public function addGroup($group)
    {
        if (!$this->hasGroup($group)) {
            $this->groups[] = $group;
        }
    }

    /**
     * @param array $groups
     */
    public function setGroups(array $groups = array())
    {
        $this->groups = $groups;
    }

    /**
     * @param string $group
     *
     * @return bool
     */
    public function hasGroup($group)
    {
        return in_array($group, array_values($this->groups));
    }
}