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