Overview

Namespaces

  • MvcCore
    • Ext
      • Auth
        • Virtual
      • Debug
        • Tracy
      • Form
        • Core
        • Validators
      • Request
      • Router
        • Lang
      • View
        • Helpers
  • None

Classes

  • MvcCore
  • MvcCore\Config
  • MvcCore\Controller
  • MvcCore\Debug
  • MvcCore\Ext\Auth
  • MvcCore\Ext\Auth\Controller
  • MvcCore\Ext\Auth\SignInForm
  • MvcCore\Ext\Auth\SignOutForm
  • MvcCore\Ext\Auth\User
  • MvcCore\Ext\Auth\Virtual\Controller
  • MvcCore\Ext\Auth\Virtual\Form
  • MvcCore\Ext\Auth\Virtual\User
  • MvcCore\Ext\Debug\Tracy
  • MvcCore\Ext\Debug\Tracy\AuthPanel
  • MvcCore\Ext\Debug\Tracy\IncludePanel
  • MvcCore\Ext\Debug\Tracy\MvcCorePanel
  • MvcCore\Ext\Debug\Tracy\RoutingPanel
  • MvcCore\Ext\Debug\Tracy\SessionPanel
  • MvcCore\Ext\Form
  • MvcCore\Ext\Form\Button
  • MvcCore\Ext\Form\Checkbox
  • MvcCore\Ext\Form\CheckboxGroup
  • MvcCore\Ext\Form\Core\Base
  • MvcCore\Ext\Form\Core\Configuration
  • MvcCore\Ext\Form\Core\Field
  • MvcCore\Ext\Form\Core\FieldGroup
  • MvcCore\Ext\Form\Core\Helpers
  • MvcCore\Ext\Form\Core\Validator
  • MvcCore\Ext\Form\Core\View
  • MvcCore\Ext\Form\CountrySelect
  • MvcCore\Ext\Form\Date
  • MvcCore\Ext\Form\DateTime
  • MvcCore\Ext\Form\Email
  • MvcCore\Ext\Form\Hidden
  • MvcCore\Ext\Form\NoType
  • MvcCore\Ext\Form\Number
  • MvcCore\Ext\Form\Password
  • MvcCore\Ext\Form\RadioGroup
  • MvcCore\Ext\Form\Range
  • MvcCore\Ext\Form\ResetButton
  • MvcCore\Ext\Form\ResetInput
  • MvcCore\Ext\Form\Select
  • MvcCore\Ext\Form\SubmitButton
  • MvcCore\Ext\Form\SubmitInput
  • MvcCore\Ext\Form\Text
  • MvcCore\Ext\Form\Textarea
  • MvcCore\Ext\Form\Time
  • MvcCore\Ext\Form\Validators\CompanyId
  • MvcCore\Ext\Form\Validators\CompanyVatId
  • MvcCore\Ext\Form\Validators\Date
  • MvcCore\Ext\Form\Validators\Email
  • MvcCore\Ext\Form\Validators\FloatVal
  • MvcCore\Ext\Form\Validators\Integer
  • MvcCore\Ext\Form\Validators\Maxlength
  • MvcCore\Ext\Form\Validators\MaxSelectedOptions
  • MvcCore\Ext\Form\Validators\MinSelectedOptions
  • MvcCore\Ext\Form\Validators\NumberField
  • MvcCore\Ext\Form\Validators\Pattern
  • MvcCore\Ext\Form\Validators\Phone
  • MvcCore\Ext\Form\Validators\RangeField
  • MvcCore\Ext\Form\Validators\SafeString
  • MvcCore\Ext\Form\Validators\Time
  • MvcCore\Ext\Form\Validators\Url
  • MvcCore\Ext\Form\Validators\ValueInOptions
  • MvcCore\Ext\Form\Validators\ZipCode
  • MvcCore\Ext\Request\ApacheDpi
  • MvcCore\Ext\Request\Cli
  • MvcCore\Ext\Router\Lang
  • MvcCore\Ext\Router\Lang\Route
  • MvcCore\Ext\Router\Media
  • MvcCore\Ext\Router\MediaSiteKey
  • MvcCore\Ext\View\Helpers\Assets
  • MvcCore\Ext\View\Helpers\Css
  • MvcCore\Ext\View\Helpers\Js
  • MvcCore\Ext\View\Helpers\LineBreaks
  • MvcCore\Model
  • MvcCore\Request
  • MvcCore\Response
  • MvcCore\Route
  • MvcCore\Router
  • MvcCore\Session
  • MvcCore\Tool
  • MvcCore\View

Exceptions

  • MvcCore\Ext\Form\Core\Exception
  • Overview
  • Namespace
  • Class
  • Tree
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 
<?php

/**
 * MvcCore
 *
 * This source file is subject to the BSD 3 License
 * For the full copyright and license information, please view
 * the LICENSE.md file that are distributed with this source code.
 *
 * @copyright   Copyright (c) 2016 Tom FlĂ­dr (https://github.com/mvccore/mvccore)
 * @license     https://mvccore.github.io/docs/mvccore/4.0.0/LICENCE.md
 */

namespace MvcCore\Ext\View\Helpers;

class Js extends Assets
{   
    /**
     * Whatever Expires header is send over http protocol, 
     * minimal cache time for external files will be one 
     * day from last download
     * @const integer
     */
    const EXTERNAL_MIN_CACHE_TIME = 86400;

    /**
     * Array with full class name and public method accepted as first param javascript code and returning minified code
     * @var callable
     */
    public static $MinifyCallable = array('\JSMin', 'minify');

    /**
     * Array with all defined files to create specific script tags
     * @var array 
     */
    protected static $scriptsGroupContainer = array();

    /**
     * View Helper Method, returns current object instance.
     * @param  string $groupName string identifier
     * @return \MvcCore\Ext\View\Helpers\Js
     */
    public function Js ($groupName = self::GROUP_NAME_DEFAULT) {
        $this->actualGroupName = $groupName;
        $this->_getScriptsGroupContainer($groupName);
        return $this;
    }

    /**
     * Check if script is already presented in scripts group
     * @param  string  $path
     * @param  boolean $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @return bool
     */
    public function Contains ($path = '', $async = FALSE, $defer = FALSE, $doNotMinify = FALSE) {
        $result = FALSE;
        $scriptsGroup = & $this->_getScriptsGroupContainer($this->actualGroupName);
        foreach ($scriptsGroup as & $item) {
            if ($item->path == $path) {
                if ($item->async == $async && $item->defer == $defer && $item->doNotMinify == $doNotMinify) {
                    $result = TRUE;
                    break;
                }
            }
        }
        return $result;
    }

    /**
     * Append script after all group scripts for later render process with downloading external content
     * @param  string  $path
     * @param  boolean $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @return \MvcCore\Ext\View\Helpers\Js
     */
    public function AppendExternal ($path = '', $async = FALSE, $defer = FALSE, $doNotMinify = FALSE) {
        return $this->Append($path, $async, $defer, $doNotMinify, TRUE);
    }

    /**
     * Prepend script before all group scripts for later render process with downloading external content
     * @param  string  $path
     * @param  boolean $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @return \MvcCore\Ext\View\Helpers\Js
     */
    public function PrependExternal ($path = '', $async = FALSE, $defer = FALSE, $doNotMinify = FALSE) {
        return $this->Prepend($path, $async, $defer, $doNotMinify, TRUE);
    }
    
    /**
     * Add script into given index of scripts group array for later render process with downloading external content
     * @param  integer $index
     * @param  string  $path
     * @param  boolean $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @return \MvcCore\Ext\View\Helpers\Js
     */
    public function OffsetExternal ($index = 0, $path = '', $async = FALSE, $defer = FALSE, $doNotMinify = FALSE) {
        return $this->Offset($index, $path, $async, $defer, $doNotMinify, TRUE);
    }

    /**
     * Append script after all group scripts for later render process
     * @param  string  $path
     * @param  boolean $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @param  boolean $external
     * @return \MvcCore\Ext\View\Helpers\Js
     */
    public function Append ($path = '', $async = FALSE, $defer = FALSE, $doNotMinify = FALSE, $external = FALSE) {
        $item = $this->_completeItem($path, $async, $defer, $doNotMinify, $external);
        $actialGroupItems = & $this->_getScriptsGroupContainer($this->actualGroupName);
        array_push($actialGroupItems, $item);
        return $this;
    }

    /**
     * Prepend script before all group scripts for later render process
     * @param  string  $path
     * @param  boolean $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @param  boolean $external
     * @return \MvcCore\Ext\View\Helpers\Js
     */
    public function Prepend ($path = '', $async = FALSE, $defer = FALSE, $doNotMinify = FALSE, $external = FALSE) {
        $item = $this->_completeItem($path, $async, $defer, $doNotMinify, $external);
        $actualGroupItems = & $this->_getScriptsGroupContainer($this->actualGroupName);
        array_unshift($actualGroupItems, $item);
        return $this;
    }

    /**
     * Add script into given index of scripts group array for later render process
     * @param  integer $index
     * @param  string  $path
     * @param  boolean $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @param  boolean $external
     * @return \MvcCore\Ext\View\Helpers\Js
     */
    public function Offset ($index = 0, $path = '', $async = FALSE, $defer = FALSE, $doNotMinify = FALSE, $external = FALSE) {
        $item = $this->_completeItem($path, $async, $defer, $doNotMinify, $external);
        $actialGroupItems = & $this->_getScriptsGroupContainer($this->actualGroupName);
        $newItems = array();
        $added = FALSE;
        foreach ($actialGroupItems as $key => & $groupItem) {
            if ($key == $index) {
                $newItems[] = $item;
                $added = TRUE;
            }
            $newItems[] = $groupItem;
        }
        if (!$added) $newItems[] = $item;
        self::$scriptsGroupContainer[$this->getCtrlActionKey()][$this->actualGroupName] = $newItems;
        return $this;
    }

    /**
     * Get actualy dispatched controller/action group name
     * @param string $name
     * @return array
     */
    private function & _getScriptsGroupContainer ($name = '') {
        $ctrlActionKey = $this->getCtrlActionKey();
        if (!isset(self::$scriptsGroupContainer[$ctrlActionKey])) {
            self::$scriptsGroupContainer[$ctrlActionKey] = array();
        }
        if (!isset(self::$scriptsGroupContainer[$ctrlActionKey][$name])) {
            self::$scriptsGroupContainer[$ctrlActionKey][$name] = array();
        }
        return self::$scriptsGroupContainer[$ctrlActionKey][$name];
    }
    
    /**
     * Create data item to store for render process
     * @param  string  $path
     * @param  string  $async
     * @param  boolean $defer
     * @param  boolean $doNotMinify
     * @param  boolean $external
     * @return \stdClass
     */
    private function _completeItem ($path, $async, $defer, $doNotMinify, $external) {
        if (self::$logingAndExceptions) {
            if (!$path) $this->exception('Path to *.js can\'t be an empty string.');
            $duplication = $this->_isDuplicateScript($path);
            if ($duplication) $this->warning("Script '$path' is already added in js group: '$duplication'.");
        }
        return (object) array(
            'path'          => $path,
            'async'         => $async,
            'defer'         => $defer,
            'doNotMinify'   => $doNotMinify,
            'external'      => $external,
        );
    }

    /**
     * Is the linked script duplicate?
     * @param  string $path
     * @return string
     */
    private function _isDuplicateScript ($path) {
        $result = '';
        $allGroupItems = & self::$scriptsGroupContainer[$this->getCtrlActionKey()];
        foreach ($allGroupItems as $groupName => $groupItems) {
            foreach ($groupItems as $item) {
                if ($item->path == $path) {
                    $result = $groupName;
                    break;
                }
            }
        }
        return $result;
    }
    
    /**
     * Render script elements as html code with links to original files or temporary downloaded files
     * @param  int $indent
     * @return string
     */
    public function Render ($indent = 0) {
        $actualGroupItems = & $this->_getScriptsGroupContainer($this->actualGroupName);
        if (count($actualGroupItems) === 0) return '';
        $minify = (bool)self::$globalOptions['jsMinify'];
        $joinTogether = (bool)self::$globalOptions['jsJoin'];
        if ($joinTogether) {
            $result = $this->_renderItemsTogether(
                $this->actualGroupName,
                $actualGroupItems, 
                $indent, 
                $minify
            );
        } else {
            $result = $this->_renderItemsSeparated(
                $this->actualGroupName,
                $actualGroupItems, 
                $indent, 
                $minify
            );
        }
        return $result;
    }
    
    /**
     * Render data items as separated <script> html tags
     * @param string  $actualGroupName 
     * @param array   $items 
     * @param int     $indent 
     * @param boolean $minify 
     * @return string
     */
    private function _renderItemsSeparated ($actualGroupName = '', $items = array(), $indent = 0, $minify = FALSE) {
        $indentStr = $this->getIndentString($indent);
        $resultItems = array();
        if (self::$fileRendering) $resultItems[] = '<!-- js group begin: ' . $actualGroupName . ' -->';
        $appCompilation = \MvcCore::GetInstance()->GetCompiled();
        foreach ($items as $item) {
            if ($item->external) {
                $item->src = $this->CssJsFileUrl($this->_downloadFileToTmpAndGetNewHref($item, $minify));
            } else if ($minify && !$item->doNotMinify) {
                $item->src = $this->CssJsFileUrl($this->_renderFileToTmpAndGetNewHref($item, $minify));
            } else {
                $item->src = $this->CssJsFileUrl($item->path);
            }
            if (!$appCompilation) {
                /*if ($item->external) {
                    $tmpOrSrcPath = substr($item->src, strlen(self::$basePath));
                } else {
                    $tmpOrSrcPath = $item->src;
                }*/
                $item->src = $this->addFileModificationImprintToHrefUrl($item->src, $item->path);
            }
            $resultItems[] = $this->_renderItemSeparated($item);
        }
        if (self::$fileRendering) $resultItems[] = '<!-- js group end: ' . $actualGroupName . ' -->';
        return $indentStr . implode(PHP_EOL . $indentStr, $resultItems);
    }
    
    /**
     * Render js file by path and store result in tmp directory and return new href value
     * @param \stdClass $item
     * @param boolean  $minify
     * @return string
     */
    private function _renderFileToTmpAndGetNewHref ($item, $minify = FALSE) {
        $path = $item->path;
        $tmpFileName = '/rendered_js_' . self::$systemConfigHash . '_' . trim(str_replace('/', '_', $path), "_");
        $srcFileFullPath = $this->getAppRoot() . $path;
        $tmpFileFullPath = $this->getTmpDir() . $tmpFileName;
        if (self::$fileRendering) {
            if (file_exists($srcFileFullPath)) {
                $srcFileModDate = filemtime($srcFileFullPath);
            } else {
                $srcFileModDate = 1;
            }
            if (file_exists($tmpFileFullPath)) {
                $tmpFileModDate = filemtime($tmpFileFullPath);
            } else {
                $tmpFileModDate = 0;
            }
            if ($srcFileModDate !== FALSE && $tmpFileModDate !== FALSE) {
                if ($srcFileModDate > $tmpFileModDate) {
                    $fileContent = file_get_contents($srcFileFullPath);
                    if ($minify) {
                        $fileContent = $this->_minify($fileContent, $path);
                    }
                    $this->saveFileContent($tmpFileFullPath, $fileContent);
                    $this->log("Js file rendered ('$tmpFileFullPath').", 'debug');
                }
            }
        }
        $tmpPath = substr($tmpFileFullPath, strlen($this->getAppRoot()));
        return $tmpPath;
    }
    
    /**
     * Download js file by path and store result in tmp directory and return new href value
     * @param \stdClass $item
     * @param boolean  $minify
     * @return string
     */
    private function _downloadFileToTmpAndGetNewHref ($item, $minify = FALSE) {
        $path = $item->path;
        $tmpFileFullPath = $this->getTmpDir() . '/external_js_' . md5($path) . '.js';
        if (self::$fileRendering) {
            if (file_exists($tmpFileFullPath)) {
                $cacheFileTime = filemtime($tmpFileFullPath);
            } else {
                $cacheFileTime = 0;
            }
            if (time() > $cacheFileTime + self::EXTERNAL_MIN_CACHE_TIME) {
                while (TRUE) {
                    $newPath = $this->_getPossiblyRedirectedPath($path);
                    if ($newPath === $path) {
                        break;
                    } else {
                        $path = $newPath;
                    }
                }
                $fr = fopen($path, 'r');
                $fileContent = '';
                $bufferLength = 102400; // 100 KB
                $buffer = '';
                while ($buffer = fread($fr, $bufferLength)) {
                    $fileContent .= $buffer;
                }
                fclose($fr);
                if ($minify) {
                    $fileContent = $this->_minify($fileContent, $path);
                }
                $this->saveFileContent($tmpFileFullPath, $fileContent);
                $this->log("External js file downloaded ('$tmpFileFullPath').", 'debug');
            }
        }
        $tmpPath = substr($tmpFileFullPath, strlen($this->getAppRoot()));
        return $tmpPath;
    }

    /**
     * If there is any redirection in external content path - get redirect path
     * @param string $path 
     * @return string
     */
    private function _getPossiblyRedirectedPath ($path = '') {
        $fp = fopen($path, 'r');
        $metaData = stream_get_meta_data($fp);
        foreach ($metaData['wrapper_data'] as $response) {
            // Were we redirected? */
            if (strtolower(substr($response, 0, 10)) == 'location: ') {
                // update $src with where we were redirected to
                $path = substr($response, 10);
            }
        }
        return $path;
    }
    
    /**
     * Create HTML script element from data item
     * @param  \stdClass $item
     * @return string
     */
    private function _renderItemSeparated (\stdClass $item) {
        $result = '<script type="text/javascript"';
        if ($item->async) $result .= ' async="async"';
        if ($item->async) $result .= ' defer="defer"';
        if (!$item->external && self::$fileChecking) {
            $fullPath = $this->getAppRoot() . $item->path;
            if (!file_exists($fullPath)) {
                $this->log("File not found in CSS view rendering process ('$fullPath').", 'error');
            }
        }
        $result .= ' src="' . $item->src . '"></script>';
        return $result;
    }

    /**
     * Minify javascript string and return minified result
     * @param string $js
     * @param string $path
     * @return string
     */
    private function _minify (& $js, $path) {
        $result = '';
        if (!is_callable(static::$MinifyCallable)) {
            $this->exception(
                "Configured callable object for JS minification doesn't exist. "
                ."Use: https://github.com/mrclay/minify -> /min/lib/JSMin.php"
            );
        }
        try {
            $result = call_user_func(static::$MinifyCallable, $js);
        } catch (\Exception $e) {
            $this->exception("Unable to minify javascript ('$path').");
        }
        return $result;
    }

    /**
     * Render data items as one <script> html tag or all another <script> html tags after with files which is not possible to minify.
     * @param string  $actualGroupName 
     * @param array   $items 
     * @param int     $indent 
     * @param boolean $minify 
     * @return string
     */
    private function _renderItemsTogether ($actualGroupName = '', $items = array(), $indent, $minify = FALSE) {
        
        // some configurations is not possible to render together and minimized
        list($itemsToRenderMinimized, $itemsToRenderSeparately) = $this->filterItemsForNotPossibleMinifiedAndPossibleMinifiedItems($items);
        
        $indentStr = $this->getIndentString($indent);
        $resultItems = array();
        if (self::$fileRendering) $resultItems[] = '<!-- js group begin: ' . $actualGroupName . ' -->';
        
        // process array with groups, which are not possible to minimize
        foreach ($itemsToRenderSeparately as & $itemsToRender) {
            $resultItems[] = $this->_renderItemsTogetherAsGroup($itemsToRender, FALSE);
        }
        
        // process array with groups to minimize
        foreach ($itemsToRenderMinimized as & $itemsToRender) {
            $resultItems[] = $this->_renderItemsTogetherAsGroup($itemsToRender, $minify);
        }

        if (self::$fileRendering) $resultItems[] = $indentStr . '<!-- js group end: ' . $actualGroupName . ' -->';
        
        return $indentStr . implode(PHP_EOL, $resultItems);
    }

    /**
     * Render all items in group together, when application is compiled, do not check source files and changes.
     * @param array   $itemsToRender 
     * @param boolean $minify 
     * @return string
     */
    private function _renderItemsTogetherAsGroup ($itemsToRender = array(), $minify = FALSE) {
        
        // complete tmp filename by source filenames and source files modification times
        $filesGroupInfo = array();
        foreach ($itemsToRender as $item) {
            if ($item->external) {
                $srcFileFullPath = $this->_downloadFileToTmpAndGetNewHref($item, $minify);
                $filesGroupInfo[] = $item->path . '?_' . self::getFileImprint($this->getAppRoot() . $srcFileFullPath);
            } else {
                if (self::$fileChecking) {
                    $fullPath = $this->getAppRoot() . $item->path;
                    if (!file_exists($fullPath)) {
                        $this->exception("File not found in JS view rendering process ('$fullPath').");
                    }
                    $filesGroupInfo[] = $item->path . '?_' . self::getFileImprint($fullPath);
                } else {
                    $filesGroupInfo[] = $item->path;
                }
            }
        }
        $tmpFileFullPath = $this->getTmpFileFullPathByPartFilesInfo($filesGroupInfo, $minify, 'js');
        
        // check, if the rendered, together completed and minimized file is in tmp cache already
        if (self::$fileRendering) {
            if (!file_exists($tmpFileFullPath)) {
                // load all items and join them together
                $resultContent = '';
                foreach ($itemsToRender as & $item) {
                    $srcFileFullPath = $this->getAppRoot() . $item->path;
                    if ($item->external) {
                        $srcFileFullPath = $this->_downloadFileToTmpAndGetNewHref($item, $minify);
                        $fileContent = file_get_contents($this->getAppRoot() . $srcFileFullPath);
                    } else if ($minify) {
                        $fileContent = file_get_contents($srcFileFullPath);
                        if ($minify) $fileContent = $this->_minify($fileContent, $item->path);
                    } else {
                        $fileContent = file_get_contents($srcFileFullPath);
                    }
                    $resultContent .= PHP_EOL . "/* " . $item->path . " */" . PHP_EOL . $fileContent . PHP_EOL;
                }
                // save completed tmp file
                $this->saveFileContent($tmpFileFullPath, $resultContent);
                $this->log("Js files group rendered ('$tmpFileFullPath').", 'debug');
            }
        }

        // complete <link> tag with tmp file path in $tmpFileFullPath variable
        $firstItem = array_merge((array) $itemsToRender[0], array());
        $pathToTmp = substr($tmpFileFullPath, strlen($this->getAppRoot()));
        $firstItem['src'] = $this->CssJsFileUrl($pathToTmp);
        
        return $this->_renderItemSeparated((object) $firstItem);
    }
}
MvcCore API documentation generated by ApiGen