eZ\Publish\Core\Persistence\Legacy\User\Role\LimitationHandler\ObjectStateHandler::toSPI PHP Method

toSPI() public method

Translate Legacy StateGroup_ limitations to API STATE limitation.
public toSPI ( eZ\Publish\SPI\Persistence\User\Policy $policy )
$policy eZ\Publish\SPI\Persistence\User\Policy
    public function toSPI(Policy $policy)
    {
        if ($policy->limitations === '*' || empty($policy->limitations)) {
            return;
        }
        // First iterate to prepare for the range of possible conditions below
        $hasStateGroup = false;
        $allWildCard = true;
        $someWildCard = false;
        $map = array();
        foreach ($policy->limitations as $identifier => $limitationsValues) {
            if (strncmp($identifier, self::STATE_GROUP, 11) === 0) {
                $hasStateGroup = true;
                if ($limitationsValues !== '*') {
                    $allWildCard = false;
                } else {
                    $someWildCard = true;
                }
                $map[$identifier] = $limitationsValues;
                unset($policy->limitations[$identifier]);
            }
        }
        if (!$hasStateGroup) {
            return;
        }
        if ($allWildCard) {
            $policy->limitations[Limitation::STATE] = '*';
            return;
        }
        if ($someWildCard) {
            $fullMap = $this->getGroupMap();
            foreach ($map as $identifier => $limitationsValues) {
                if ($limitationsValues === '*') {
                    $map[$identifier] = $fullMap[$identifier];
                }
            }
        }
        $policy->limitations[Limitation::STATE] = array();
        foreach ($map as $limitationValues) {
            $policy->limitations[Limitation::STATE] = array_merge($policy->limitations[Limitation::STATE], $limitationValues);
        }
    }