1: <?php
2: /**
3: * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file LICENSE for license information (BSD). If you did not
6: * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
7: *
8: * @author Jason M. Felice <jason.m.felice@gmail.com>
9: * @package Vilma
10: */
11: abstract class Vilma_MailboxDriver
12: {
13: /**
14: * A hash containing any parameters for the current driver.
15: *
16: * @var array
17: */
18: protected $_params = array();
19:
20: /**
21: * Constructor.
22: *
23: * @param array $params Any parameters needed for this driver.
24: */
25: public function __construct(array $params = array())
26: {
27: $this->_params = $params;
28: }
29:
30: public function getParam($param)
31: {
32: return isset($this->_params[$param]) ? $this->_params[$param] : null;
33: }
34:
35: /**
36: * Creates a new mailbox.
37: *
38: * @param string $user The name of the mailbox to create.
39: * @param string $domain The name of the domain in which to create the
40: * mailbox.
41: *
42: * @throws Vilma_Exception
43: */
44: abstract public function createMailbox($user, $domain);
45:
46: /**
47: * Deletes an existing mailbox.
48: *
49: * @param string $user The name of the mailbox to delete.
50: * @param string $domain The name of the domain in which to delete the
51: * mailbox.
52: *
53: * @throws Vilma_Exception
54: */
55: abstract public function deleteMailbox($user, $domain);
56:
57: /**
58: * Checks whether a mailbox exists and is set up properly.
59: *
60: * @param string $user The name of the mailbox to check.
61: * @param string $domain The mailbox' domain.
62: *
63: * @return boolean True if the mailbox exists.
64: * @throws Vilma_Exception if the mailbox doesn't exist.
65: */
66: abstract public function checkMailbox($user, $domain);
67:
68: /**
69: * Creates a new mailbox driver instance.
70: *
71: * @param string $driver The name of the driver to create an instance of.
72: * @param array $params Driver-specific parameters.
73: *
74: * @return Vilma_MailboxDriver The new driver instance.
75: * @throws Vilma_Exception
76: */
77: static public function factory($driver = null, $params = null)
78: {
79: if (is_null($driver)) {
80: $driver = $GLOBALS['conf']['mailboxes']['driver'];
81: }
82: $driver = Horde_String::ucfirst(basename($driver));
83:
84: if (is_null($params)) {
85: $params = $GLOBALS['conf']['mailboxes']['params'];
86: }
87:
88: $class = 'Vilma_MailboxDriver_' . $driver;
89: if (class_exists($class)) {
90: return new $class($params);
91: }
92:
93: throw new Vilma_Exception(sprintf('No such mailbox driver "%s" found', $driver));
94: }
95: }
96: