1: <?php
2: /**
3: * A Horde_Injector:: based Horde_Core_Ajax_Imple:: factory.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Core
9: * @author Michael Slusarz <slusarz@horde.org>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Core
12: */
13:
14: /**
15: * A Horde_Injector:: based Horde_Core_Ajax_Imple:: factory.
16: *
17: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Core
24: * @author Michael Slusarz <slusarz@horde.org>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Core
27: */
28: class Horde_Core_Factory_Imple extends Horde_Core_Factory_Base
29: {
30: /**
31: * Attempts to return a concrete Imple instance.
32: *
33: * @param mixed $driver The type of concrete subclass to return. If
34: * $driver is an array, then look in
35: * $driver[0]/lib/Ajax/Imple for the subclass
36: * implementation named $driver[1].php.
37: * @param array $params A hash containing any additional configuration or
38: * parameters a subclass might need.
39: * @param boolean $noattach Don't attach on creation.
40: *
41: * @return Horde_Core_Ajax_Imple The newly created instance.
42: * @throws Horde_Exception
43: */
44: public function create($driver, array $params = array(),
45: $noattach = false)
46: {
47: if (is_array($driver)) {
48: list($app, $driv_name) = $driver;
49: $driver = ucfirst(basename($driv_name));
50: $class = ucfirst($app) . '_Ajax_Imple_' . $driver;
51: } else {
52: $driver = basename($driver);
53: $class = 'Horde_Core_Ajax_Imple_' . $driver;
54: }
55:
56: if (class_exists($class)) {
57: $ob = new $class($params);
58: if (!$noattach) {
59: $ob->attach();
60: }
61: return $ob;
62: }
63:
64: throw new Horde_Exception('Imple driver ' . $driver . ' not found.');
65: }
66:
67: }
68: