View sourcecode

The following files exists in this folder. Click to view.

phpdoc-cache-file_e2ba016d7174abc516119080482812d7.dat

1 lines ASCII Unix (LF)
1
O:39:"phpDocumentor\Descriptor\FileDescriptor":22:{s:7:"*hash";s:32:"f27c067a110f9b78ac4999fec8e09449";s:7:"*path";s:22:"Navigation/CNavbar.php";s:9:"*source";s:3498:"<?php

namespace Anax\Navigation;

/**
 * Helper to create a navbar for sites by reading its configuration from file
 * and then applying some code while rendering the resultning navbar.
 *
 */
class CNavbar
{
    use \Anax\TConfigure,
        \Anax\DI\TInjectionAware;



    /**
     * Create a navigation bar / menu, with submenu.
     * 
     * @return string with html for the menu.
     *
     * @link http://dbwebb.se/coachen/skapa-en-dynamisk-navbar-meny-med-undermeny-via-php
     */
    public function create()
    {
        // Keep default options in an array and merge with incoming options that can override the defaults.
        $default = array(
          'id'          => null,
          'class'       => null,
          'wrapper'     => 'nav',
          'create_url'  => function ($url) {
            return $url;
          },
        );
        $menu = array_replace_recursive($default, $this->config);

        // Function to create urls
        $createUrl = $menu['create_url'];

        // Create the ul li menu from the array, use an anonomous recursive function that returns an array of values.
        $createMenu = function ($items, $callback) use (&$createMenu, $createUrl) {
            
            $html = null;
            $hasItemIsSelected = false;

            foreach ($items as $item) {

                // has submenu, call recursivly and keep track on if the submenu has a selected item in it.
                $submenu        = null;
                $selectedParent = null;
            
                if (isset($item['submenu'])) {
                    list($submenu, $selectedParent) = $createMenu($item['submenu']['items'], $callback);
                    $selectedParent = $selectedParent
                        ? "selected-parent "
                        : null;
                }

                // Check if the current menuitem is selected
                $selected = $callback($item['url'])
                    ? "selected "
                    : null;
                
                // Is there a class set for this item, then use it
                $class = isset($item['class']) && ! is_null($item['class'])
                    ? $item['class']
                    : null;

                // Prepare the class-attribute, if used
                $class = ($selected || $selectedParent || $class)
                    ? " class='{$selected}{$selectedParent}{$class}' "
                    : null;

                // Add the menu item
                $url = $createUrl($item['url']);
                $html .= "\n<li{$class}><a href='{$url}' title='{$item['title']}'>{$item['text']}</a>{$submenu}</li>\n";
                
                // To remember there is selected children when going up the menu hierarchy
                if ($selected) {
                    $hasItemIsSelected = true;
                }
            }

            // Return the menu
            return array("\n<ul>$html</ul>\n", $hasItemIsSelected);
        };

        // Call the anonomous function to create the menu, and submenues if any.
        list($html, $ignore) = $createMenu($menu['items'], $menu['callback']);


        // Set the id & class element, only if it exists in the menu-array
        $id      = isset($menu['id'])    ? " id='{$menu['id']}'"       : null;
        $class   = isset($menu['class']) ? " class='{$menu['class']}'" : null;
        $wrapper = $menu['wrapper'];

        return "\n<{$wrapper}{$id}{$class}>{$html}</{$wrapper}>\n";
    }
}
";s:19:"*namespaceAliases";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:11:"*includes";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:12:"*constants";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:12:"*functions";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:10:"*classes";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:1:{s:24:"\Anax\Navigation\CNavbar";O:40:"phpDocumentor\Descriptor\ClassDescriptor":19:{s:9:"*parent";s:0:"";s:13:"*implements";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:11:"*abstract";b:0;s:8:"*final";b:0;s:12:"*constants";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:13:"*properties";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:10:"*methods";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:1:{s:6:"create";O:41:"phpDocumentor\Descriptor\MethodDescriptor":17:{s:9:"*parent";r:15;s:11:"*abstract";b:0;s:8:"*final";b:0;s:9:"*static";b:0;s:13:"*visibility";s:6:"public";s:12:"*arguments";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:8:"*fqsen";s:34:"\Anax\Navigation\CNavbar::create()";s:7:"*name";s:6:"create";s:12:"*namespace";N;s:10:"*package";s:0:"";s:10:"*summary";s:45:"Create a navigation bar / menu, with submenu.";s:14:"*description";s:0:"";s:17:"*fileDescriptor";N;s:7:"*line";i:24;s:7:"*tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:3:{s:6:"return";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:1:{i:0;O:45:"phpDocumentor\Descriptor\Tag\ReturnDescriptor":4:{s:8:"*types";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:1:{i:0;O:46:"phpDocumentor\Descriptor\Type\StringDescriptor":0:{}}}s:7:"*name";s:6:"return";s:14:"*description";s:23:"with html for the menu.";s:9:"*errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}}}}s:4:"link";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:1:{i:0;O:43:"phpDocumentor\Descriptor\Tag\LinkDescriptor":4:{s:7:"*link";s:76:"http://dbwebb.se/coachen/skapa-en-dynamisk-navbar-meny-med-undermeny-via-php";s:7:"*name";s:4:"link";s:14:"*description";s:76:"http://dbwebb.se/coachen/skapa-en-dynamisk-navbar-meny-med-undermeny-via-php";s:9:"*errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}}}}s:5:"param";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}}}s:9:"*errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:19:"*inheritedElement";N;}}}s:13:"*usedTraits";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:2:{i:0;s:16:"\Anax\TConfigure";i:1;s:24:"\Anax\DI\TInjectionAware";}}s:8:"*fqsen";s:24:"\Anax\Navigation\CNavbar";s:7:"*name";s:7:"CNavbar";s:12:"*namespace";s:16:"\Anax\Navigation";s:10:"*package";s:0:"";s:10:"*summary";s:141:"Helper to create a navbar for sites by reading its configuration from file
and then applying some code while rendering the resultning navbar.";s:14:"*description";s:0:"";s:17:"*fileDescriptor";r:1;s:7:"*line";i:10;s:7:"*tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:2:{s:7:"package";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:1:{i:0;O:38:"phpDocumentor\Descriptor\TagDescriptor":3:{s:7:"*name";s:7:"package";s:14:"*description";s:7:"Default";s:9:"*errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}}}}s:10:"subpackage";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}}}s:9:"*errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:19:"*inheritedElement";N;}}}s:13:"*interfaces";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:9:"*traits";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}s:10:"*markers";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:13:{i:0;a:3:{s:4:"type";s:0:"";s:7:"message";s:69:"dbwebb.se/coachen/skapa-en-dynamisk-navbar-meny-med-undermeny-via-php";s:4:"line";i:22;}i:1;a:3:{s:4:"type";s:0:"";s:7:"message";s:96:"Keep default options in an array and merge with incoming options that can override the defaults.";s:4:"line";i:26;}i:2;a:3:{s:4:"type";s:0:"";s:7:"message";s:23:"Function to create urls";s:4:"line";i:37;}i:3;a:3:{s:4:"type";s:0:"";s:7:"message";s:106:"Create the ul li menu from the array, use an anonomous recursive function that returns an array of values.";s:4:"line";i:40;}i:4;a:3:{s:4:"type";s:0:"";s:7:"message";s:88:"has submenu, call recursivly and keep track on if the submenu has a selected item in it.";s:4:"line";i:48;}i:5;a:3:{s:4:"type";s:0:"";s:7:"message";s:41:"Check if the current menuitem is selected";s:4:"line";i:59;}i:6;a:3:{s:4:"type";s:0:"";s:7:"message";s:47:"Is there a class set for this item, then use it";s:4:"line";i:64;}i:7;a:3:{s:4:"type";s:0:"";s:7:"message";s:36:"Prepare the class-attribute, if used";s:4:"line";i:69;}i:8;a:3:{s:4:"type";s:0:"";s:7:"message";s:17:"Add the menu item";s:4:"line";i:74;}i:9;a:3:{s:4:"type";s:0:"";s:7:"message";s:71:"To remember there is selected children when going up the menu hierarchy";s:4:"line";i:78;}i:10;a:3:{s:4:"type";s:0:"";s:7:"message";s:15:"Return the menu";s:4:"line";i:84;}i:11;a:3:{s:4:"type";s:0:"";s:7:"message";s:69:"Call the anonomous function to create the menu, and submenues if any.";s:4:"line";i:88;}i:12;a:3:{s:4:"type";s:0:"";s:7:"message";s:63:"Set the id & class element, only if it exists in the menu-array";s:4:"line";i:92;}}}s:8:"*fqsen";s:0:"";s:7:"*name";s:11:"CNavbar.php";s:12:"*namespace";N;s:10:"*package";s:7:"Default";s:10:"*summary";s:0:"";s:14:"*description";s:0:"";s:17:"*fileDescriptor";N;s:7:"*line";i:0;s:7:"*tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:2:{s:7:"package";r:82;s:10:"subpackage";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:0:{}}}}s:9:"*errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:"*items";a:1:{i:0;O:40:"phpDocumentor\Descriptor\Validator\Error":4:{s:11:"*severity";s:5:"error";s:7:"*code";s:13:"PPC:ERR-50000";s:7:"*line";i:0;s:10:"*context";a:2:{s:11:"{{ value }}";s:2:"""";i:0;s:0:"";}}}}s:19:"*inheritedElement";N;}