PageRenderTime 28ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/api/_object_factory_8php_source.html

http://openbiz-cubi.googlecode.com/
HTML | 165 lines | 164 code | 0 blank | 1 comment | 0 complexity | 5cc51b16e6d977d7a8be54349cc12f75 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <title>openbiz: E:/E/GEAMP/www/openbiz/openbiz/bin/ObjectFactory.php Source File</title>
  6. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  7. <link href="doxygen.css" rel="stylesheet" type="text/css"/>
  8. </head>
  9. <body>
  10. <!-- Generated by Doxygen 1.7.2 -->
  11. <div class="navigation" id="top">
  12. <div class="tabs">
  13. <ul class="tablist">
  14. <li><a href="main.html"><span>Main&#160;Page</span></a></li>
  15. <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  16. <li><a href="namespaces.html"><span>Namespaces</span></a></li>
  17. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  18. <li class="current"><a href="files.html"><span>Files</span></a></li>
  19. </ul>
  20. </div>
  21. <div class="tabs2">
  22. <ul class="tablist">
  23. <li><a href="files.html"><span>File&#160;List</span></a></li>
  24. </ul>
  25. </div>
  26. <div class="header">
  27. <div class="headertitle">
  28. <h1>E:/E/GEAMP/www/openbiz/openbiz/bin/ObjectFactory.php</h1> </div>
  29. </div>
  30. <div class="contents">
  31. <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?<a class="code" href="category_p_h_p.html">PHP</a>
  32. <a name="l00026"></a><a class="code" href="class_object_factory.html">00026</a> <span class="keyword">class </span><a class="code" href="class_object_factory.html">ObjectFactory</a>
  33. <a name="l00027"></a>00027 {
  34. <a name="l00032"></a>00032 <span class="keyword">protected</span> $_objsRefMap = array();
  35. <a name="l00033"></a>00033
  36. <a name="l00034"></a>00034 <span class="keyword">public</span> function __construct()
  37. <a name="l00035"></a>00035 {
  38. <a name="l00036"></a>00036 }
  39. <a name="l00037"></a>00037
  40. <a name="l00038"></a>00038 <span class="keyword">public</span> function __destruct()
  41. <a name="l00039"></a>00039 {
  42. <a name="l00040"></a>00040 }
  43. <a name="l00041"></a>00041
  44. <a name="l00049"></a><a class="code" href="class_object_factory.html#a71bc9af6707bfba4a96afb2547adba4a">00049</a> <span class="keyword">public</span> function <a class="code" href="class_object_factory.html#a71bc9af6707bfba4a96afb2547adba4a">getObject</a>($objName, $new=0)
  45. <a name="l00050"></a>00050 {
  46. <a name="l00051"></a>00051 <span class="keywordflow">if</span> (array_key_exists($objName, $this-&gt;_objsRefMap) &amp;&amp; $new==0)
  47. <a name="l00052"></a>00052 {
  48. <a name="l00053"></a>00053 <span class="keywordflow">return</span> $this-&gt;_objsRefMap[$objName];
  49. <a name="l00054"></a>00054 }
  50. <a name="l00055"></a>00055
  51. <a name="l00056"></a>00056 $obj = $this-&gt;<a class="code" href="class_object_factory.html#a276a15d5187194e2c92b31b8c1f23997">constructObject</a>($objName);
  52. <a name="l00057"></a>00057 <span class="keywordflow">if</span> ($obj)
  53. <a name="l00058"></a>00058 $this-&gt;_objsRefMap[$objName] = $obj; <span class="comment">// save object to cache</span>
  54. <a name="l00059"></a>00059 <span class="keywordflow">if</span>($new!=1){
  55. <a name="l00060"></a>00060 <span class="keywordflow">if</span> (method_exists($obj, <span class="stringliteral">&quot;GetSessionVars&quot;</span>))
  56. <a name="l00061"></a>00061 $obj-&gt;getSessionVars(<a class="code" href="class_biz_system.html#af4e34e77c3fcde41b5c49a48a0b58b0d">BizSystem::sessionContext</a>());
  57. <a name="l00062"></a>00062 }
  58. <a name="l00063"></a>00063 <span class="keywordflow">return</span> $obj;
  59. <a name="l00064"></a>00064 }
  60. <a name="l00065"></a>00065
  61. <a name="l00073"></a><a class="code" href="class_object_factory.html#a271930bb6cceaa4c4d52e61d06bdf71e">00073</a> <span class="keyword">public</span> function <a class="code" href="class_object_factory.html#a271930bb6cceaa4c4d52e61d06bdf71e">createObject</a>($objName, &amp;$xmlArr=null)
  62. <a name="l00074"></a>00074 {
  63. <a name="l00075"></a>00075 $obj = $this-&gt;<a class="code" href="class_object_factory.html#a276a15d5187194e2c92b31b8c1f23997">constructObject</a>($objName, $xmlArr);
  64. <a name="l00076"></a>00076 <span class="keywordflow">return</span> $obj;
  65. <a name="l00077"></a>00077 }
  66. <a name="l00078"></a>00078
  67. <a name="l00079"></a>00079 <span class="keyword">public</span> function setObject($objName, $obj)
  68. <a name="l00080"></a>00080 {
  69. <a name="l00081"></a>00081 $this-&gt;_objsRefMap[$objName] = $obj;
  70. <a name="l00082"></a>00082 }
  71. <a name="l00083"></a>00083
  72. <a name="l00089"></a><a class="code" href="class_object_factory.html#ae7c5da1d80d44662d922178b234fc629">00089</a> <span class="keyword">public</span> function <a class="code" href="class_object_factory.html#ae7c5da1d80d44662d922178b234fc629">getAllObjects</a>()
  73. <a name="l00090"></a>00090 {
  74. <a name="l00091"></a>00091 <span class="keywordflow">return</span> $this-&gt;_objsRefMap;
  75. <a name="l00092"></a>00092 }
  76. <a name="l00093"></a>00093
  77. <a name="l00101"></a><a class="code" href="class_object_factory.html#a276a15d5187194e2c92b31b8c1f23997">00101</a> <span class="keyword">protected</span> function <a class="code" href="class_object_factory.html#a276a15d5187194e2c92b31b8c1f23997">constructObject</a>($objName, &amp;$xmlArr=null)
  78. <a name="l00102"></a>00102 {
  79. <a name="l00103"></a>00103 <span class="keywordflow">if</span> (!$xmlArr)
  80. <a name="l00104"></a>00104 {
  81. <a name="l00105"></a>00105 $xmlFile = BizSystem::GetXmlFileWithPath ($objName);
  82. <a name="l00106"></a>00106 <span class="keywordflow">if</span> (!$xmlFile)
  83. <a name="l00107"></a>00107 {
  84. <a name="l00108"></a>00108 $dotPos = strrpos($objName, <span class="stringliteral">&quot;.&quot;</span>);
  85. <a name="l00109"></a>00109 $package = $dotPos&gt;0 ? substr($objName, 0, $dotPos) : null;
  86. <a name="l00110"></a>00110 $class = $dotPos&gt;0 ? substr($objName, $dotPos+1) : $objName;
  87. <a name="l00111"></a>00111 }
  88. <a name="l00112"></a>00112 <span class="keywordflow">else</span>
  89. <a name="l00113"></a>00113 $xmlArr = <a class="code" href="class_biz_system.html#afb3b9597319d812f889a89ab0c7c5e4b">BizSystem::getXmlArray</a>($xmlFile);
  90. <a name="l00114"></a>00114 }
  91. <a name="l00115"></a>00115 <span class="keywordflow">if</span> ($xmlArr)
  92. <a name="l00116"></a>00116 {
  93. <a name="l00117"></a>00117 $keys = array_keys($xmlArr);
  94. <a name="l00118"></a>00118 $root = $keys[0];
  95. <a name="l00119"></a>00119
  96. <a name="l00120"></a>00120 <span class="comment">// add by mr_a_ton , atrubut name must match with object name</span>
  97. <a name="l00121"></a>00121 $dotPos = strrpos($objName, <span class="stringliteral">&quot;.&quot;</span>);
  98. <a name="l00122"></a>00122 $shortObjectName = $dotPos &gt; 0 ? substr($objName, $dotPos+1) : $objName;
  99. <a name="l00123"></a>00123 <span class="keywordflow">if</span> ($xmlArr[$root][<span class="stringliteral">&quot;ATTRIBUTES&quot;</span>][<span class="stringliteral">&quot;NAME&quot;</span>]==<span class="stringliteral">&quot;&quot;</span>)
  100. <a name="l00124"></a>00124 {
  101. <a name="l00125"></a>00125 $xmlArr[$root][<span class="stringliteral">&quot;ATTRIBUTES&quot;</span>][<span class="stringliteral">&quot;NAME&quot;</span>]=$shortObjectName;
  102. <a name="l00126"></a>00126 }
  103. <a name="l00127"></a>00127 <span class="keywordflow">else</span>
  104. <a name="l00128"></a>00128 {
  105. <a name="l00129"></a>00129 <span class="keywordflow">if</span> ($shortObjectName != $xmlArr[$root][<span class="stringliteral">&quot;ATTRIBUTES&quot;</span>][<span class="stringliteral">&quot;NAME&quot;</span>] )
  106. <a name="l00130"></a>00130 {
  107. <a name="l00131"></a>00131 trigger_error(<span class="stringliteral">&quot;Metadata file parsing error for object $objName. Name attribut [&quot;</span>.$xmlArr[$root][<span class="stringliteral">&quot;ATTRIBUTES&quot;</span>][<span class="stringliteral">&quot;NAME&quot;</span>].<span class="stringliteral">&quot;] not same with object name. Please double check your metadata xml file again.&quot;</span>, E_USER_ERROR);
  108. <a name="l00132"></a>00132 }
  109. <a name="l00133"></a>00133 }
  110. <a name="l00134"></a>00134
  111. <a name="l00135"></a>00135 <span class="comment">//$package = $xmlArr[$root][&quot;ATTRIBUTES&quot;][&quot;PACKAGE&quot;];</span>
  112. <a name="l00136"></a>00136 $class = $xmlArr[$root][<span class="stringliteral">&quot;ATTRIBUTES&quot;</span>][<span class="stringliteral">&quot;CLASS&quot;</span>];
  113. <a name="l00137"></a>00137 <span class="comment">// if class has package name as prefix, change the package to the prefix</span>
  114. <a name="l00138"></a>00138 $dotPos = strrpos($class, <span class="stringliteral">&quot;.&quot;</span>);
  115. <a name="l00139"></a>00139 $classPrefix = $dotPos&gt;0 ? substr($class, 0, $dotPos) : null;
  116. <a name="l00140"></a>00140 $classPackage = $classPrefix ? $classPrefix : null;
  117. <a name="l00141"></a>00141 <span class="keywordflow">if</span> ($classPrefix) $class = substr($class, $dotPos+1);
  118. <a name="l00142"></a>00142 <span class="comment">// set object package</span>
  119. <a name="l00143"></a>00143 $dotPos = strrpos($objName, <span class="stringliteral">&quot;.&quot;</span>);
  120. <a name="l00144"></a>00144 $package = $dotPos&gt;0 ? substr($objName, 0, $dotPos) : null;
  121. <a name="l00145"></a>00145 <span class="keywordflow">if</span> (strpos($package, <span class="charliteral">&#39;@&#39;</span>) === 0) $package = substr($package, 1);
  122. <a name="l00146"></a>00146 <span class="keywordflow">if</span> (!$classPackage) $classPackage = $package;
  123. <a name="l00147"></a>00147 $xmlArr[$root][<span class="stringliteral">&quot;ATTRIBUTES&quot;</span>][<span class="stringliteral">&quot;PACKAGE&quot;</span>] = $package;
  124. <a name="l00148"></a>00148 }
  125. <a name="l00149"></a>00149
  126. <a name="l00150"></a>00150 <span class="keywordflow">if</span> ($class == <span class="stringliteral">&quot;BizObj&quot;</span>) <span class="comment">// convert BizObj to BizDataObj, support &lt;1.2 version</span>
  127. <a name="l00151"></a>00151 $class = <span class="stringliteral">&quot;BizDataObj&quot;</span>;
  128. <a name="l00152"></a>00152
  129. <a name="l00153"></a>00153 <span class="keywordflow">if</span> (!class_exists($class, <span class="keyword">false</span>))
  130. <a name="l00154"></a>00154 {
  131. <a name="l00155"></a>00155 $classFile= <a class="code" href="class_biz_system.html#a6bbd0684f00be761ca64e9c4eb57a0c7">BizSystem::getLibFileWithPath</a>($class, $classPackage);
  132. <a name="l00156"></a>00156 <span class="keywordflow">if</span> (!$classFile)
  133. <a name="l00157"></a>00157 {
  134. <a name="l00158"></a>00158 <span class="keywordflow">if</span> ($package)
  135. <a name="l00159"></a>00159 trigger_error(<span class="stringliteral">&quot;Cannot find the class with name as $package.$class&quot;</span>, E_USER_ERROR);
  136. <a name="l00160"></a>00160 <span class="keywordflow">else</span>
  137. <a name="l00161"></a>00161 trigger_error(<span class="stringliteral">&quot;Cannot find the class with name as $class of $objName&quot;</span>, E_USER_ERROR);
  138. <a name="l00162"></a>00162 exit();
  139. <a name="l00163"></a>00163 }
  140. <a name="l00164"></a>00164 include_once($classFile);
  141. <a name="l00165"></a>00165 }
  142. <a name="l00166"></a>00166 <span class="keywordflow">if</span> (class_exists($class, <span class="keyword">false</span>))
  143. <a name="l00167"></a>00167 {
  144. <a name="l00168"></a>00168 <span class="comment">//if ($objName == &quot;collab.calendar.form.EventListForm&quot;) { print_r($xmlArr); exit; }</span>
  145. <a name="l00169"></a>00169 $obj_ref = <span class="keyword">new</span> $class($xmlArr);
  146. <a name="l00170"></a>00170 <span class="keywordflow">if</span> ($obj_ref)
  147. <a name="l00171"></a>00171 {
  148. <a name="l00172"></a>00172 <span class="keywordflow">return</span> $obj_ref;
  149. <a name="l00173"></a>00173 }
  150. <a name="l00174"></a>00174 }
  151. <a name="l00175"></a>00175 <span class="keywordflow">else</span>
  152. <a name="l00176"></a>00176 trigger_error(<span class="stringliteral">&quot;Cannot find the class with name as $class in $classFile&quot;</span>, E_USER_ERROR);
  153. <a name="l00177"></a>00177 <span class="keywordflow">return</span> null;
  154. <a name="l00178"></a>00178 }
  155. <a name="l00179"></a>00179
  156. <a name="l00180"></a>00180 }
  157. <a name="l00181"></a>00181
  158. <a name="l00182"></a>00182 ?&gt;
  159. </pre></div></div>
  160. </div>
  161. <hr class="footer"/><address class="footer"><small>Generated on Thu Apr 19 2012 17:09:13 for openbiz by&#160;
  162. <a href="http://www.doxygen.org/index.html">
  163. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
  164. </body>
  165. </html>