1: <?php
2: /**
3: * A Horde_Injector:: based factory for creating Horde_Core_Block_Collection
4: * objects.
5: *
6: * PHP version 5
7: *
8: * @category Horde
9: * @package Core
10: * @author Michael Slusarz <slusarz@horde.org>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Core
13: */
14:
15: /**
16: * A Horde_Injector:: based factory for creating Horde_Core_Block_Collection
17: * objects.
18: *
19: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you
22: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Horde
25: * @package Core
26: * @author Michael Slusarz <slusarz@horde.org>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28: * @link http://pear.horde.org/index.php?package=Core
29: */
30: class Horde_Core_Factory_BlockCollection extends Horde_Core_Factory_Base
31: {
32: /**
33: * Instances.
34: *
35: * @var array
36: */
37: private $_instances = array();
38:
39: /**
40: * Return the Block_Collection instance.
41: *
42: * @param array $apps The applications whose blocks to list.
43: * @param string $layout The preference name for the layout
44: * configuration.
45: *
46: * @return Horde_Core_Block_Collection The singleton instance.
47: * @throws Horde_Exception
48: */
49: public function create(array $apps = array(), $layout = 'portal_layout')
50: {
51: global $registry, $session;
52:
53: if (empty($apps)) {
54: $apps = $registry->listApps();
55: } else {
56: $apps = array_intersect($registry->listApps(), $apps);
57: }
58:
59: sort($apps);
60: $sig = hash('md5', serialize(array($apps, $layout)));
61:
62: if (!isset($this->_instances[$sig])) {
63: if (!($ob = $session->retrieve('horde', 'blocks/' . $sig))) {
64: $ob = new Horde_Core_Block_Collection($apps, $layout);
65: $session->set('horde', 'blocks/' . $sig, $ob);
66:
67: }
68:
69: $this->_instances[$sig] = $ob;
70: }
71:
72: return $this->_instances[$sig];
73: }
74:
75: }
76: