1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * The Factory frontend class. |
---|
5 | * This class controls which concrete Factory |
---|
6 | * will be used, depending on the current |
---|
7 | * 'security mode'. It lazy instantiates both |
---|
8 | * factories (process and module) when they are |
---|
9 | * required, and stores these objects. All the |
---|
10 | * accesses to factories are done through this class, |
---|
11 | * implementing a kind of Proxy design pattern. |
---|
12 | * This class depends on Security frontend class |
---|
13 | * to decide which factory to call. |
---|
14 | * |
---|
15 | * @author Pedro Eugênio Rocha |
---|
16 | * @package Factory |
---|
17 | * @static |
---|
18 | */ |
---|
19 | class Factory { |
---|
20 | |
---|
21 | |
---|
22 | /** |
---|
23 | * @var object $_unsecuredFactory Stores WorkflowFactory object. |
---|
24 | * @access private |
---|
25 | * @static |
---|
26 | */ |
---|
27 | private static $_unsecuredFactory = null; |
---|
28 | |
---|
29 | |
---|
30 | /** |
---|
31 | * @var object $_securedFactory Stores ProcessFactory object. |
---|
32 | * @access private |
---|
33 | * @static |
---|
34 | */ |
---|
35 | private static $_securedFactory = null; |
---|
36 | |
---|
37 | |
---|
38 | /** |
---|
39 | * Constructor. Just disable direct instantiation. |
---|
40 | * |
---|
41 | * @access public |
---|
42 | * @return void |
---|
43 | * @static |
---|
44 | */ |
---|
45 | public function __construct() { |
---|
46 | throw new Exception("Oops! Static only class."); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | * Just forward this call to the correct class. |
---|
52 | * |
---|
53 | * @access public |
---|
54 | * @retun object |
---|
55 | * @static |
---|
56 | */ |
---|
57 | public static function getInstance() { |
---|
58 | |
---|
59 | /* oops. we are in the process space. */ |
---|
60 | if (Security::isEnabled()) { |
---|
61 | |
---|
62 | /* must instatiate it */ |
---|
63 | if (is_null(self::$_securedFactory)) |
---|
64 | self::$_securedFactory = new ProcessFactory(); |
---|
65 | |
---|
66 | $args = func_get_args(); |
---|
67 | call_user_func_array(array(self::$_securedFactory, "getInstance"), $args); |
---|
68 | |
---|
69 | } |
---|
70 | /* regular module space */ |
---|
71 | else { |
---|
72 | |
---|
73 | /* must instatiate it */ |
---|
74 | if (is_null(self::$_unsecuredFactory)) |
---|
75 | self::$_unsecuredFactory = new WorkflowFactory(); |
---|
76 | |
---|
77 | $args = func_get_args(); |
---|
78 | call_user_func_array(array(self::$_unsecuredFactory, "getInstance"), $args); |
---|
79 | } |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | /** |
---|
85 | * Just forward this call to the correct class. |
---|
86 | * |
---|
87 | * @todo I must implement it! |
---|
88 | * @access public |
---|
89 | * @retun object |
---|
90 | * @static |
---|
91 | */ |
---|
92 | public static function newInstance() { |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | ?> |
---|