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/Assets.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 Assets
 *
 * @package selector\base
 */
abstract class Assets {
    /**
     * Default JavaScript file extension
     */
    const SCRIPT_EXT = 'js';
    /**
     * Default Css files extension
     */
    const STYLE_EXT = 'css';

    /**
     * Default assets directory path
     */
    const ASSET_DIRECTORY = 'Assets';

    /**
     * JavaScript files repository
     *
     * @var array
     */
    protected $_scripts = array();
    /**
     * Style files repository
     *
     * @var array
     */
    protected $_styles = array();

    /**
     * Render JavaScript files on the view page
     *
     * @param bool $output
     * @return mixed string|void
     */
    abstract public function renderScriptFiles($output = true);

    /**
     * Render style files on the view page
     *
     * @param bool $output
     * @return mixed string|void
     */
    abstract public function renderStyleFiles($output = true);

    /**
     *
     */
    public function __construct()
    {
        $this->relativePath = self::ASSET_DIRECTORY;
    }

    /**
     * Add JavaScript files to local repository
     *
     * @param array $fileNames
     */
    public function registerScriptFiles($fileNames = array())
    {
        foreach($fileNames as $row) {
            $this->_scripts[] = $row;
        }
    }

    /**
     * Add style files to local repository
     *
     * @param array $fileNames
     */
    public function registerStyleFiles($fileNames = array())
    {
        foreach($fileNames as $row) {
            $this->_styles[] = $row;
        }
    }

    /**
     * Get JavaScript file content
     *
     * @param $fileName
     * @return string
     */
    public function getScriptFileContent($fileName)
    {
        return $this->getFileContent($fileName, self::SCRIPT_EXT);
    }

    /**
     * Get style file content
     *
     * @param $fileName
     * @return string
     */
    public function getStyleFileContent($fileName)
    {
        return $this->getFileContent($fileName, self::STYLE_EXT);
    }

    /**
     * Get file content by extension
     *
     * @param $fileName
     * @param $fileExtension
     * @param bool $registration   Is registration of files needed ?
     * @return string
     * @throws Exception
     */
    public function getFileContent($fileName, $fileExtension, $registration = true)
    {
        $content = '';
        $filePath = SELECTOR_ROOT_DIR . DS . self::ASSET_DIRECTORY . DS .
            $fileName;

        $filePath .= $fileExtension === 'font' ? '' : '.' . $fileExtension;

        if (file_exists($filePath)) {
            if (!$registration) {
                return file_get_contents($filePath);
            } elseif (in_array($fileName, $this->_styles) || in_array($fileName, $this->_scripts)) {
                return file_get_contents($filePath);
            }
        } else {
            throw new Exception("REQUIRED FILE \"$fileName\" DOES NOT EXIST IN $fileExtension");
        }

        return $content;
    }
}

Zerion Mini Shell 1.0