Вход Регистрация
Файл: cobisja/BootHelp/src/Nav.php
Строк: 122
<?php

/**
 * BootHelp - PHP Helpers for Bootstrap
 *
 * (The MIT License)
 *
 * Copyright (c) 2015 Jorge Cobis <jcobis@gmail.com / http://twitter.com/cobisja>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

namespace cobisjaBootHelp;

use 
cobisjaBootHelpBase;
use 
cobisjaBootHelpHelpersContentTag;

/**
 * Generates an HTML block tag that follows the Bootstrap documentation
 * on how to display <strong>Nav</strong> component.
 *
 * See {@link http://getbootstrap.com/components/#nav} for more information.
 */
class Nav extends Base
{
    
/**
     * Initializes a Nav instance.
     *
     * @param array $options options the display options for the nav.
     * @param mixed $block Block to generate a customized inside nav content.
     */
    
public function __construct($options = [], $block null)
    {
        
$num_args $this->getFunctionNumArgs(func_get_args());

        if (
$num_args && is_callable(func_get_arg($num_args-1))) {
            
$block func_get_arg($num_args-1);
            
$options = [];
        }

        
Base::setNavLink(true);
        
$nav = new ContentTag('ul'$this->parseNavOptions($options), $block);
        
Base::setNavLink(false);

        
$this->setHtmlObject($nav->getHtmlObject());
    }

    
/**
     * Process the Nav's options.
     *
     * @param array $options Nav's options.
     * 
     * @return array Nav's options processed.
     */
    
private function parseNavOptions($options = [])
    {
        
$this->appendClass($options'nav');

        if (
Base::getNavbarId()) {
            
$this->appendClass($options'navbar-nav');
        } else {
            if (isset(
$options['as'])) {
                
$as 'single' === $options['as'] ? '' 'nav-' $options['as'];
                unset(
$options['as']);
            } else {
                
$as 'nav-tabs';
            }

            
$this->appendClass($options$as);

            if (isset(
$options['layout'])) {
                
$this->appendClass($options"nav-{$options['layout']}");
                unset(
$options['layout']);
            }
        }

        return 
$options;
    }
}
Онлайн: 1
Реклама