src/Menu/MenuPermissionsFilter.php
protected function compileIndexForLayoutLayer(array $layout, $parentKeys = [])
    {
        $permissions = [];

        $unconditional = false;
        $mixed         = false;

        foreach ($layout as $key => $value) {

            if ($value->type() === MenuPresenceType::GROUP) {

                $childKeys = $parentKeys;
                array_push($childKeys, $key);

                $childPermissions = $this->compileIndexForLayoutLayer($value->children(), $childKeys);

                // If the children of the group have unconditional presences,
                // this layer becomes unconditionally displayable as well.
                if (false === $childPermissions) {
                    $mixed = true;
                } elseif (count($childPermissions)) {
                    $permissions = array_merge($permissions, $childPermissions);
                }

                continue;
            }

            // For non-group presences, check the permissions directly
            if ( ! count($value->permissions())) {
                $unconditional = true;
                continue;
            }

            $permissions = array_merge($permissions, $value->permissions());
        }

        $this->permissions = array_merge($this->permissions, $permissions);

        // This layer and its descendants have mixed con/unconditional presences when:
        if ($mixed || count($permissions) && $unconditional) {
            return false;
        }

        array_unique($permissions);

        if (count($parentKeys)) {
            $this->permissionsIndex->setForNode($parentKeys, $permissions);
        }

        return $permissions;
    }
protected function compileIndexForLayoutLayer(array $layout, $parentKeys = [])
    {
        $permissions = [];

        $unconditional = false;
        $mixed         = false;

        foreach ($layout as $key => $value) {

            if ($value->type() === MenuPresenceType::GROUP) {

                $childKeys = $parentKeys;
                array_push($childKeys, $key);

                $childPermissions = $this->compileIndexForLayoutLayer($value->children(), $childKeys);

                // If the children of the group have unconditional presences,
                // this layer becomes unconditionally displayable as well.
                if (false === $childPermissions) {
                    $mixed = true;
                } elseif (count($childPermissions)) {
                    $permissions = array_merge($permissions, $childPermissions);
                }

                continue;
            }

            // For non-group presences, check the permissions directly
            if ( ! count($value->permissions())) {
                $unconditional = true;
                continue;
            }

            $permissions = array_merge($permissions, $value->permissions());
        }

        $this->permissions = array_merge($this->permissions, $permissions);

        // This layer and its descendants have mixed con/unconditional presences when:
        if ($mixed || count($permissions) && $unconditional) {
            return false;
        }

        array_unique($permissions);

        if (count($parentKeys)) {
            $this->permissionsIndex->setForNode($parentKeys, $permissions);
        }

        return $permissions;
    }
protected function compileIndexForLayoutLayer ( array $ layout , $ parentKeys = [ ] ) { $ permissions = [ ] ; $ unconditional = false ; $ mixed = false ; foreach ( $ layout as $ key => $ value ) { if ( $ value -> type ( ) === MenuPresenceType :: GROUP ) { $ childKeys = $ parentKeys ; array_push ( $ childKeys , $ key ) ; $ childPermissions = $ this -> compileIndexForLayoutLayer ( $ value -> children ( ) , $ childKeys ) ; // If the children of the group have unconditional presences, // this layer becomes unconditionally displayable as well. if ( false === $ childPermissions ) { $ mixed = true ; } elseif ( count ( $ childPermissions ) ) { $ permissions = array_merge ( $ permissions , $ childPermissions ) ; } continue ; } // For non-group presences, check the permissions directly if ( ! count ( $ value -> permissions ( ) ) ) { $ unconditional = true ; continue ; } $ permissions = array_merge ( $ permissions , $ value -> permissions ( ) ) ; } $ this -> permissions = array_merge ( $ this -> permissions , $ permissions ) ; // This layer and its descendants have mixed con/unconditional presences when: if ( $ mixed || count ( $ permissions ) && $ unconditional ) { return false ; } array_unique ( $ permissions ) ; if ( count ( $ parentKeys ) ) { $ this -> permissionsIndex -> setForNode ( $ parentKeys , $ permissions ) ; } return $ permissions ; }
Compiles data for the index for a nested node of the layout.

Only returns permissions list for nodes for which goes that ALL children
have permissions, or NONE do. Mixed conditional & unconditional must be
parsed no matter what, anyway.

@param MenuPresenceInterface[] $layout
@param array                   $parentKeys
@return string[]|false     permissions, or false if the layer has mixed (un)conditional presences
Compiles data for the index for a nested node of the layout .