src/Menu/MenuModulesInterpreter.php
protected function normalizeMenuPresence($data)
    {
        if ( ! $data) {
            return false;
        }

        if ($data instanceof MenuPresenceInterface) {

            $data = [ $data ];

        } elseif (is_array($data) && ! Arr::isAssoc($data)) {

            $presences = [];

            foreach ($data as $nestedData) {

                if (is_array($nestedData)) {
                    $nestedData = new MenuPresence($nestedData);
                }

                if ( ! ($nestedData instanceof MenuPresenceInterface)) {
                    throw new UnexpectedValueException(
                        'Menu presence data from array provided by module is not an array or menu presence instance'
                    );
                }

                $presences[] = $nestedData;
            }

            $data = $presences;

        } else {

            $data = [ new MenuPresence($data) ];
        }

        /** @var MenuPresenceInterface[] $data */

        // Now normalized to an array with one or more menu presences.
        // Make sure the children of each menu presence are normalized aswell.
        foreach ($data as $index => $presence) {

            $children = $presence->children();

            if ( ! empty($children)) {
                $data[$index]->setChildren(
                    $this->normalizeMenuPresence($children)
                );
            }
        }

        return $data;
    }
protected function normalizeMenuPresence($data)
    {
        if ( ! $data) {
            return false;
        }

        if ($data instanceof MenuPresenceInterface) {

            $data = [ $data ];

        } elseif (is_array($data) && ! Arr::isAssoc($data)) {

            $presences = [];

            foreach ($data as $nestedData) {

                if (is_array($nestedData)) {
                    $nestedData = new MenuPresence($nestedData);
                }

                if ( ! ($nestedData instanceof MenuPresenceInterface)) {
                    throw new UnexpectedValueException(
                        'Menu presence data from array provided by module is not an array or menu presence instance'
                    );
                }

                $presences[] = $nestedData;
            }

            $data = $presences;

        } else {

            $data = [ new MenuPresence($data) ];
        }

        /** @var MenuPresenceInterface[] $data */

        // Now normalized to an array with one or more menu presences.
        // Make sure the children of each menu presence are normalized aswell.
        foreach ($data as $index => $presence) {

            $children = $presence->children();

            if ( ! empty($children)) {
                $data[$index]->setChildren(
                    $this->normalizeMenuPresence($children)
                );
            }
        }

        return $data;
    }
protected function normalizeMenuPresence ( $ data ) { if ( ! $ data ) { return false ; } if ( $ data instanceof MenuPresenceInterface ) { $ data = [ $ data ] ; } elseif ( is_array ( $ data ) && ! Arr :: isAssoc ( $ data ) ) { $ presences = [ ] ; foreach ( $ data as $ nestedData ) { if ( is_array ( $ nestedData ) ) { $ nestedData = new MenuPresence ( $ nestedData ) ; } if ( ! ( $ nestedData instanceof MenuPresenceInterface ) ) { throw new UnexpectedValueException ( 'Menu presence data from array provided by module is not an array or menu presence instance' ) ; } $ presences [ ] = $ nestedData ; } $ data = $ presences ; } else { $ data = [ new MenuPresence ( $ data ) ] ; } /** @var MenuPresenceInterface[] $data */ // Now normalized to an array with one or more menu presences. // Make sure the children of each menu presence are normalized aswell. foreach ( $ data as $ index => $ presence ) { $ children = $ presence -> children ( ) ; if ( ! empty ( $ children ) ) { $ data [ $ index ] -> setChildren ( $ this -> normalizeMenuPresence ( $ children ) ) ; } } return $ data ; }
Normalizes menu presence data to an array of MenuPresence instances.

@param $data
@return false|MenuPresenceInterface[]
Normalizes menu presence data to an array of MenuPresence instances .