aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/assets/Storage.php
blob: d4888782d8dc824c0c54c192fa0863a3695be458 (plain)
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
<?php
namespace Assets;

/**
 * General class for assets storage retrieval
 *
 * @author  Jan-Hendrik Willms
 * @license GPL2 or any later version
 * @since   Stud.IP 3.4
 */
class Storage
{
    private static $default_factory = null;

    /**
     * Sets a file factory to use. If no file factory will be set,
     * the default PluginAssetFactory will be used.
     *
     * @param Assets\AssetFactory $factory The factory
     */
    public static function setFactory(AssetFactory $factory = null)
    {
        $old_factory = self::$default_factory;
        self::$default_factory = $factory;
        return $old_factory;
    }

    /**
     * Returns the currently selected asset factory. If no asset
     * factory is set, the default PluginAssetFactory will be returned.
     *
     * @return Assets\AssetFactory instance
     */
    public static function getFactory()
    {
        if (self::$default_factory === null) {
            $factory = new PluginAssetFactory();
            self::setFactory($factory);
        }
        return self::$default_factory;
    }
}