Mini Shell

Direktori : /usr/share/l.v.e-manager/directadmin/lvemanager_spa/app/Base/
Upload File :
Current File : //usr/share/l.v.e-manager/directadmin/lvemanager_spa/app/Base/View.php

<?php
/**
 * Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */


namespace App\Base;

/**
 * Class View
 *
 * @package selector\base
 */
class View {
    /**
     *
     */
    const VIEW_DIRECTORY = 'View';
    /**
     *
     */
    const LAYOUT_DIRECTORY = 'Layout';

    /**
     * @var string
     */
    public $viewDirectory;
    /**
     * @var string
     */
    public $layoutDirectory;
    /**
     * @var string
     */
    public $layout = 'default';
    /**
     * @var
     */
    public $assetManager;

    /**
     * @param string $controller
     */
    public function __construct($controller = '')
    {
        $billing = Base::load()->getBilling();
        $this->viewDirectory = SELECTOR_ROOT_DIR . DS . self::VIEW_DIRECTORY . DS . $billing;
        $this->layoutDirectory = SELECTOR_ROOT_DIR . DS . self::VIEW_DIRECTORY . DS . self::LAYOUT_DIRECTORY;
        $this->assetManager = Base::load()->billingManager->getAssetManager();

        if($controller) {
            $this->viewDirectory .= DS . lcfirst($controller);
        }
    }

    /**
     * Render view file with layout
     *
     * @param string $view
     * @param array $values
     * @param bool $output
     * @return string
     * @throws \Exception
     */
    public function render($view, $values = array(), $output = true)
    {
        $viewPath = $this->viewDirectory . DS . $view . '.php';
        $layoutPath = $this->layoutDirectory . DS . $this->layout . '.php';

        if(!file_exists($viewPath)) {
            throw new Exception('View file not founded: '. $view);
        }

        if(!file_exists($layoutPath)) {
            throw new Exception('Layout file not founded: '. $this->layout);
        }

        ob_start();
        extract($values);
        include $viewPath;
        $content = ob_get_contents();
        ob_end_clean();

        ob_start();
        include_once $layoutPath;
        $content = ob_get_contents();
        $output ? ob_end_flush() : ob_end_clean();

        return $content;
    }

    /**
     * Render view file
     *
     * @param string $view
     * @param array $values
     * @param bool $output
     * @return string
     * @throws \Exception
     */
    public function renderPartial($view, $values = array(), $output = true)
    {
        $viewPath = $this->viewDirectory . DS . $view . '.php';

        if(!file_exists($viewPath)) {
            throw new Exception('View file not founded');
        }

        ob_start();
        extract($values);
        include $viewPath;
        $content = ob_get_contents();
        $output ? ob_end_flush() : ob_end_clean();

        return $content;
    }
} 

Zerion Mini Shell 1.0