1<?php
2/**
3 * Copyright 2003-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
7 *
8 * @author   Michael Slusarz <slusarz@horde.org>
9 * @category Horde
10 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
11 * @package  Compress
12 */
13
14/**
15 * This class provides an API for various compression techniques that can be
16 * used by Horde applications.
17 *
18 * @author    Michael Slusarz <slusarz@horde.org>
19 * @category  Horde
20 * @copyright 2003-2017 Horde LLC
21 * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
22 * @package   Compress
23 */
24class Horde_Compress
25{
26    /**
27     * Attempts to return a concrete Horde_Compress_Base instance based on
28     * $driver.
29     *
30     * @param string $driver  Either a driver name, or the full class name to
31     *                        use (class must extend Horde_Compress_Base).
32     * @param array $params   Hash containing any additional configuration
33     *                        or parameters a subclass needs.
34     *
35     * @return Horde_Compress_Base  The newly created concrete instance.
36     * @throws Horde_Compress_Exception
37     */
38    public static function factory($driver, $params = null)
39    {
40        /* Base drivers (in Compress/ directory). */
41        $class = __CLASS__ . '_' . Horde_String::ucfirst($driver);
42        if (@class_exists($class)) {
43            return new $class($params);
44        }
45
46        /* Explicit class name. */
47        if (@class_exists($driver)) {
48            return new $driver($params);
49        }
50
51        throw new Horde_Compress_Exception(__CLASS__ . ': Class definition of ' . $driver . ' not found.');
52    }
53
54}
55