<?php
namespace Engine\Theme\JSLoader;

/**
 * Facade/singleton for the JS loader.
 * By default instantiates LoaderComplex, but can be overridden via setInstance().
 */
class JSLoader
{
    static private $instance = null;

    /**
     * Get the global JS loader instance.
     * @return LoaderAbstract
     */
    static public function getInstance()
    {
        if (self::$instance===null) {
            self::$instance = new LoaderComplex();
        }

        return self::$instance;
    }

    /**
     * Override the global loader instance (useful for testing/custom loaders).
     * @param LoaderAbstract $instance
     * @return LoaderAbstract
     */
    static public function setInstance($instance)
    {
        self::$instance = $instance;

        return self::$instance;
    }
}
