Overview

Packages

  • Agora
  • None

Classes

  • Agora
  • Agora_Api
  • Agora_Driver
  • Agora_Driver_SplitSql
  • Agora_Driver_Sql
  • Agora_Exception
  • Agora_Factory_Driver
  • Agora_Form_Forum
  • Agora_Form_Message
  • Agora_Form_Search
  • Agora_View
  • Horde_Form_Renderer_MessageForm
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Horde_Injector factory to create Agora_Driver instances.
 4:  *
 5:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file COPYING for license information (GPL). If you
 8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 9:  *
10:  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
11:  * @author  Vilius Ĺ umskas <vilius@lnk.lt>
12:  * @package Agora
13:  */
14: class Agora_Factory_Driver
15: {
16:     /**
17:      * Instances.
18:      *
19:      * @var array
20:      */
21:     private $_instances = array();
22: 
23:     /**
24:      * The injector.
25:      *
26:      * @var Horde_Injector
27:      */
28:     private $_injector;
29: 
30:     /**
31:      * Constructor.
32:      *
33:      * @param Horde_Injector $injector  The injector to use.
34:      */
35:     public function __construct(Horde_Injector $injector)
36:     {
37:         $this->_injector = $injector;
38:     }
39: 
40:     /**
41:      * Return the Agora_Driver:: instance.
42:      *
43:      * @param string $scope  Instance scope
44:      * @param int $forum_id  Forum to link to
45:      *
46:      * @return Agora_Driver  The singleton instance.
47:      * @throws Agora_Exception
48:      */
49:     public function create($scope = 'agora', $forum_id = 0)
50:     {
51:         if (!isset($this->_instances[$scope])) {
52:             $driver = $GLOBALS['conf']['threads']['split'] ? 'SplitSql' : 'Sql';
53:             $params = Horde::getDriverConfig('sql');
54: 
55:             $class = 'Agora_Driver_' . $driver;
56:             if (!class_exists($class)) {
57:                 throw new Agora_Exception(sprintf('Unable to load the definition of %s.', $class));
58:             }
59: 
60:             $params = array(
61:                 'db' => $this->_injector->getInstance('Horde_Db_Adapter'),
62:                 'charset' => $params['charset'],
63:             );
64: 
65:             $driver = new $class($scope, $params);
66:             $this->_instances[$scope] = $driver;
67:         }
68: 
69:         if ($forum_id) {
70:             /* Check if there was a valid forum object to get. */
71:             try {
72:                 $forum = $this->_instances[$scope]->getForum($forum_id);
73:             } catch (Horde_Exception $e) {
74:                 throw new Agora_Exception($e->getMessage());
75:             }
76: 
77:             /* Set current forum id and forum data */
78:             $this->_instances[$scope]->_forum = $forum;
79:             $this->_instances[$scope]->_forum_id = (int)$forum_id;
80:         }
81: 
82:         return $this->_instances[$scope];
83:     }
84: }
85: 
API documentation generated by ApiGen