Converts a policies array into an array that can be used for the CMIS request

@param string[] $policies A list of policy string representations
@return array
770595
protected function convertPolicyIdArrayToQueryArray(array $policies)
    {
        $policiesArray = [];
        $policyCounter = 0;

        foreach ($policies as $policy) {
            $policiesArray[Constants::CONTROL_POLICY][$policyCounter] = (string) $policy;
            $policyCounter ++;
        }

        return $policiesArray;
    }
86017
protected function constraintToArray($rule)
    {
        if ($rule instanceof ConstraintGroup) {
            return $this->constraintGroupToArray($rule);
        }

        $operator = $rule->operator();

        // Do some more strict checks if constraints with operators were passed
        if (!$operator) {
            return [$rule->name() => $rule->parameters()];
        }

        if (strtolower($operator) == 'like') {
            return ['like' => $rule->parameters()];
        }

        return [
            'compare' => [
                $operator,
                $rule->parameters()[0],
                true
            ]
        ];
    }
380543
public function toArray($values = true)
    {
        if ($values) {
            $result = array();
            foreach ($this->_data as $state) {
                $result[$state->name] = $state->value;
            }
        } else {
            $result = $this->_data;
        }

        return $result;
    }
800614
protected function parse_array_rules( array $rules ) {
		$parse_rules = [];

		foreach ( $rules as $key => $value ) {
			if ( is_int( $key ) ) {
				$parse_rules[] = [ $this->normalize( $value ), [] ];
				continue;
			}

			$key = $this->normalize( $key );

			if ( ! is_array( $value ) ) {
				$value = [ $value ];
			}

			$parse_rules[] = [ $key, $this->wrap_parameters( $key, $value ) ];
		}

		return $parse_rules;
	}
293325
public function optimize(array $policiesAndSets): array
    {
        assert(empty($policiesAndSets) === false);

        $index              = 0;
        $rawTargets         = [];
        $serializedPolicies = [];
        foreach ($policiesAndSets as $policyOrSet) {
            /** @var PolicyInterface|PolicySetInterface $policyOrSet */
            $rawTargets[$index]         = $policyOrSet->getTarget();
            $serializedPolicies[$index] = $policyOrSet instanceof PolicyInterface ?
                Encoder::encodePolicy($policyOrSet) : Encoder::encodePolicySet($policyOrSet);
            $index++;
        }

        $callable         = static::METHOD;
        $optimizedTargets = $this->optimizeTargets($rawTargets);

        /** @var callable|array $callable */
        assert($callable !== null && is_array($callable) === true &&
            is_callable($callable) === true && count($callable) === 2 &&
            is_string($callable[0]) === true && is_string($callable[1]) === true);

        return [
            static::INDEX_TARGETS           => $optimizedTargets,
            static::INDEX_POLICIES_AND_SETS => $serializedPolicies,
            static::INDEX_CALLABLE          => $callable,
        ];
    }
154407
private static function encodeObligations(array $obligations): array
    {
        $result = [];
        foreach ($obligations as $item) {
            /** @var ObligationInterface $item*/
            $result[$item->getFulfillOn()][] = $item->getCallable();
        }

        return $result;
    }
781384
protected function convertRoles($roles)
    {
        if ($roles instanceof Traversable) {
            $roles = iterator_to_array($roles);
        }

        $collectedRoles = [];
        $toCollect      = [];

        foreach ((array) $roles as $role) {
            // If it's already a RoleInterface, nothing to do as a RoleInterface contains everything already
            if ($role instanceof RoleInterface) {
                $collectedRoles[] = $role;
                continue;
            }

            // Otherwise, it's a string and hence we need to collect it
            $toCollect[] = (string) $role;
        }

        // Nothing to collect, we don't even need to hit the (potentially) costly role provider
        if (empty($toCollect)) {
            return $collectedRoles;
        }

        return array_merge($collectedRoles, $this->roleProvider->getRoles($toCollect));
    }
734699
private static function _gatherChildren(PolicyNode ...$nodes): array
    {
        $children = array();
        foreach ($nodes as $node) {
            $children = array_merge($children, $node->children());
        }
        return $children;
    }
869375
public static function parse($rules)
    {
        if ($rules instanceof RuleContract) {
            return [$rules, []];
        }

        if (is_array($rules)) {
            $rules = static::parseArrayRule($rules);
        } else {
            $rules = static::parseStringRule($rules);
        }

        $rules[0] = static::normalizeRule($rules[0]);

        return $rules;
    }
432851
public function prepareRoleCollection (array $roles)
    {
        $roleCollection = [];
        $roleHelper = new RoleNameHelper();

        foreach ($roles as $role => $configuration)
        {
            try
            {
                // normalize role name
                $roleName = $roleHelper->normalizeRoleName($role);

                // check for duplicate role definitions
                if (array_key_exists($roleName, $roleCollection))
                {
                    $addition = ($roleName !== $role) ? " (normalized from “{$role}”)" : "";
                    throw new DuplicateRoleDefinitionException("The role “{$roleName}”{$addition} has multiple definitions. Keep in mind that all role names are normalized to a common “ROLE_…” format.");
                }

                $roleCollection[$roleName] = $configuration;
            }
            catch (\InvalidArgumentException $e)
            {
                throw new EmptyRoleNameException("Role name could not be normalized: {$e->getMessage()}.", 0, $e);
            }
        }

        return $this->prepareIncludedRoles($roleCollection);
    }
1015297
public static function encodePolicySet(PolicySetInterface $set): array
    {
        $algorithm       = $set->getCombiningAlgorithm();
        $policiesAndSets = $set->getPoliciesAndSets();
        $result          = [
            static::TYPE                   => static::TYPE_POLICY_SET,
            static::POLICY_SET_NAME        => $set->getName(),
            static::POLICY_SET_TARGET      => static::encodeTarget($set->getTarget()),
            static::POLICY_SET_OBLIGATIONS => static::encodeObligations($set->getObligations()),
            static::POLICY_SET_ADVICE      => static::encodeAdvice($set->getAdvice()),
            static::POLICY_SET_CHILDREN    => static::serializePoliciesAndSets($algorithm, $policiesAndSets),
        ];

        return $result;
    }
1260722
protected function flattenRoles(array $roles)
    {
        $roleNames = [];
        $iterator  = $this->traversalStrategy->getRolesIterator($roles);

        foreach ($iterator as $role) {
            $roleNames[] = $role->getName();
        }

        return array_unique($roleNames);
    }
758162
public function loadRoles()
    {
        $data = $this->roleGateway->loadRoles();

        $roles = $this->mapper->mapRoles($data);
        foreach ($roles as $role) {
            foreach ($role->policies as $policy) {
                $this->limitationConverter->toSPI($policy);
            }
        }

        return $roles;
    }
1104489
public function policy( Policy $policy )
	{
		$this->loadedPolicies[] = $policy;

		// Caches the policy nodes as a nestable tree
		foreach ( $policy->getNodes() as $namespace => $callable )
			$this->getPermission( $namespace )->addPolicyMethod( $callable );
	}
1285441
private function getActions(string $policyClass): array
    {
        $reflectionClass = new ReflectionClass($policyClass);

        $actions = [];
        foreach ($reflectionClass->getMethods() as $reflectionMethod) {
            if ($reflectionMethod->isPublic() === true &&
                $reflectionMethod->isStatic() === true &&
                $reflectionMethod->hasReturnType() === true &&
                (string)$reflectionMethod->getReturnType() === 'bool' &&
                $reflectionMethod->getNumberOfParameters() === 1 &&
                $reflectionMethod->getParameters()[0]->getClass()->implementsInterface(ContextInterface::class) === true
            ) {
                $actions[] = $reflectionMethod->getName();
            }
        }

        return $actions;
    }
390376
public function setPolicies(array $policies)
    {
        $this->policies = [];
        
        foreach ($policies as $policy) {
            $this->policies[] = $this->policyFactory($policy);
        }
        
        return $this;
    }
1167329
public static function encodePolicy(PolicyInterface $policy): array
    {
        $result = [
            static::TYPE               => static::TYPE_POLICY,
            static::POLICY_NAME        => $policy->getName(),
            static::POLICY_TARGET      => static::encodeTarget($policy->getTarget()),
            static::POLICY_OBLIGATIONS => static::encodeObligations($policy->getObligations()),
            static::POLICY_ADVICE      => static::encodeAdvice($policy->getAdvice()),
            static::POLICY_RULES       => static::encodeRules($policy->getCombiningAlgorithm(), $policy->getRules()),
        ];

        return $result;
    }